简体   繁体   English

Redhat试图使用pip ImportError:没有名为pip的模块

[英]Redhat trying to use pip ImportError: No module named pip

I am trying to use pip on my Redhat system. 我试图在我的Redhat系统上使用pip。

I installed pip following the instructions here , but when I try to use it, for example pip install , I get the following error code: 我按照这里的说明安装了pip,但是当我尝试使用它时,例如pip install ,我得到以下错误代码:

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

If pip is already installed and your unable to access it, one of the reason could be that you don't have permissions to read or execute the library. 如果已经安装了pip并且您无法访问它,原因之一可能是您没有读取或执行库的权限。 Try doing 试着做

sudo chmod -R u+rx /usr/lib/python2.7/site-packages/pip/

If pip is installed in a different folder, you can obtain the folder path by doing 如果pip安装在其他文件夹中,则可以通过执行操作获取文件夹路径

>>> import pip
>>> pip.__path__
['/usr/lib/python2.7/site-packages/pip']

this issue due to common user do not have privilege to access packages py file. 这个问题由于普通用户没有权限访问包py文件。
1. root user can run 'pip list' 1. root用户可以运行'pip list'
2. other common user cannot run '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

solution : root user login and run 解决方案:root用户登录并运行

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

fix this issue. 解决这个问题。

如果您没有root权限并在python 2.6上运行,那么您可以尝试这个文件https://bootstrap.pypa.io/2.6/get-pip.py (它来自您使用的相同指令,它是一个简单的python安装所有依赖项和pip本身的脚本)并使用命令python get-pip.py --user运行它

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM