ImportError: cannot import name main when running pip --version command in windows7 32 bit

后端 未结 16 1415
余生分开走
余生分开走 2020-11-28 01:28

I\'ve installed the latest python (2.7.9) bundled with pip and setuptools for windows 32-bit. I\'ve tried reinstalling pip but the problem persists.

Here\'s the erro

相关标签:
16条回答
  • 2020-11-28 01:48

    On MacOS if you've installed python via Homebrew, change the line in /usr/local/opt/python/libexec/bin/pip

    from

    from pip.internal import main
    

    to

    from pip._internal import main
    

    Or use this one liner: sed -i '' "s/from pip import main/from pip._internal import main/" /usr/local/opt/python/libexec/bin/pip

    Explanation:

    The issue is caused by the changes in pip version 10 moving internal namespace under main._internal and the bin script put in place by homebrew still looking it from the old place (where it used to be in version 9). Issue and some discussion https://github.com/pypa/pip/issues/5240

    0 讨论(0)
  • 2020-11-28 01:48

    Open your terminal linux.

    hash -d pip
    
    0 讨论(0)
  • 2020-11-28 01:50

    A simple solution that works with Ubuntu, but may fix the problem on windows too:

    Just call

    pip install --upgrade pip
    
    0 讨论(0)
  • 2020-11-28 01:55

    try this

    #!/usr/bin/python
    # GENERATED BY DEBIAN
    
    import sys
    
    # Run the main entry point, similarly to how setuptools does it, but because
    # we didn't install the actual entry point from setup.py, don't use the
    # pkg_resources API.i
    try:
        from pip import main
    except ImportError:
        from pip._internal import main
    if __name__ == '__main__':
        sys.exit(main())
    
    0 讨论(0)
  • 2020-11-28 01:57

    It works on ubuntu 16.04. Step 1:

     sudo gedit /home/user_name/.local/bin/pip
    

    a file opens with the content:

    #!/usr/bin/python
    
    # -*- coding: utf-8 -*-
    import re
    import sys
    
    from pip import main
    
    if __name__ == '__main__':
        sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
        sys.exit(main())
    

    Change the main to __main__ as it appears below:

    #!/usr/bin/python
    
    # -*- coding: utf-8 -*-
    import re
    import sys
    
    from pip import __main__
    
    if __name__ == '__main__':
        sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
        sys.exit(__main__._main())
    

    Save the file and close it. And you are done!

    0 讨论(0)
  • 2020-11-28 02:00

    For those having similar trouble using pip 10 with PyCharm, download the latest version here

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