Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
372 views
in Technique[技术] by (71.8m points)

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

My ultimate goal is to download and install awscli http://docs.aws.amazon.com/cli/latest/userguide/awscli-install-linux.html

Seems python and pip are required in order to accomplish my goal.

Installing python via yum isn't working for me, so I downloaded and installed python3 manually as follows:

wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tar.xz
tar xf Python-3.6.1.tar.xz
cd Python-3.6.1.tar.xz
./configure
make
sudo make altinstall

When I do

pip3.6 --version

I get this:

Traceback (most recent call last):
  File "/usr/local/bin/pip3.6", line 7, in <module>
    from pip import main
ImportError: cannot import name 'main'

Environment: RHEL 6.6 Accessed via ssh

What is going on? How to install pip and python3.6 correctly on my linux box?

Edit:

When trying to install via yum it fails so I am trying to avoid using yum:

[asemani@rcdc9pfda5r Python-3.6.1]$ sudo yum -y install python-pip

[sudo] password for asemeani: 
Loaded plugins: security
Setting up Install Process
No package python-pip available.
Error: Nothing to do

Another Edit:

After importing sys and then called sys.path this is what I get:

[asemani@rcdc9pfda5r Python-3.6.1]$ python3.6
Python 3.6.1 (default, Apr 28 2017, 11:03:27) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-17)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['', '/usr/local/lib/python36.zip', '/usr/local/lib/python3.6', '/usr/local/lib/python3.6/lib-dynload', '/usr/local/lib/python3.6/site-packages']
>>> quit()
[asemani@rcdc9pfda5r Python-3.6.1]$ ls -l /usr/local/lib/python3.6/site-packages
total 32
-rw-------  1 root root  126 Apr 27 23:45 easy_install.py
drwx------ 11 root root 4096 Apr 27 23:45 pip
drwx------  2 root root 4096 Apr 27 23:45 pip-9.0.1.dist-info
drwx------  5 root root 4096 Apr 27 23:45 pkg_resources
drwx------  2 root root 4096 Apr 27 23:45 __pycache__
-rw-r--r--  1 root root  119 Apr 27 23:45 README.txt
drwx------  5 root root 4096 Apr 27 23:45 setuptools
drwx------  2 root root 4096 Apr 27 23:45 setuptools-28.8.0.dist-info
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...