Anaconda: Permanently include external packages (like in PYTHONPATH)

后端 未结 4 2184
粉色の甜心
粉色の甜心 2020-11-28 18:37

I know how to install packages in Anaconda using conda install and also how to install packages that are on PyPi which is described in the manual.

But h

4条回答
  •  感情败类
    2020-11-28 19:05

    The way I do this, which I believe is the most native to conda, is by creating env_vars.sh files in my environment, as per the official documentation here.

    For macOS and Linux users, the steps are as follows:

    1. Go to your environment folder (e.g. /miniconda1/env/env_name). $CONDA_PREFIX is the environemnt variable for your environment path.

      cd $CONDA_PREFIX
      
    2. Create the activate.d and deactivate.d directories.

      mkdir -p ./etc/conda/activate.d
      mkdir -p ./etc/conda/deactivate.d
      
    3. Inside the each respective directory, create one env_vars.sh file. The one in the activate.d directory will set (or export) your environment variables when you conda activate your environment. The file in the deactivate.d directory will serve to unset the environment variables when you conda deactivate your environment.

      touch ./etc/conda/activate.d/env_vars.sh
      touch ./etc/conda/deactivate.d/env_vars.sh
      
    4. First edit the $CONDA_PREFIX/etc/conda/activate.d/env_vars.sh to export the desired environment variables.

      #!/bin/sh
      
      export VAR_A='some-thing-here'
      export VAR_B=/path/to/my/file/
      
    5. Afterwards, open to edit the $CONDA_PREFIX/etc/conda/deactivate/env_vars.sh, in order to unset the env variables when you conda deactivate like so:

      #!/bin/sh
      
      unset VAR_A
      unset VAR_B
      

    Again, the source of my description comes straight from the conda docs here.

提交回复
热议问题