Python pip:没有名为 _internal 的模块

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/49940813/
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 19:19:12  来源:igfitidea点击:

pip: no module named _internal

pythonpip

提问by Grimdrem

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

当我尝试以任何方式使用 pip 时遇到问题。我正在使用 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).

我应该说我已经使用过它,我从来没有遇到过任何问题,但是从今天开始,当我使用任何命令时,我总是遇到相同的错误(例如使用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-pipfollowed by sudo apt-get install python-pipbut nothing changed.

我试过做sudo apt-get remove python-pipsudo apt-get install python-pip但没有任何改变。

Thank you for your time!

感谢您的时间!

回答by magicrebirth

This did it for me:

这为我做到了:

python -m pip install --upgrade pip

Environment: OSX && Python installed via brew

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

回答by YongHao Hu

An answer from askUbuntuworks.

来自askUbuntu的回答有效。

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-reinstallto reinstall pip.

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

Problem solved. Also works for python3.

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

回答by Abdallah Okasha

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 sudofor elevated permissions (sudo python3 get-pip.py --force-reinstall).

或使用sudo提升权限 ( sudo python3 get-pip.py --force-reinstall)。

Of course, you can also use pythoninstead of python3;)

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

Source

来源

回答by zangw

Refer to this issue list

参考这个问题列表

sudo easy_install pip

works for me under Mac OS

在 Mac OS 下对我有用

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

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

回答by GauthamGAjith

In file "/usr/local/bin/pip" changefrom pip._internal import mainto from pip import main

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

回答by Yi Yang Apollo

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'

这个问题可能是由于普通用户没有权限访问包 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

Check pip py file privilege.

检查 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  

solution : root user login and run

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

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

fix this issue.

解决这个问题。

回答by Levi Morrison

I've seen this issue when PYTHONPATHwas set to include the built-in site-packagesdirectory. Since Python looks there automatically it is unnecessary and can be removed.

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

回答by Dongcheng Wang

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

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

  1. use python3 -m pip --versionto 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.
  1. 用于python3 -m pip --version查看您是否安装了pip。
  2. 如果是,请运行python3 -m pip install --upgrade pip
  3. 如果没有,运行sudo apt-get install python3-pip,然后再做一次。

回答by Tinashe Makuti

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

这可能是由于版本冲突,尝试运行它,它会以某种方式删除旧的 pip。

sudo apt remove python pip

回答by tospo

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):

我刚刚遇到了同样的问题,就我而言,事实证明这是我的 virtualenv 中的 python 安装和站点范围的 python (Ubuntu) 之间的冲突。为我解决的是以这种方式运行 pip,以强制使用正确的 python 安装(在我的 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.

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