簡體   English   中英

ImportError:沒有名為 pip 的模塊

[英]ImportError: No module named pip

操作系統:Mac OS X 10.7.5 Python 版本:2.7.5

I have installed setuptools 1.0 with ez_setup.py from https://pypi.python.org/pypi/setuptools Then I download pip.1.4.1 pkg from https://pypi.python.org/pypi/pip/1.4.1 .

在 iTerm 中運行 (sudo) python setup.py install表明

running install
running bdist_egg running egg_info writing requirements to
pip.egg-info/requires.txt writing pip.egg-info/PKG-INFO writing
top-level names to pip.egg-info/top_level.txt writing dependency_links
to pip.egg-info/dependency_links.txt writing entry points to
pip.egg-info/entry_points.txt warning: manifest_maker: standard file
'setup.py' not found

reading manifest file 'pip.egg-info/SOURCES.txt' writing manifest file
'pip.egg-info/SOURCES.txt' installing library code to
build/bdist.macosx-10.6-intel/egg running install_lib warning:
install_lib: 'build/lib' does not exist -- no Python modules to
install

creating build/bdist.macosx-10.6-intel/egg creating
build/bdist.macosx-10.6-intel/egg/EGG-INFO copying
pip.egg-info/PKG-INFO -> build/bdist.macosx-10.6-intel/egg/EGG-INFO
copying pip.egg-info/SOURCES.txt ->
build/bdist.macosx-10.6-intel/egg/EGG-INFO copying
pip.egg-info/dependency_links.txt ->
build/bdist.macosx-10.6-intel/egg/EGG-INFO copying
pip.egg-info/entry_points.txt ->
build/bdist.macosx-10.6-intel/egg/EGG-INFO copying
pip.egg-info/not-zip-safe ->
build/bdist.macosx-10.6-intel/egg/EGG-INFO copying
pip.egg-info/requires.txt ->
build/bdist.macosx-10.6-intel/egg/EGG-INFO copying
pip.egg-info/top_level.txt ->
build/bdist.macosx-10.6-intel/egg/EGG-INFO creating
'dist/pip-1.4.1-py2.7.egg' and adding
'build/bdist.macosx-10.6-intel/egg' to it removing
'build/bdist.macosx-10.6-intel/egg' (and everything under it)
Processing pip-1.4.1-py2.7.egg removing
'/Users/dl/Library/Python/2.7/lib/python/site-packages/pip-1.4.1-py2.7.egg'
(and everything under it) creating
/Users/dl/Library/Python/2.7/lib/python/site-packages/pip-1.4.1-py2.7.egg
Extracting pip-1.4.1-py2.7.egg to
/Users/dl/Library/Python/2.7/lib/python/site-packages pip 1.4.1 is
already the active version in easy-install.pth Installing pip script
to /Users/dl/Library/Python/2.7/bin Installing pip-2.7 script to
/Users/dl/Library/Python/2.7/bin

Installed
/Users/dl/Library/Python/2.7/lib/python/site-packages/pip-1.4.1-py2.7.egg
Processing dependencies for pip==1.4.1 Finished processing
dependencies for pip==1.4.1

然后我輸入pip install ,錯誤信息顯示如下

Traceback (most recent call last):   File
"/Library/Frameworks/Python.framework/Versions/2.7/bin/pip", line 9,
in <module>
load_entry_point('pip==1.4.1', 'console_scripts', 'pip')()   File "build/bdist.macosx-10.6-intel/egg/pkg_resources.py", line 357, in
load_entry_point   File
"build/bdist.macosx-10.6-intel/egg/pkg_resources.py", line 2394, in
load_entry_point   File
"build/bdist.macosx-10.6-intel/egg/pkg_resources.py", line 2108, in
load ImportError: No module named pip

以前遇到過同樣問題的任何人都可以給我一些解決方法嗎?

我有同樣的問題。 我的解決方案:

對於 Python 3

sudo apt-get install python3-pip

對於 Python 2

sudo apt-get install python-pip

在 Mac 上使用brew是更好的選擇,因為apt-get不可用。 命令:

brew install python

如果您在機器上安裝了 python2 和 python3

python2.7 -m ensurepip --default-pip

應該可以解決問題。

相反,如果您缺少 python 3 中的 pip,那么只需在上面的命令中將python2.7更改為python3

使用 macOS 10.15 和 Homebrew 2.1.6,我在使用 Python 3.7 時遇到此錯誤。 我只需要運行:

python3 -m ensurepip

現在python3 -m pip對我python3 -m pip

安裝ez_setup 后,您應該可以使用easy_install 要安裝pip只需執行以下操作:

easy_install pip

嘗試通過 Python 安裝pip

請前往: https : //pip.pypa.io/en/stable/installing/

並下載get-pip.py ,然后運行:

(sudo) python get-pip.py

在某種 Linux 上,例如基於 Debian 的發行版,您可能需要考慮先更新“ apt-get ”,以防您通過它安裝 python-pip。

sudo apt-get update

這可能有助於 apt-get 更新其索引並找到 python-pip 包。 在此之后,您可能會像這樣安裝 pip-

sudo apt-get install python-pip (Python2)
sudo apt-get install python3-pip (Python3)

跑步

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py

然后在您下載的文件夾中運行以下命令:get-pip.py

python get-pip.py

我在嘗試安裝 nova 客戶端時遇到了同樣的問題。

spencers-macbook-pro:python-novaclient root# python  setup.py install    
running install
/usr/bin/python: No module named pip
error: /usr/bin/python -m pip.__init__ install   'pbr>=0.5.21,<1.0' 'iso8601>=0.1.4' 'PrettyTable>=0.6,<0.8' 'requests>=1.1' 'simplejson>=2.0.9' 'six' 'Babel>=0.9.6' returned 1

我使用自制軟件,所以我用sudo easy_install pip解決了這個問題

spencers-macbook-pro:python-novaclient root# brew search pip
aespipe     brew-pip    lesspipe    pipebench   pipemeter   spiped  pipeviewer

If you meant "pip" precisely:

Homebrew provides pip via: `brew install python`. However you will then
have two Pythons installed on your Mac, so alternatively you can:
    sudo easy_install pip
spencers-macbook-pro:python-novaclient root# sudo easy_install pip

如果您使用 macports,命令應該類似。

我認為以上這些答案都不能解決您的問題。

我也有一次被這個問題搞糊塗了。 您應該按照官方指南pip 安裝手動安裝pip (目前涉及運行單個get-pip.py Python 腳本

之后,只需sudo pip install Django 錯誤將消失。

我從這里下載了pip二進制文件,它解決了這個問題。

我知道這個線程很舊,但我只是在 OS X 上為自己解決了與這里描述的不同的問題。

基本上我通過 brew 重新安裝了 Python 2.7,它帶有 pip。

如果還沒有安裝 Xcode:

xcode-select –install

按照此處所述安裝 Brew:

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

然后通過 Brew 安裝 Python:

brew install python

你已經完成了。 就我而言,我只需要安裝 pyserial。

pip install pyserial

我在 MacOS Big Sur 上使用 Python 3.8.6 遇到了同樣的錯誤。

無論我使用pip還是pip3我都會收到這個錯誤:

 File "/Users/marcelloromani/dev/<repository>/venv/bin/pip", line 5, in <module>
    from pip._internal.cli.main import main
ModuleNotFoundError: No module named 'pip'

原來我的 virtualenv 已經過時了。 這為我解決了問題:

  1. 刪除舊的 virtualenv
$ deactivate
$ rm -rf venv
  1. 初始化一個新的 virtualenv
$ virtualenv venv
$ . venv/bin/activate
  1. 安裝新的要求然后工作:
$ pip install -r src/requirements.txt

在終端試試這個:

ls -lA /usr/local/bin | grep pip

就我而言,我得到:

-rwxr-xr-x 1 root  root      284 Сен 13 16:20 pip
-rwxr-xr-x 1 root  root      204 Окт 27 16:37 pip2
-rwxr-xr-x 1 root  root      204 Окт 27 16:37 pip2.7
-rwxr-xr-x 1 root  root      292 Сен 13 16:20 pip-3.4

所以 pip2 || pip2.7 在我的情況下工作,和 pip

下載:

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py

然后安裝pip:

py get-pip.py

然后安裝biopython:

py -m pip install biopython

我希望它會有用

我在使用命令創建新的 Python 3 虛擬環境時遇到了問題ModuleNotFoundError: No module named 'pip'

python3 -m venv ~/venv/ontology    ## << note: "python3" (problematic)

這是經常建議的命令(此處,其他地方)。 當我進入那個 venv 時,找不到 pip。

在此期間,自從第一次使用該命令創建 Python 虛擬環境以來,我的系統 Python 已從 Python 3.7.4 升級(Arch Linux 系統更新)到 Python 3.9.2。

解決方法是使用命令

python -m venv <your_venv>  ## e.g. python -m ~/venv/ontology

當我這樣做時( python -m ...不是python3 -m ... ),venv 現在包含pip ...

要在該 venv 中升級pip ,請使用

<your_venv_path>/bin/python -m pip install --upgrade pip

## e.g.
## /home/victoria/venv/ontology/bin/python -m pip install --upgrade pip

如果你在 ubuntu 中得到“No module named pip”,試試這個。

$python3 -m pip --version
/usr/bin/python3: No module named pip

$sudo apt-get install python3-pip

它對我有用。

安裝成功后使用驗證

$python3 -m pip --version

升級到最新的 pip 版本

$python3 -m pip install --upgrade pip

我通過將 PYTHONPATH 設置為站點包位置解決了 Linux 上的類似錯誤。 這是在運行python get-pip.py --prefix /home/chet/pip

[chet@rhel1 ~]$ ~/pip/bin/pip -V
Traceback (most recent call last):
  File "/home/chet/pip/bin/pip", line 7, in <module>
    from pip import main
ImportError: No module named pip

[chet@rhel1 ~]$ export PYTHONPATH=/home/chet/pip/lib/python2.6/site-packages

[chet@rhel1 ~]$ ~/pip/bin/pip -V
pip 9.0.1 from /home/chet/pip/lib/python2.6/site-packages (python 2.6)

我的 py 版本是 3.7.3,這個 cmd 有效

python3.7 -m pip install requests

請求庫 - 用於從 Web API 檢索數據。

這將運行 pip 模塊並要求它在 PyPI.org(Python 包索引)上找到 requests 庫並將其安裝在您的本地系統中,以便您可以導入

下面針對 Linux 進行了測試:您可以直接從https://pypi.org/simple/pip/ untar 下載 pip 並直接與您最新的 python 一起使用。

tar -xvf  pip-0.2.tar.gz
cd pip-0.2

檢查內容。

anant$ ls
docs  pip.egg-info  pip-log.txt  pip.py  PKG-INFO  regen-docs  scripts  setup.cfg  setup.py  tests

直接執行:

anant$ python pip.py --help
Usage: pip.py COMMAND [OPTIONS]

Options:
  --version             show program's version number and exit
  -h, --help            show this help message and exit
  -E DIR, --environment=DIR
                        virtualenv environment to run pip in (either give the
                        interpreter or the environment base directory)
  -v, --verbose         Give more output
  -q, --quiet           Give less output
  --log=FILENAME        Log file where a complete (maximum verbosity) record
                        will be kept
  --proxy=PROXY         Specify a proxy in the form
                        user:passwd@proxy.server:port. Note that the
                        user:password@ is optional and required only if you
                        are behind an authenticated proxy.  If you provide
                        user@proxy.server:port then you will be prompted for a
                        password.
  --timeout=SECONDS     Set the socket timeout (default 15 seconds)

以下是使用 MacPorts 升級到 Python 3 的最小指令集:

sudo port install py37-pip
sudo port select --set pip pip37
sudo port select --set pip3 pip37
sudo pip install numpy, scipy, matplotlib

我運行了一些舊代碼,這次升級后它又可以工作了。

按照此 URL 上的建議重命名 python39._pth 文件。 這解決了問題

https://michlstechblog.info/blog/python-install-python-with-pip-on-windows-by-the-embeddable-zip-file/#more-5606

ren python39._pth python39._pth.save

我只需要用pip3替換pip所以我最終運行了如下命令: pip3 install matplotlib

我在從requirements.txt文件安裝依賴python3.8時遇到了類似的問題, virtualenvpython3.8 我設法通過激活virtualenv然后運行命令python -m pip install -r requirements.txt讓它工作,它工作了。

嘗試重新安裝 pip 使用 curl 命令下載 get-pip.py 文件:

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python get-pip.py

如果 curl 不起作用,請打開此鏈接: get-pip.py

在您的目錄中創建一個 get-pip.py 文件,復制此鏈接中的代碼並將其放入 get-pip.py 文件中,並將該文件保存在同一目錄中。 然后運行命令

python get-pip.py

我使用的是 Debian,但此解決方案也適用於 Ubuntu。

  1. 通常,pip 是默認自帶python的,目的是檢查你的系統運行中是否安裝了pip。
 python -m pip --version
  1. 如果 pip 不存在,請使用 Aptitude Linux Package Manager 安裝它,
 # For Python 2 sudo apt install python-pip # For Python 3 sudo apt install python3-venv python3-pip
  1. 我不會在 Debian/Ubuntu 中使用get-pip.py腳本,因為在文檔頁面中提到了以下內容。

如果您使用由操作系統或其他包管理器管理的 Python 安裝,請務必小心。 get-pip.py 不與這些工具協調,並且可能會使您的系統處於不一致的狀態。

來源在這里那里

運行 sudo apt-get install pip 並重試這個修復了我的問題的過程

對於 Windows:

python -m ensurepip

激活您的 env ex 后:venv

(venv) PS D:\your path> d:\your path\venv\scripts\python.exe -m pip install --upgrade pip

結果樣本:

收集點子

使用緩存的 pip-21.3-py3-none-any.whl (1.7 MB)

安裝收集的包:pip

嘗試卸載:pip

Found existing installation: pip 20.1.1

Uninstalling pip-20.1.1:

  Successfully uninstalled pip-20.1.1

成功安裝 pip-21.3

對於 python2.7,從https://bootstrap.pypa.io/pip/2.7/get-pip.py下載

然后運行

python get-pip.py

Windows中PIP升級步驟(一)首先,在Windows搜索框中輸入Command Prompt

(2) 接下來,打開命令提示符,您將看到以下屏幕,顯示您的用戶名(為避免任何權限問題,您可以考慮以管理員身份運行命令提示符):

C:\\Users\\Ron> (3) 在命令提示符中,鍵入“cd\\”以確保您的起點只有驅動器名稱:

C:\\用戶\\Ron>cd
(4) 按回車,你會看到驅動器名稱 C:>

C:> (5) 找到你的 Python 應用程序路徑,也就是你最初安裝 Python 的文件夾。

以下是 Python 應用程序路徑的示例:

C:\\Users\\Ron\\AppData\\Local\\Programs\\Python\\Python39

(6) 檢索到 Python 應用程序路徑后,在命令提示符中鍵入以下命令:

“cd”后跟您的 Python 應用程序路徑

對於我們的示例:

C:>cd C:\\Users\\Ron\\AppData\\Local\\Programs\\Python\\Python39 (7) 按回車,你會看到:

C:\\Users\\Ron\\AppData\\Local\\Programs\\Python\\Python39> (8) 要升級 PIP,請鍵入\/復制此命令,然后按 Enter:

python -m pip install --upgrade pip 這是命令在命令提示符中的樣子:

C:\\Users\\Ron\\AppData\\Local\\Programs\\Python\\Python39>python -m pip install ––upgrade pip (9) 你會注意到會安裝最新版本的 PIP:

成功安裝 pip-21.1.1 在 Windows 中檢查 PIP 版本的步驟 要隨時檢查 PIP 的版本,您需要使用 Python 腳本路徑,而不是 Python 應用程序路徑。

(1) 首先,鍵入“cd\\”以確保您的起點只有驅動器名稱:

C:\\用戶\\Ron>cd
(2) 然后,找到您的 Python 腳本路徑。 Scripts 文件夾應位於 Python 應用程序路徑中。

對於我們的示例,Python 腳本路徑是:

C:\\Users\\Ron\\AppData\\Local\\Programs\\Python\\Python39\\Scripts

(3) 鍵入“cd”,后跟 Python Scripts 路徑(然后按 Enter):

C:>cd C:\\Users\\Ron\\AppData\\Local\\Programs\\Python\\Python39\\Scripts (4) 最后輸入以下命令查看PIP的版本:

pip --version 對於我們的示例:

C:\\Users\\Ron\\AppData\\Local\\Programs\\Python\\Python39\\Scripts>pip ––version (5) 回車,你會看到PIP版本:

pip 21.1.1 現在,如果您想恢復到以前的 PIP 版本怎么辦?

您可以按照以下步驟輕松降級到以前版本的 PIP。

https:\/\/datatofish.com\/upgrade-pip\/<\/a> ----> 會幫助你更好

python -m ensurepip --user

如果你的 mac 不在 big sur 以上

你安裝了 py 3 -

我這樣做了,我現在沒有問題

我猜想回到舊版 2.7。

我在win11上遇到了同樣的錯誤,所以主要問題是在沒有管理員權限的情況下執行pip命令,所以用管理員權限打開你的終端,然后再次執行pip命令。 希望能幫助到你,

對於 Windows:

如果下載 Python 時pip不可用:運行命令

python get-pip.py

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM