无法安装pip和软件包

3
我正在使用Python 3.6版本。Python自带了Pip,但似乎找不到Pip。我已经尝试了各种解决方案,但都没有成功。请帮我解决这个问题。
已进行的验证: 路径设置为C:\Program Files\Python36\Scripts 添加了三个主机条目
PIP错误:
C:\Users\>pip
Traceback (most recent call last):
  File "c:\program files\python36\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\program files\python36\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Program Files\Python36\Scripts\pip.exe\__main__.py", line 5, in <module>
ImportError: cannot import name 'main'

已尝试的解决方案:

pip install --trusted-host pypi.python.org --trusted-host pypi.org --trusted-host files.pythonhosted.org {package name}

C:\Users\>pip
Traceback (most recent call last):
  File "c:\program files\python36\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\program files\python36\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Program Files\Python36\Scripts\pip.exe\__main__.py", line 5, in <module>
ImportError: cannot import name 'main'

C:\Users>python3 -m pip uninstall pip setuptools
'python3' is not recognized as an internal or external command,
operable program or batch file.

C:\Users>python
Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 17:00:18) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> python3 -m pip uninstall pip setuptools
  File "<stdin>", line 1
    python3 -m pip uninstall pip setuptools
                 ^
SyntaxError: invalid syntax
>>> python3 -m pip uninstall pip setuptools
  File "<stdin>", line 1
    python3 -m pip uninstall pip setuptools
                 ^
SyntaxError: invalid syntax
>>> pip install --trusted-host pypi.python.org --trusted-host pypi.org --trusted-host files.pythonhosted.org {package name}
  File "<stdin>", line 1
    pip install --trusted-host pypi.python.org --trusted-host pypi.org --trusted-host files.pythonhosted.org {package name}
              ^
SyntaxError: invalid syntax
>>>

使用以下版本

C:\Users\>python
Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 17:00:18) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
5个回答

0

尝试使用

pip2

适用于 Python 2。

pip3

针对Python 3版本进行操作

并在管理员命令行中执行。


C:\Users>pip3 install --trusted-host pypi.python.org --trusted-host pypi.org --trusted-host files.pythonhosted.org {package name} 回溯(最近的调用最先): 文件 "c:\program files\python36\lib\runpy.py",行 193,在 _run_module_as_main 中 "main", mod_spec) 文件 "c:\program files\python36\lib\runpy.py",行 85,在 run_code 中 exec(code, run_globals) 文件 "C:\Program Files\Python36\Scripts\pip3.exe_main.py",行 5,在 <module> 中 ImportError: 无法导入名称 'main' - Phoenix2529

0
在Windows 10上,我遇到了同样的问题。PIP 19已经安装在我的系统中,但没有显示出来。错误提示是No Module Found
python -m pip uninstall pip
python -m pip install pip==9.0.3

pip 降级至 9.0.3 对我来说很有效。

我已经在这里回答过了。


0

请检查您是否已将路径添加到这些目录中(如果您正在使用python3.x版本)- C:\ Users \ tojose \ AppData \ Local \ Programs \ Python \ Python3.x和pip C:\ Users \ tojose \ AppData \ Local \ Programs \ Python \ Python3.x \ Scripts,因为pip * .exe存储在此处。


C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\ProgramData\Oracle\Java\javapath;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0;C:\Windows\NSSAppLogs\FW-JetBrains-PyCharm Community Edition-2017.3-3264-171.4694.38;C:\Program Files\Python36;C:\Program Files\Python36\Scripts; - Phoenix2529
这是添加到环境变量中的路径。 - Phoenix2529
Python 默认安装在本地用户文件夹中,而不是程序文件夹下。请将您的路径更改为以下内容: %USERPROFILE%\AppData\Local\Programs\Python\Python36 和 %USERPROFILE%\AppData\Local\Programs\Python\Python36\Scripts 。 - Tom J

0

尝试使用完整路径来安装pip和您想要安装的软件包。

例如(适用于Python 3.6):

C:\Python36\Scripts\pip install C:\Python36\requests-2.18.4-py2.py3-none-any.whl


0

我曾经遇到过同样的问题,尝试了几个命令都没有结果。后来我只是将我的pip版本从19.10升级到了20.3.3版本,现在它可以正常工作了。

python -m pip install --upgrade pip 

(适用于Windows)

enter image description here

注意:您正在Python REPL中应用pip命令,这是错误的。 通过使用exit()函数退出Python并像这样编写。

enter image description here

在我的情况下,我已经安装了新版本。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接