pip:没有名为_internal的模块

问题:pip:没有名为_internal的模块

我尝试以任何方式使用pip时遇到问题。我正在使用Ubuntu 16.04.4

我应该说我已经使用过它,并且从未遇到任何问题,但是从今天开始,当我使用任何命令时,我总是会遇到相同的错误(例如使用的示例pip --upgrade)。

Traceback (most recent call last):
  File "/usr/local/bin/pip", line 7, in <module>
    from pip._internal import main
ImportError: No module named _internal

我尝试了sudo apt-get remove python-pip之后,sudo apt-get install python-pip但没有任何改变。

I have a problem when I try to use pip in any way. I’m using Ubuntu 16.04.4

I should say that I’ve used it already, and I never had any problem, but starting today when I use any command I always get the same error (as an example using pip --upgrade).

Traceback (most recent call last):
  File "/usr/local/bin/pip", line 7, in <module>
    from pip._internal import main
ImportError: No module named _internal

I have tried doing sudo apt-get remove python-pip followed by sudo apt-get install python-pip but nothing changed.


回答 0

这为我做到了:

python -m pip install --upgrade pip

环境:通过brew安装OSX && Python

This did it for me:

python -m pip install --upgrade pip

Environment: OSX && Python installed via brew


回答 1

askUbuntu的回答有效。

对于pip2.7,您可以首先安装curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py,然后python2.7 get-pip.py --force-reinstall重新安装pip。

问题解决了。也适用于python3。

An answer from askUbuntu works.

For pip2.7, you can at first curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py, then python2.7 get-pip.py --force-reinstall to reinstall pip.

Problem solved. Also works for python3.


回答 2

此解决方案适用于我:

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

或使用sudo获得更高的权限(sudo python3 get-pip.py --force-reinstall)。

当然,您也可以使用python代替python3;)

资源

This solution works for me:

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

or use sudo for elevated permissions (sudo python3 get-pip.py --force-reinstall).

Of course, you can also use python instead of python3 ;)

Source


回答 3

请参阅此问题列表

sudo easy_install pip

在Mac OS下为我工作

对于python3,可以尝试sudo easy_install-3.x pip取决于python 3.x版本。要么python3 -m pip install --user --upgrade pip

Refer to this issue list

sudo easy_install pip

works for me under Mac OS

For python3, may try sudo easy_install-3.x pip depends on the python 3.x version. Or python3 -m pip install --user --upgrade pip


回答 4

在文件“ / usr / local / bin / pip”中更改 from pip._internal import mainfrom pip import main

In file “/usr/local/bin/pip” change from pip._internal import main to from pip import main


回答 5

此问题可能是由于普通用户没有访问软件包py文件的特权。
1. root用户可以运行“ pip list”
2.其他普通用户不能运行“ pip list”

[~]$ pip list
Traceback (most recent call last):
  File "/usr/bin/pip", line 7, in <module>
from pip._internal import main
ImportError: No module named pip._internal

检查pip py文件特权。

[root@]# ll /usr/lib/python2.7/site-packages/pip/  
合計 24  
-rw-------  1 root root   24  6  7 16:57 __init__.py  
-rw-------  1 root root  163  6  7 16:57 __init__.pyc  
-rw-------  1 root root  629  6  7 16:57 __main__.py  
-rw-------  1 root root  510  6  7 16:57 __main__.pyc  
drwx------  8 root root 4096  6  7 16:57 _internal  
drwx------ 18 root root 4096  6  7 16:57 _vendor  

解决方案:root用户登录并运行

chmod -R 755 /usr/lib/python2.7 

解决此问题。

This issue maybe due to common user do not have privilege to access packages py file.
1. root user can run ‘pip list’
2. other common user cannot run ‘pip list’

[~]$ pip list
Traceback (most recent call last):
  File "/usr/bin/pip", line 7, in <module>
from pip._internal import main
ImportError: No module named pip._internal

Check pip py file privilege.

[root@]# ll /usr/lib/python2.7/site-packages/pip/  
合計 24  
-rw-------  1 root root   24  6月  7 16:57 __init__.py  
-rw-------  1 root root  163  6月  7 16:57 __init__.pyc  
-rw-------  1 root root  629  6月  7 16:57 __main__.py  
-rw-------  1 root root  510  6月  7 16:57 __main__.pyc  
drwx------  8 root root 4096  6月  7 16:57 _internal  
drwx------ 18 root root 4096  6月  7 16:57 _vendor  

solution : root user login and run

chmod -R 755 /usr/lib/python2.7 

fix this issue.


回答 6

为了完整起见,我刚遇到了“ Ubuntu Latest”问题……v18.04 …,并通过以下方式解决了该问题:

python3 -m pip install --upgrade pip

(注意,必须指定,python3因为它引用了Python 3.6.9。python同一系统上的命令引用了Python 2.7.17。由于这显然是系统范围的安装,因此它遇到了[“ not sudo” …]权限。错误,但这没关系,因为无论如何都是错的。我遇到了pip3。)问题。

For completeness, I just encountered this problem with “Ubuntu latest” … v18.04 … and fixed it in this way:

python3 -m pip install --upgrade pip

(Notice that it was necessary to specify python3 since this references Python 3.6.9. The python command on the same system references Python 2.7.17. Since this is apparently a system-wide installation it encountered a [“not sudo” …] permission error, but it didn’t matter because it was the wrong thing to do anyway. I was encountering the problem with pip3.)


回答 7

PYTHONPATH设置为包含内置site-packages目录时,我已经看到了此问题。由于Python自动出现在那儿,因此没有必要,可以将其删除。

I’ve seen this issue when PYTHONPATH was set to include the built-in site-packages directory. Since Python looks there automatically it is unnecessary and can be removed.


回答 8

我只是遇到了同样的问题,以我为例,事实证明这是我的virtualenv中的python安装与站点范围的python(Ubuntu)之间的冲突。为我解决的是以这种方式运行pip,以强制使用正确的python安装(在我的vortualenv中):

python3 -m pip install PACKAGE

代替

pip3 install PACKAGE

当我尝试遵循一些建议重新安装pip的答案时,我意识到了这一点,尽管我已经激活了virtualenv,但我收到的错误输出却指向现有的站点范围内的python库路径。值得一试,然后再删除并重新安装东西。

I just encountered the same problem and in my case, it turns out this is a conflict between the python installation in my virtualenv and the site-wide python (Ubuntu). What solves it for me is to run pip in this way, to force usage of the correct python installation (in my vortualenv):

python3 -m pip install PACKAGE

instead of

pip3 install PACKAGE

I realised this when I tried to follow some of the answers here that suggest re-installing pip and the error output I got was pointing to an existing site-wide python library path although I had activated my virtualenv. Worth trying before deleting and re-installing stuff.


回答 9

您使用的是python2还是python3?以下命令可能有所不同!

  1. 用于python3 -m pip --version查看是否已安装pip。
  2. 如果是,请运行python3 -m pip install --upgrade pip
  3. 如果否,请运行sudo apt-get install python3-pip,然后再次执行。

Are you using python2 or python3? The following command could be different!

  1. use python3 -m pip --version to see if you have pip installed.
  2. if yes, run python3 -m pip install --upgrade pip.
  3. if no, run sudo apt-get install python3-pip, and do it again.

回答 10

它可能是由于版本冲突所致,请尝试运行此命令,它将以某种方式删除较旧的点。

sudo apt remove python pip

Its probably due to a version conflict, try to run this, it will remove the older pip somehow.

sudo apt remove python pip

回答 11

为了我

python -m pip uninstall pip

解决了这个问题。参考

For me

python -m pip uninstall pip

solved the issue. Reference


回答 12

我通过运行以下命令解决了此错误:

sudo apt remove python-pip
wget https://bootstrap.pypa.io/get-pip.py
sudo python get-pip.py

它将删除先前安装的pip并重新安装。谢谢 :)

I have fixed this error by running the following commands:

sudo apt remove python-pip
wget https://bootstrap.pypa.io/get-pip.py
sudo python get-pip.py

It will remove the previously installed pip and reinstall it. Thanks :)


回答 13

以下解决方案在我的机器上为python2.7解决了问题:“ $ curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py”,然后是“ $ sudo python2.7 get-pip .py –force-reinstall“

The following solution solved the problem on my machine for python2.7 “$ curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py” and then “$ sudo python2.7 get-pip.py –force-reinstall”


回答 14

仅对于当前用户:

easy_install --user pip

要么

python -m pip install --upgrade --user pip

第二个可能会给出/usr/bin/python: No module named pip 即使which pip找到名为pip的模块。在这种情况下,请尝试easy_install

For the current user only:

easy_install --user pip

or

python -m pip install --upgrade --user pip

The second may give /usr/bin/python: No module named pip Even if which pip finds the module named pip. In this case try the easy_install


回答 15

当我尝试通过pip3安装软件包时,在Windows上遇到了相同的错误:

Traceback (most recent call last):
  File "d:\anaconda\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "d:\anaconda\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "D:\Anaconda\Scripts\pip3.6.exe\__main__.py", line 5, in <module>
ModuleNotFoundError: No module named 'pip._internal'

我的python是通过Anaconda安装的。我通过conda重新安装pip解决了这个问题:

conda install pip

之后,pip恢复正常。

I met the same error on Windows when I tried to install a package via pip3:

Traceback (most recent call last):
  File "d:\anaconda\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "d:\anaconda\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "D:\Anaconda\Scripts\pip3.6.exe\__main__.py", line 5, in <module>
ModuleNotFoundError: No module named 'pip._internal'

My python is installed via Anaconda. I solved this issue by reinstalling pip via conda:

conda install pip

After that, pip returns to normal.


回答 16

什么都没有对我有用,但只有一件事:我在命令前使用了sudo,它工作正常。

Nothing worked for me, but only one thing: I used sudo in front of the command and it is working fine.


回答 17

在将python安装从3.6升级到3.7后,我在虚拟环境中存在相同的问题,但仅在vent全局pip上可以正常工作,要解决此问题,请在重新创建后停用并删除我的虚拟环境,现在在venv上可以了:

deactivate
rm -rvf venv 

然后重新创建虚拟环境。我使用mac OS 10.11和python 3

I have the same problem on my virtual environment after upgrade python installation from 3.6 to 3.7 but only on vent globally pip work fine, to solve it I deactivate and delete my virtual environment after recreate again and now is fine, on venv:

deactivate
rm -rvf venv 

and after recreate the virtual environment. I use mac OS 10.11, and python 3


回答 18

(在Windows上)不确定为什么会这样,但是我的PYTHONPATH设置指向安装了python的c:\ python27。与virtualenv结合使用会产生上述错误。

通过一起删除PYTHONPATH env var来解决

(On windows) not sure why this was happening but I had my PYTHONPATH setup to point to c:\python27 where python was installed. in combination with virtualenv this produced the mentioned bug.

resolved by removing the PYTHONPATH env var all together


回答 19

我的解决方案:像大多数其他答案一样的第一步:

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python2.7 get-pip.py --force-reinstall

第二,添加软链接

sudo ln -s /usr/local/bin/pip /usr/bin/pip

my solution: first step like most other answer:

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python2.7 get-pip.py --force-reinstall

second, add soft link

sudo ln -s /usr/local/bin/pip /usr/bin/pip

回答 20

此命令对我有用。

卷曲https://bootstrap.pypa.io/get-pip.py -o get-pip.py python get-pip.py –force-reinstall –user

This command works for me.

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py python get-pip.py –force-reinstall –user


回答 21

您可以先将其删除,然后重新安装,即可。对于centos:

yum remove python-pip
yum install python-pip

you can remove it first, and install again ,it will be ok. for centos:

yum remove python-pip
yum install python-pip

回答 22

我通过解决这个问题

sudo apt-get install python3-pip

这甚至适用于python2.7,令人惊讶…

I fixed this problem by

sudo apt-get install python3-pip

this worked even for python2.7, amazing…


回答 23

我的解决方案是添加import pip到链接到pip/pip3命令的脚本。

首先,/usr/local/bin/pip使用您喜欢的文本编辑器和sudo模式打开文件(例如)。例如,我sudo vim /usr/local/bin/pip用来打开脚本文件。

您将获得一些文件,如下所示:

import re
import sys

from pip._internal import main

if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
    sys.exit(main())

然后,在问题解决import pip之前插入该语句from pip._internal import main

My solution is adding import pip to the script linked to the pip/pip3 commands.

Firstly, open the file (e.g. /usr/local/bin/pip) with your favorite text editor and the sudo mode. For example, I use sudo vim /usr/local/bin/pip to open the script file.

You will obtain some file as following:

import re
import sys

from pip._internal import main

if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
    sys.exit(main())

Afterwards, insert the statement import pip just before the from pip._internal import main then the issue is resolved.


回答 24

这些通常来自使用pip来“更新”系统安装的pip,和/或在用户下具有多个pip安装。我的解决方案是清除用户下已安装的多个pip,重新安装pip repo,然后如上所述进行“ pip install –user pip”。

请参阅:https//github.com/pypa/pip/issues/5599,以获取正式的完整讨论以及针对该问题的修复程序。

These often comes from using pip to “update” system installed pip, and/or having multiple pip installs under user. My solution was to clean out the multiple installed pips under user, reinstall pip repo, then “pip install –user pip” as above.

See: https://github.com/pypa/pip/issues/5599 for an official complete discussion and fixes for the problem.


回答 25

我尝试了以下命令来解决此问题,它对我有用:

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

I tried the following command to solve the issue and it worked for me:

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