Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PIP module has no attribute "main"

Tags:

python

EDIT: The computer in question was a client machine with restrictions on what software could be installed. I'm unsure if that may have been a cause of the issue or if the client's IT department gave the machine a corrupted version of pip. The recommended answers below probably would have worked but were blocked by the company's IT department and required admin login to do. I have since left that project and hope to avoid similar situations.

I'm attempting to install a WHL file

While attempting to run:

import pip
my_path = <a path to the WHL file>
pip.main(['install', my_path])

I received an Attribute error:

'module' object has no attribute 'main'

I ran help(pip) and

__main__ 

was listed as a package content.

I'm running Python 3.4 in the console.

like image 295
DCUFan7 Avatar asked Apr 13 '17 18:04

DCUFan7


2 Answers

they made a refactoring. you can support both 9 and 10 pip by using:

try:
    from pip import main as pipmain
except:
    from pip._internal.main import main as pipmain

and then use pipmain as you used pip.main. for example

pipmain(['install', "--upgrade", "pip"])
pipmain(['install', "-q", "package"])
like image 88
Alexey ALERT Rubasheff Avatar answered Oct 13 '22 01:10

Alexey ALERT Rubasheff


easy_install --upgrade pip worked for me.

like image 22
coding_idiot Avatar answered Oct 12 '22 23:10

coding_idiot