使用 Pip 將軟件包安裝到 Anaconda 環境 - Using Pip to install packages to Anaconda Environment

問題:

conda 4.2.13 MacOSX 10.12.1康達 4.2.13 MacOSX 10.12.1

I am trying to install packages from pip to a fresh environment (virtual) created using anaconda.我正在嘗試將pip中的軟件包安裝到使用 anaconda 創建的新環境(虛擬)中。 In the Anaconda docs it says this is perfectly fine. 在 Anaconda 文檔中,它說這完全沒問題。 It is done the same way as for virtualenv.它的完成方式與 virtualenv 相同。

Activate the environment where you want to put the program, then pip install a program...激活要放置程序的環境,然後pip install一個程序...

I created an empty environment in Ananconda like this:我在 Ananconda 中創建了一個空環境,如下所示:

conda create -n shrink_venv

Activate it:激活它:

source activate shrink_venv

I then can see in the terminal that I am working in my env (shrink_venv) .然後我可以在終端中看到我正在我的 env (shrink_venv) Problem is coming up, when I try to install a package using pip :問題來了,當我嘗試使用pip安裝軟件包時:

(shrink_venv): pip install Pillow

Requirement already satisfied (use --upgrade to upgrade): Pillow in /Library/Python/2.7/site-packages

So I can see it thinks the requirement is satisfied from the system-wide package.所以我可以看到它認爲系統範圍的包滿足了要求。 So it seems the environment is not working correctly, definitely not like it said in the docs.所以看起來環境不能正常工作,絕對不像文檔中所說的那樣。 Am I doing something wrong here?我在這裏做錯了嗎?

Just a note, I know you can use conda install for the packages, but I have had an issue with Pillow from anaconda, so I wanted to get it from pip , and since the docs say that is fine.請注意,我知道您可以將conda install用於軟件包,但是我遇到了來自 anaconda 的 Pillow 問題,所以我想從pip獲取它,因爲文檔說這很好。

Output of which -a pip : which -a pip輸出:

/usr/local/bin/pip
/Users/my_user/anaconda/bin/pip

** UPDATE ** I see this is pretty common issue. ** 更新 ** 我認爲這是很常見的問題。 What I have found is that the conda env doesn't play well with the PYTHONPATH.我發現 conda env 不能很好地與 PYTHONPATH 配合使用。 The system seems to always look in the PYTHONPATH locations even when you're using a conda environment.即使您使用的是 conda 環境,系統似乎總是在 PYTHONPATH 位置中查找。 Now, I always run unset PYTHONPATH when using a conda environment, and it works much better.現在,我在使用 conda 環境時總是運行unset PYTHONPATH ,而且效果更好。 I'm on a mac.我在 mac 上。


解決方案:

參考一: https://stackoom.com/question/2mHgE
參考二: Using Pip to install packages to Anaconda Environment
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章