pip: no module named _internal

2020-01-30 03:55发布

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.

Thank you for your time!

标签: python pip
24条回答
霸刀☆藐视天下
2楼-- · 2020-01-30 04:32

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.

查看更多
三岁会撩人
3楼-- · 2020-01-30 04:34

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

查看更多
爱情/是我丢掉的垃圾
4楼-- · 2020-01-30 04:34

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.

查看更多
疯言疯语
5楼-- · 2020-01-30 04:37

(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

查看更多
不美不萌又怎样
6楼-- · 2020-01-30 04:38

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"

查看更多
趁早两清
7楼-- · 2020-01-30 04:39

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
查看更多
登录 后发表回答