Conda仅将env设置为LD_LIBRARY_PATH [英] Conda set LD_LIBRARY_PATH for env only

查看:404
本文介绍了Conda仅将env设置为LD_LIBRARY_PATH的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我安装了miniconda3,并在其中创建了一个名为py35的虚拟环境.我有一些我只想在此环境中使用的库.因此它们在

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. hence they are under

 /.../miniconda3/envs/py35/libs

但是在环境中找不到它们,因为LD_LIBRARY_PATH不包含所述文件夹.现在,我想将LD_LIBRARY_PATH设置为仅在虚拟环境中时才包含/lib.

However they are not found from within the environment as LD_LIBRARY_PATH does not contain said folder. I now want to set LD_LIBRARY_PATH to include the /lib only when I am in the virtual environment.

我当时正在考虑修改miniconda用来启动环境的激活脚本,但不确定这是否是标准做法,或者是否有更简单的方法来实现.

I was thinking of modifying the activate script miniconda uses to start the environment but am not quite sure if this is standard practice or if there is an easier way to achieve this.

推荐答案

在激活环境时,可以通过编辑activate.d/env_vars.sh脚本来设置环境变量.参见此处: https://conda.io/docs/user-guide/tasks/manage-environments.html#macos-and-linux

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

该链接的关键部分是:

  1. 在终端中找到conda环境的目录 窗口,例如/home/jsmith/anaconda3/envs/analytics.

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

输入该目录并创建这些子目录,然后 文件:

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

  • 按如下所示编辑./etc/conda/activate.d/env_vars.sh:

    #!/bin/sh
    
    export MY_KEY='secret-key-value'
    export MY_FILE=/path/to/my/file/
    

  • 按如下所示编辑./etc/conda/deactivate.d/env_vars.sh:

    #!/bin/sh
    
    unset MY_KEY
    unset MY_FILE
    

  • 运行conda activate analytics时,环境 变量MY_KEY和MY_FILE设置为您写入的值 文件.当您运行conda deactivate时,这些变量是 删除.

    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.

    这篇关于Conda仅将env设置为LD_LIBRARY_PATH的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆