conda能夠實現多個環境共存原因的感悟

2021-07-27 20:45:48 字數 3543 閱讀 2705

conda能夠實現多個環境共存原因:

首先檢視我目前有多少個環境:

conda info —envs

結果如下:

# conda environments:

#python27                 /users/zj_macbook/anaconda/envs/python27

python3               *  /users/zj_macbook/anaconda/envs/python3

root                     /users/zj_macbook/anaconda

用 source activate 啟用不同的python環境

三個環境下的path的值分別為:

root:

~/anaconda/bin:

/opt/local/bin:

/opt/local/sbin:

/usr/local/bin:

/usr/bin:

/bin:

/usr/sbin:

/sbin:

/library/tex/texbin

python27:

/users/zj_macbook/anaconda/envs/python27/bin:

~/anaconda/bin:

/opt/local/bin:

/opt/local/sbin:

/usr/local/bin:

/usr/bin:

/bin:

/usr/sbin:

/sbin:

/library/tex/texbin

python3:

/users/zj_macbook/anaconda/envs/python3/bin:

~/anaconda/bin:

/opt/local/bin:

/opt/local/sbin:

/usr/local/bin:

/usr/bin:

/bin:

/usr/sbin:

/sbin:

/library/tex/texbin

從這裡可以看出conda把自己當前的環境寫入path,這樣在終端呼叫的部分工具都是當前環境目錄下的工具。

比如,在每乙個不同的python環境下都有乙個對應版本的pip,當使用該pip時,pip會把庫檔案安裝在當前環境的python目錄下。

而brew則不同,brew安裝在/usr/local/bin中,呼叫brew安裝庫檔案時brew會把它們安裝在/usr/local/lib/python2.7/site-packages中,這時conda中的python是引用不了brew安裝的庫檔案的

三個環境下的python的sys.path的值分別為:

root:

['', 

'/users/zj_macbook/anaconda/lib/python27.zip',

'/users/zj_macbook/anaconda/lib/python2.7', 

'/users/zj_macbook/anaconda/lib/python2.7/plat-darwin', 

'/users/zj_macbook/anaconda/lib/python2.7/plat-mac', 

'/users/zj_macbook/anaconda/lib/python2.7/plat-mac/lib-scriptpackages', 

'/users/zj_macbook/anaconda/lib/python2.7/lib-tk', 

'/users/zj_macbook/anaconda/lib/python2.7/lib-old', 

'/users/zj_macbook/anaconda/lib/python2.7/lib-dynload', 

'/users/zj_macbook/anaconda/lib/python2.7/site-packages', 

'/users/zj_macbook/anaconda/lib/python2.7/site-packages/sphinx-1.4.6-py2.7.egg', 

'/users/zj_macbook/anaconda/lib/python2.7/site-packages/aeosa', 

'/users/zj_macbook/anaconda/lib/python2.7/site-packages/setuptools-27.2.0-py2.7.egg']

python27:

['', 

'/users/zj_macbook/anaconda/envs/python27/lib/python27.zip', 

'/users/zj_macbook/anaconda/envs/python27/lib/python2.7', 

'/users/zj_macbook/anaconda/envs/python27/lib/python2.7/plat-darwin', 

'/users/zj_macbook/anaconda/envs/python27/lib/python2.7/plat-mac', 

'/users/zj_macbook/anaconda/envs/python27/lib/python2.7/plat-mac/lib-scriptpackages', 

'/users/zj_macbook/anaconda/envs/python27/lib/python2.7/lib-tk', 

'/users/zj_macbook/anaconda/envs/python27/lib/python2.7/lib-old', 

'/users/zj_macbook/anaconda/envs/python27/lib/python2.7/lib-dynload', 

'/users/zj_macbook/anaconda/envs/python27/lib/python2.7/site-packages', 

'/users/zj_macbook/anaconda/envs/python27/lib/python2.7/site-packages/setuptools-27.2.0-py2.7.egg']

python3:

['', 

'/users/zj_macbook/anaconda/envs/python3/lib/python36.zip', 

'/users/zj_macbook/anaconda/envs/python3/lib/python3.6', 

'/users/zj_macbook/anaconda/envs/python3/lib/python3.6/lib-dynload', 

'/users/zj_macbook/anaconda/envs/python3/lib/python3.6/site-packages', 

'/users/zj_macbook/anaconda/envs/python3/lib/python3.6/site-packages/setuptools-27.2.0-py3.6.egg']

這裡可以看出不同環境下的python的sys.path中的路徑的是當前環境下的路徑,保證了匯入的python包只能是當前環境下的。

conda切換環境 conda

2020 8 3理論課 親緣關係和pca分析 gcta運用的是bed模式 需要轉化 make bed 無root許可權下conda的安裝 wget no check certificate 2.安裝 bash miniconda3 4.7.12 linux x86 64.sh 切換到家目錄 cd s...

conda 拷貝環境

已經有了乙個python環境 對應著安裝所有包的目錄 想要複製環境下的所有包。假設環境的所有包在目錄env path下。想要將環境安裝到dst下,直接用conda的拷貝命令 conda create prefix dst clone env path 啟用當前環境 source activate d...

conda環境移植

python配環境是真的麻煩,為了能進行環境移植,特意寫了此篇博文 conda info e檢視已配置完成的環境位址 conda create n bbb clone path把原來電腦上目標conda環境的目錄複製到新電腦上 使用該命令進行conda環境的移植,建立乙個bbb環境,從 path移植...