Bug 1569488

Summary: [abrt] python3-pip: module(): pip3:7:<module>:ImportError: cannot import name 'main'
Product: [Fedora] Fedora Reporter: thilp
Component: python-pipAssignee: Tomas Orsava <torsava>
Status: CLOSED ERRATA QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 27CC: bkabrda, cstratak, metherid, mhroncok, ncoghlan, socertis, SShehriyar266, tflink, TicoTimo, torsava
Target Milestone: ---   
Target Release: ---   
Hardware: x86_64   
OS: Unspecified   
URL: https://retrace.fedoraproject.org/faf/reports/bthash/e9afcc73a400032e7843983eed88c47ceb8d8266
Whiteboard: abrt_hash:bc47de74540b1f133cd6d189c51d352ecab99d8d;VARIANT_ID=workstation;
Fixed In Version: python-pip-9.0.3-2.fc28 python-pip-9.0.3-2.fc27 python-pip-9.0.3-2.fc26 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2018-04-19 13:52:31 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
File: backtrace
none
File: cgroup
none
File: cpuinfo
none
File: environ
none
File: mountinfo
none
File: namespaces
none
File: open_fds none

Description thilp 2018-04-19 11:43:16 UTC
Description of problem:
Upgraded pip from v9.0.3 to 10.0.0 as follows:

pip3 install --upgrade --user pip

The upgrade procedure seemed to work. Immediately afterwards, I tried to upgrade different packages:

pip3 install --upgrade --user mkdocs mkdocs-material

And only got the stacktrace associated to "ImportError: cannot import name 'main'".

Version-Release number of selected component:
python3-pip-9.0.3-1.fc27

Additional info:
reporter:       libreport-2.9.3
cmdline:        /usr/bin/python3 /usr/bin/pip3 install --upgrade --user mkdocs mkdocs-material
crash_function: module
exception_type: ImportError
executable:     /usr/bin/pip3
kernel:         4.15.17-300.fc27.x86_64
runlevel:       N 5
type:           Python3
uid:            1000

Truncated backtrace:
pip3:7:<module>:ImportError: cannot import name 'main'

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

Local variables in innermost frame:
__name__: '__main__'
__doc__: None
__package__: None
__loader__: <_frozen_importlib_external.SourceFileLoader object at 0x7f31a8d21e10>
__spec__: None
__annotations__: {}
__builtins__: <module 'builtins' (built-in)>
__file__: '/usr/bin/pip3'
__cached__: None
re: <module 're' from '/usr/lib64/python3.6/re.py'>
sys: <module 'sys' (built-in)>

Comment 1 thilp 2018-04-19 11:43:24 UTC
Created attachment 1424020 [details]
File: backtrace

Comment 2 thilp 2018-04-19 11:43:26 UTC
Created attachment 1424021 [details]
File: cgroup

Comment 3 thilp 2018-04-19 11:43:27 UTC
Created attachment 1424022 [details]
File: cpuinfo

Comment 4 thilp 2018-04-19 11:43:29 UTC
Created attachment 1424023 [details]
File: environ

Comment 5 thilp 2018-04-19 11:43:30 UTC
Created attachment 1424024 [details]
File: mountinfo

Comment 6 thilp 2018-04-19 11:43:32 UTC
Created attachment 1424025 [details]
File: namespaces

Comment 7 thilp 2018-04-19 11:43:33 UTC
Created attachment 1424026 [details]
File: open_fds

Comment 8 Charalampos Stratakis 2018-04-19 11:50:26 UTC
Bugs like that are a common occurrence when updating pip with itself, as it replaces the system installed packages with the ones installed from pypi (and then rpm will not own the files) and pip doesn't play well will all systems and configs. Also pip 10 hides a lot of internals which were exposed with previous versions.

I have worked on updating the package but there are various issues and I would prefer to wait until most of the issues are ironed out upstream. Please wait for the official package update from Fedora.

Comment 9 Miro Hrončok 2018-04-19 13:52:31 UTC
When you install new version of pip (the way you did) it installs files inside your home directory.

When you run pip3, it runs /usr/bin/pip3 and that is from the Fedora package. It expects pip module to have some interface (i.e. it contains "main" to import), yet your pip from home is newer and it doesn't have "main" and it fails. There is nothing we can do from that in Fedora.

Here are some tips:

 * check whether pip installs ~/.local/bin/pip3 or only ~/.local/bin/pip
 * check if ~/.local/bin is in your path
 * always invoke pip with "python3 -m pip"
 * run "python3 -Ei -m pip" to run the system pip

Comment 10 Muhammad Shehriyar Qureshi 2018-04-20 12:10:07 UTC
Similar problem has been detected:

It appeared using both pip and pip3
I ran
pip install --upgrade pip --user

pip3 install --upgrade pip --user

This caused the problem.

reporter:       libreport-2.9.3
cmdline:        /usr/bin/python3 /usr/bin/pip3
crash_function: module
exception_type: ImportError
executable:     /usr/bin/pip3
kernel:         4.15.17-300.fc27.x86_64
package:        python3-pip-9.0.3-1.fc27
reason:         pip3:7:<module>:ImportError: cannot import name 'main'
runlevel:       N 5
type:           Python3
uid:            1000

Comment 11 Tomas Orsava 2018-04-23 09:38:34 UTC
Hey, Muhammad! That seems odd, installing with --user shouldn't break things like that. Have you before that used pip(3) with sudo, perhaps?

Could you please run these two commands and report back?

$ rpm -V python2-pip
$ rpm -V python3-pip

Comment 12 Brian Weber 2018-05-01 06:12:17 UTC
Similar problem has been detected:

tried to run pip3 after failing to upgrade pip many times and finally reinstalling it via dnf

error when I tried to upgrade from 9.0.3 to 10.0.1

pip3 install --upgrade pip                                            
Collecting pip                                 
  Using cached https://files.pythonhosted.org/packages/0f/74/ecd13431bcc456ed390b44c8a6e917c1820365cbebcb6a8974d1cd045ab4/pip-10.0.1-py2.py3-none-any.whl                                     
Installing collected packages: pip             
  Found existing installation: pip 9.0.3       
    Uninstalling pip-9.0.3:                    
Exception:                                     
Traceback (most recent call last):             
  File "/usr/lib64/python3.6/shutil.py", line 544, in move                                     
    os.rename(src, real_dst)                   
OSError: [Errno 18] Invalid cross-device link: '/usr/bin/pip3' -> '/tmp/pip-vnlj0f9t-uninstall/usr/bin/pip3'                                                                                  

During handling of the above exception, another exception occurred:                            

Traceback (most recent call last):             
  File "/usr/lib/python3.6/site-packages/pip/basecommand.py", line 215, in main                
    status = self.run(options, args)           
  File "/usr/lib/python3.6/site-packages/pip/commands/install.py", line 365, in run            
    strip_file_prefix=options.strip_file_prefix,                                               
  File "/usr/lib/python3.6/site-packages/pip/req/req_set.py", line 778, in install             
    requirement.uninstall(auto_confirm=True)   
  File "/usr/lib/python3.6/site-packages/pip/req/req_install.py", line 754, in uninstall       
    paths_to_remove.remove(auto_confirm)       
  File "/usr/lib/python3.6/site-packages/pip/req/req_uninstall.py", line 115, in remove        
    renames(path, new_path)
  File "/usr/lib/python3.6/site-packages/pip/utils/__init__.py", line 267, in renames
    shutil.move(old, new)
  File "/usr/lib64/python3.6/shutil.py", line 559, in move
    os.unlink(src)
PermissionError: [Errno 13] Permission denied: '/usr/bin/pip3'
You are using pip version 9.0.3, however version 10.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

reporter:       libreport-2.9.3
cmdline:        /usr/bin/python3 /usr/bin/pip3
crash_function: module
exception_type: ImportError
executable:     /usr/bin/pip3
kernel:         4.15.17-300.fc27.x86_64
package:        python3-pip-9.0.3-1.fc27
reason:         pip3:7:<module>:ImportError: cannot import name 'main'
runlevel:       N 5
type:           Python3
uid:            1000

Comment 13 Miro Hrončok 2018-05-01 08:18:57 UTC
> pip3 install --upgrade pip 

this cannot work by deign.

Please, use venv, or --user. If you use --user, run pip with `python3 -m pip` to avoid the originally reported problem.

Comment 14 Brian Weber 2018-05-01 08:42:41 UTC
System-wide pip is not intended to be upgraded this way? So it's just updated by the package manager?

Comment 15 Miro Hrončok 2018-05-01 09:16:22 UTC
Exactly.

Comment 16 Brian Weber 2018-05-01 23:41:44 UTC
(In reply to Miro Hrončok from comment #15)
> Exactly.

Thank you for responding to my question and volunteering your time to contribute to pip.

However, the behavior of pip gave me no indication that running "pip install --upgrade pip" cannot work by design. In fact, when installing livestreamer systemwide, pip told me to run "pip install --upgrade pip". If this cannot work, why doesn't pip tell me to run "pip install --user --upgrade pip"?

Comment 17 Miro Hrončok 2018-05-02 08:11:07 UTC
Good point. Opened as https://bugzilla.redhat.com/show_bug.cgi?id=1573755

Comment 18 Brian Weber 2018-05-02 12:24:04 UTC
Thanks Miro

Comment 19 Miro Hrončok 2018-05-04 09:06:46 UTC

*** This bug has been marked as a duplicate of bug 1571650 ***

Comment 20 Fedora Update System 2018-05-05 15:20:12 UTC
python-pip-9.0.3-2.fc28 has been submitted as an update to Fedora 28. https://bodhi.fedoraproject.org/updates/FEDORA-2018-7146cb4e7f

Comment 21 Fedora Update System 2018-05-06 10:09:08 UTC
python-pip-9.0.3-2.fc28 has been pushed to the Fedora 28 testing repository. If problems still persist, please make note of it in this bug report.
See https://fedoraproject.org/wiki/QA:Updates_Testing for
instructions on how to install test updates.
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2018-7146cb4e7f

Comment 22 Fedora Update System 2018-05-07 10:12:03 UTC
python-pip-9.0.3-2.fc27 has been submitted as an update to Fedora 27. https://bodhi.fedoraproject.org/updates/FEDORA-2018-b795b92cc0

Comment 23 Fedora Update System 2018-05-07 10:24:15 UTC
python-pip-9.0.3-2.fc26 has been submitted as an update to Fedora 26. https://bodhi.fedoraproject.org/updates/FEDORA-2018-fcbef2ab8c

Comment 24 Fedora Update System 2018-05-07 14:33:47 UTC
python-pip-9.0.3-2.fc27 has been pushed to the Fedora 27 testing repository. If problems still persist, please make note of it in this bug report.
See https://fedoraproject.org/wiki/QA:Updates_Testing for
instructions on how to install test updates.
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2018-b795b92cc0

Comment 25 Fedora Update System 2018-05-08 00:03:19 UTC
python-pip-9.0.3-2.fc26 has been pushed to the Fedora 26 testing repository. If problems still persist, please make note of it in this bug report.
See https://fedoraproject.org/wiki/QA:Updates_Testing for
instructions on how to install test updates.
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2018-fcbef2ab8c

Comment 26 Fedora Update System 2018-05-09 21:25:19 UTC
python-pip-9.0.3-2.fc28 has been pushed to the Fedora 28 stable repository. If problems still persist, please make note of it in this bug report.

Comment 27 Fedora Update System 2018-05-13 20:17:34 UTC
python-pip-9.0.3-2.fc27 has been pushed to the Fedora 27 stable repository. If problems still persist, please make note of it in this bug report.

Comment 28 Fedora Update System 2018-05-15 20:00:14 UTC
python-pip-9.0.3-2.fc26 has been pushed to the Fedora 26 stable repository. If problems still persist, please make note of it in this bug report.

Comment 29 Petr Viktorin (pviktori) 2018-09-19 16:23:01 UTC
*** Bug 1630830 has been marked as a duplicate of this bug. ***