Python 为什么我在安装 pip 后立即收到 ImportError: No module named pip ' ?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32639074/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 11:57:16  来源:igfitidea点击:

Why am I getting ImportError: No module named pip ' right after installing pip?

pythonwindows-7pip

提问by Deval Pandya

I have installed pip and ez setup. I also checked the system path and I can see the module in the folder structure. Still when i try to run pip command, I get an Import error saying no module named pip. I am running 32bit python on a windows7 machine

我已经安装了 pip 和 ez setup。我还检查了系统路径,我可以在文件夹结构中看到模块。仍然当我尝试运行 pip 命令时,我收到一个导入错误,提示没有名为 pip 的模块。我在 windows7 机器上运行 32 位 python

采纳答案by Gorodeckij Dimitrij

Just be sure that you have include python to windows PATH variable, then run python -m ensurepip

只要确保您已将 python 包含到 Windows PATH 变量中,然后运行 python -m ensurepip

回答by Setmax

try to type pip3 instead pip. also for upgrading pip dont use pip3 in the command

尝试输入 pip3 而不是 pip。也用于升级 pip 不要在命令中使用 pip3

python -m pip install -U pip

maybe it helps

也许它有帮助

回答by twasbrillig

The ensurepipmodule was added in version 3.4 and then backported to 2.7.9.

ensurepip模块是在 3.4 版中添加的,然后向后移植到 2.7.9。

So make sure your Python version is at least 2.7.9 if using Python 2, and at least 3.4 if using Python 3.

因此,如果使用 Python 2,请确保您的 Python 版本至少为 2.7.9,如果使用 Python 3,则至少为 3.4。

回答by Gonzalo Blotta

I've solved this error downloading the executable file for python 3.7. I've had downloaded the embeddeable version and got that error. Now it works! :D

我已经解决了下载 python 3.7 的可执行文件的错误。我已经下载了可嵌入版本并出现了该错误。现在它起作用了!:D

回答by Sloomy

turned out i had 2 versions of python on my laptop

原来我的笔记本电脑上有 2 个版本的 python

both commands worked for me

两个命令都对我有用

python -m ensurepip
py -m ensurepip

both with another installation path

两者都有另一个安装路径

c:\tools\python\lib\site-packages
c:\program files (x86)\microsoft visual studio\shared\python36_64\lib\site-packages 

only the first path was in my %PATH% variable

只有第一条路径在我的 %PATH% 变量中

回答by Amit Panasara

Follow steps given in https://michlstechblog.info/blog/python-install-python-with-pip-on-windows-by-the-embeddable-zip-file/. Replace xwith version number of Python.

按照https://michlstechblog.info/blog/python-install-python-with-pip-on-windows-by-the-embeddable-zip-file/ 中给出的步骤操作。替换x为 Python 的版本号。

  1. Open the pythonxx.__pthfile, located in your python folder.
  2. Edit the contents (e.g. D:\Pythonx.x.xto the following):
  1. 打开pythonxx.__pth位于 python 文件夹中的文件。
  2. 编辑内容(例如D:\Pythonx.x.x以下内容):
 D:\Pythonx.x.x 
 D:\Pythonx.x.x\DLLs
 D:\Pythonx.x.x\lib
 D:\Pythonx.x.x\lib\plat-win 
 D:\Pythonx.x.x\lib\site-packages

回答by Lucas Mota Alves

What solved the issue on my case was go to:

解决我案例问题的方法是:

cd C:\Program Files\Python37\Scripts

And run below command:

并运行以下命令:

easy_install.exe pip

回答by PratikPal

I'v solved this error by setting the correct path variables

我通过设置正确的路径变量解决了这个错误

    C:\Users\name\AppData\Local\Programs\Python\Python37\Scripts
    C:\Users\name\AppData\Local\Programs\Python\Python37\Lib\site-packages

回答by vaquar khan

I was facing same issue and resolved using following steps

我遇到了同样的问题并使用以下步骤解决了

1) Go to your paython package and rename "python37._pth" to python37._pth.save

1)转到您的paython包并将“python37._pth”重命名为python37._pth.save

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

2) 卷曲https://bootstrap.pypa.io/get-pip.py-o get-pip.py

3) then run python get-pip.py

3) 然后运行 ​​python get-pip.py

4) pip install django

4)pip安装django

Hope this help

希望这有帮助

回答by A-312

After running get_pip.pywith python embed you have to modify your pythonXX._pthfile. Add Lib\site-packages, to get something like this:

get_pip.py使用 python embed运行后,您必须修改pythonXX._pth文件。添加Lib\site-packages, 以获得如下内容:

pythonXX.zip
.
Lib\site-packages
# Uncomment to run site.main() automatically
#import site

If you don't you will get this error:

如果你不这样做,你会得到这个错误:

ModuleNotFoundError: No module named 'pip'

ModuleNotFoundError: 没有名为“pip”的模块

or

或者

python-3.8.2-embed-amd64\python.exe: No module named pip

python-3.8.2-embed-amd64\python.exe:没有名为 pip 的模块

λ pip
Traceback (most recent call last):
  File "runpy.py", line 193, in _run_module_as_main
  File "runpy.py", line 86, in _run_code
  File "python-3.8.2-embed-amd64\Scripts\pip.exe\__main__.py", line 4, in <module>
ModuleNotFoundError: No module named 'pip'

λ python -m pip
python-3.8.2-embed-amd64\python.exe: No module named pip