[Python] Environment variable in conda is not aligning with os.environ, possibly because of...

Discussão em 'Python' iniciado por Stack, Fevereiro 23, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to set an environment variable SOME_VAR in a conda environment. The value begins with a $ character. Initially I didn't properly single-quote the variable value, which might have caused a silent error in powershell because that character has special meaning. Later I thought I'd fixed the problem by re-assigning the variable properly, executing the following commands in anaconda powershell

    conda env config vars set SOME_VAR='$ValueOfTheVariable!'
    conda env config vars list -n my_env


    Conda then properly displays the full SOME_VAR=$ValueOfTheVariable!. But Spyder, loading that environment, only sees the following:

    In [4]: os.environ.get('SOME_VAR')
    Out[4]: '!'


    Specifically, anaconda displays the whole variable, but Spyder and os only see the trailing exclamation point. All other environment variables are in agreement.

    Things I've tried:

    • checking the conda documentation
    • deactivating / reloading environment in powershell
    • restarting Spyder
    • removing the environment variable in powershell and reassigning it there
    • removing the environment variable in os, then restarting Spyder (the offending version reappears)
    • Unsetting in powershell, then setting with double-quotes using a backtick before the $ (per the second answer here)

    Even after unsetting the variable in powershell, the variable persists in os.environ, making me think it's looking somewhere else and finding that version first before getting to my conda environment. But I never set that variable anywhere besides conda.

    Continue reading...

Compartilhe esta Página