在 pip3 下安裝了一個包,但在 Python3 下找不到。為什么?所有這些都發生在我的 anaconda 基礎環境中:因此,我一直在為 tensorflow 及其版本苦苦掙扎(即將發布另一篇文章)。結果發現 2.1 版僅在 pip 上可用,而 conda install 則不可用。所以升級后pip3 install --upgrade pip我安裝pip3 install tensorflow==2.1.0. 之后我打開 Jupyer-Notebook,結果發現 tensorflow 沒有安裝(運行 Python3)。我首先從終端檢查版本,然后卸載 tensorflow。它沒有安裝在 pip 下(如預期的那樣),但它確實安裝在 pip3 下。通過 pip3 卸載時,我也收到此消息:" pip is being invoked by an old script wrapper. This will fail in a future version of pip.
Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue.
To avoid this problem you can invoke Python with '-m pip' instead of running pip directly."這可能是相關的。我的印象是 pip 為默認的 python 安裝包(在我的例子中是 3.7.4),但 pip3 只為 Python3 安裝它們。我錯過了什么?謝謝!
1 回答

瀟瀟雨雨
TA貢獻1833條經驗 獲得超4個贊
pip3下安裝了一個包,但是在Python3下找不到。為什么?
因為你有很多不同的 Python。pip
不會為所有 Python 安裝包;pip3
不為 Python3 安裝包。他們為正在運行的特定 Python 安裝軟件包。如果它們的版本相同,你不能指望用一個 Python 安裝一個包并在另一個前夕導入它。
要查看 Python 與特定對象一起使用的內容,pip
請參閱它的shebang:
head -1 $(which pip) head -1 $(which pip3)
如果 shebang#!/usr/bin/env python
繼續使用which python
(或which python3
)進行調查。
查找 Python 運行python -m site
以查看從何處導入包。
添加回答
舉報
0/150
提交
取消