PIP module has no attribute “main”

前端 未结 5 1155
渐次进展
渐次进展 2021-01-04 02:18

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 c

相关标签:
5条回答
  • 2021-01-04 02:46

    My issue was related to my IDE (PyCharm). older versions of PyCharm does not support pip v10. Upgrading PyCharm solved it for me.

    0 讨论(0)
  • 2021-01-04 02:51

    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"])
    
    0 讨论(0)
  • 2021-01-04 02:52

    From pip 20.0.0, it's:

    from pip._internal.cli.main import main as pipmain
    
    0 讨论(0)
  • 2021-01-04 02:57

    For more recent versions of pip (pip>=10.0.0), the functionality described in the other answers will no longer work. I recommend running the pip with subprocess as follows:

    import subprocess
    import sys
    
    my_path = <a path to the WHL file>
    command_list = [sys.executable, "-m", "pip", "install", my_path]
    with subprocess.Popen(command_list, stdout=subprocess.PIPE) as proc:
        print(proc.stdout.read())
    

    This solution uses the current python executable to run the pip command as a commandline command. It was inspired by the solution mentioned here.

    0 讨论(0)
  • 2021-01-04 03:08

    easy_install --upgrade pip worked for me.

    0 讨论(0)
提交回复
热议问题