問題描述
我安裝了 miniconda3,在其中創建了一個名為 py35 的虛擬環境.我有一些我只想在這個環境中使用的庫.因此他們在
/.../miniconda3/envs/py35/libs
但是在環境中找不到它們,因為 LD_LIBRARY_PATH 不包含所述文件夾.我現在想將 LD_LIBRARY_PATH 設置為僅當我在虛擬環境中時才包含/lib.
我正在考慮修改 miniconda 用于啟動環境的激活腳本,但不太確定這是標準做法還是有更簡單的方法來實現這一點.
您可以通過編輯 activate.d/env_vars.sh
腳本在激活環境時設置環境變量.見這里:https://conda.io/docs/user-guide/tasks/manage-environments.html#macos-and-linux
該鏈接的關鍵部分是:
<塊引用>在終端中找到 conda 環境的目錄窗口,例如
/home/jsmith/anaconda3/envs/analytics
.進入該目錄并創建這些子目錄和文件:
cd/home/jsmith/anaconda3/envs/analyticsmkdir -p ./etc/conda/activate.dmkdir -p ./etc/conda/deactivate.d觸摸 ./etc/conda/activate.d/env_vars.sh觸摸 ./etc/conda/deactivate.d/env_vars.sh
編輯
./etc/conda/activate.d/env_vars.sh
如下:#!/bin/sh導出 MY_KEY='秘密鍵值'導出 MY_FILE=/path/to/my/file/
編輯
./etc/conda/deactivate.d/env_vars.sh
如下::#!/bin/sh取消設置 MY_KEY取消設置 MY_FILE
當您運行 conda activate analytics
時,環境變量 MY_KEY 和 MY_FILE 設置為您寫入的值文件.當你運行 conda deactivate
時,這些變量是刪除.
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
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.
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.
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:
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
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/
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 runconda deactivate
, those variables are erased.
這篇關于Conda 僅為 env 設置 LD_LIBRARY_PATH的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!