PIP module has no "main" attribute

EDIT: The computer in question was a client machine with restrictions on what software can be installed. I'm not sure if this could be the cause of this issue or if the client's IT department gave the machine a corrupted pip version. The recommended answers below would probably have worked, but were blocked by the company's IT department and required an administrator login. Since then I have left this project and I hope to avoid such situations.

I am trying to install WHL file

When trying to execute:

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

      

I got an attribute error:

'module' object has no attribute 'main'

      

I ran help (pip) and

__main__ 

      

was listed as package content.

I am running Python 3.4 on the console.

+3


source to share


3 answers


they refactored it. you can support both 9 and 10 points using:

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

      



and then use pipmain as you used pip.main. eg

pipmain(['install', "--upgrade", "pip"])
pipmain(['install', "-q", "package"])

      

+7


source


easy_install --upgrade pip

worked for me.



+6


source


My problem was with my IDE (PyCharm). older versions of PyCharm do not support pip v10. The PyCharm upgrade solved it for me.

+3


source







All Articles