Conda set LD_LIBRARY_PATH for env only

前端 未结 2 450
迷失自我
迷失自我 2020-11-28 09:06

I have an installation of miniconda3 where I have created a virtual environment called py35. I have some libraries that I only want to use from within this environment. henc

2条回答
  •  清酒与你
    2020-11-28 09:33

    You can set environment variables when an environment is activated by editing the activate.d/env_vars.sh script. See here: https://conda.io/docs/user-guide/tasks/manage-environments.html#macos-and-linux

    The key portions from that link are:

    1. Locate the directory for the conda environment in your Terminal window, such as /home/jsmith/anaconda3/envs/analytics.

    2. Enter that directory and create these subdirectories and files:

      cd /home/jsmith/anaconda3/envs/analytics
      mkdir -p ./etc/conda/activate.d
      mkdir -p ./etc/conda/deactivate.d
      touch ./etc/conda/activate.d/env_vars.sh
      touch ./etc/conda/deactivate.d/env_vars.sh
      
    3. Edit ./etc/conda/activate.d/env_vars.sh as follows:

      #!/bin/sh
      
      export MY_KEY='secret-key-value'
      export MY_FILE=/path/to/my/file/
      
    4. Edit ./etc/conda/deactivate.d/env_vars.sh as follows::

      #!/bin/sh
      
      unset MY_KEY
      unset MY_FILE
      

    When you run conda activate analytics, the environment variables MY_KEY and MY_FILE are set to the values you wrote into the file. When you run conda deactivate, those variables are erased.

提交回复
热议问题