Python Pip 安装:无法打开文件 pip,或父模块 '' 未加载
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28864307/
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
Pip install: can't open file pip, or Parent module '' not loaded
提问by Koos
Thanks for reading this in the first place.
首先感谢您阅读本文。
I'm trying to install Django. So here's what I do in the command line:
我正在尝试安装 Django。所以这是我在命令行中所做的:
C:\>python34 pip install Django
And here's what I get:
这就是我得到的:
C:\Python34\python.exe: can't open file 'pip': [Errno 2] No such file or directory
If I do the same from the site-packages directory:
如果我从 site-packages 目录中执行相同的操作:
C:\Python34\Lib\site-packages>python34 pip install Django
Traceback (most recent call last):
File "C:\Python34\lib\runpy.py", line 170, in _run_module_as_main
"__main__", mod_spec)
File "C:\Python34\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "pip\__main__.py", line 2, in <module>
from .runner import run
SystemError: Parent module '' not loaded, cannot perform relative import
I used pip before, and it worked fine, but now I don't know how to run it properly... I tried to find an answer first, but I don't understand any of them. Probably because I'm relatively new to all this. Could anyone explain in first-grade-level-language what I need to do to get this right?
我之前用过 pip,它工作得很好,但现在我不知道如何正确运行它......我试图先找到答案,但我不明白其中任何一个。可能是因为我对这一切都比较陌生。谁能用一年级的语言解释我需要做什么才能做到这一点?
回答by Selcuk
The command pip
is not a Python module. It is an executable. This should work:
该命令pip
不是 Python 模块。它是一个可执行文件。这应该有效:
C:\> pip install Django
回答by FlipperPA
IIRC, pip on Windows installs to C:\Python34\Scripts by default. So, if that's isn't on your system path, you'd actually need to do this:
IIRC,Windows 上的 pip 默认安装到 C:\Python34\Scripts。因此,如果这不在您的系统路径上,您实际上需要这样做:
C:\> \Python34\Scripts\pip install Django
Also, read up in virtualenv and virtualenvwrapper. It'll make your life a lot easier - cheers.
另外,请阅读 virtualenv 和 virtualenvwrapper。它会让你的生活更轻松 - 干杯。
回答by clare
Assuming you have pip installed and you want to do this through python as opposed to the standalone pip client, you can also do
假设你已经安装了 pip 并且你想通过 python 而不是独立的 pip 客户端来做到这一点,你也可以这样做
python -m pip install SomePackage