Python3.6 ImportError: cannot import name 'main' Linux RHEL6

前提是你 提交于 2019-11-28 17:54:02

You need to edit the pip3 file like so (your path could be different):

nano /Library/Frameworks/Python.framework/Versions/3.6/bin/pip3

And change the import main line so it says:

from pip._internal import main

After this change, my pip3 started to work and I am on macOS. If you are using Linux, your path could be something like /usr/bin/pip3

I found this tip and more information from this thread: https://github.com/pypa/pip/issues/5240

My OS is Linux Mint 18

sudo nano /usr/bin/pip3

Change

from pip import main

To

from pip._internal import main

Don't invoke pip/pip3 directly, which are shortcuts at different locations for different user and they are not well maintained when you upgrade pip (check 'which pip' and 'sudo which pip').

 $ sudo python -m pip install xxx  #for python2 
 $ sudo python3 -m pip install xxx  #for python3

These commands do not take shortcuts and directly invoke pip module, which is maintained very well (also works on Windows)

Arthur

sudo chmod -R a+rx /usr/local/lib/python3.6/site-packages

You can see the problem right there in your ls -l /usr/local/lib/python3.6/site-packages output that your pip directory is only readable by the owner, which is root.

Iyanuoluwa Ajao

Do a cd /usr/bin

Then sudo nano pip so as to edit the pip file

Change from pip import main to from pip._internal import main

This will resolve the issue

try the following as a way around the issue until it got solved

sudo python -m pip --version
>> pip 10.0.1 from /usr/local/lib/python2.7/site-packages/pip (python 2.7)
sudo python -m pip install numpy --upgrade
>> Requirement already up-to-date: numpy in /usr/local/lib/python2.7/site-packages (1.14.2)

I don't exactly know the answer, but: that error indicates that the script can find some package called pip, but not the right one. Probably, an old version of pip, from back before they created a main method (you can check pip.__version__ from the python shell).

I'm willing to bet that you still have another, older version of python installed which has its own version of pip. For some reason your pythonpath is loading that one instead of the one that goes with py3.6.

Some possibilities to look into:

  • I don't know anything about redhat, but is there some redhat-specific way of choosing the "default python" to be used?

  • Is the shebang line at the top of the pip script something like #!/usr/bin/env python instead of #!/usr/bin/python3.6 like it should be?

  • Is it possible to modify your shell's PATH so that the downloaded python is used?

  • Is it possible to change your PYTHONPATH (i think it gets added to the default value of sys.path inside python; look it up) so that it loads the new pip instead of the old pip?

My OS was Mac sierra and I had to change the following line

from pip import main

into

from pip._internal import main

Seems the get pip script was missing the fact that more than 1 version of python could reside on a machine. So I added the following lines:

PY2 = sys.version_info[0] == 2
PY3 = sys.version_info[0] == 3

For some reason it was missing this. Anyway this worked for me. Thanks for your help guys.

Do the following steps to solve the problem --(Ubuntu-Debian)

step 1 - Go to directory

cd usr/bin/

and open pip3 file using gedit or nano(via terminal) .

Step 2- change from pip import main into from pip._internal import main

P.S - If you donot have permission to change use command - sudo chmod 777 pip3 and save this file.

Hope this helps!!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!