Python `no module pip.__main__;` error when trying to install a module

后端 未结 4 1318

I am getting the following error on my Raspberry Pi: No module named pip__main__; \'pip\' is a package and cannot be directly executed

When I type in to

相关标签:
4条回答
  • 2020-12-11 17:12

    I had the same issue and none of the previous answers solved it for me.

    The error appeared when I uninstalled and reinstalled python to my PC. As it appears the previous existing version of pip wasn't completely removed and when I was trying to import it with python -m pip install package it was actually trying to call the previous version.

    To solve it first manually delete the pip folders in the following locations:

    C:\Users\username\pip
    C:\Users\username\AppData\Local\pip
    C:\Users\username\AppData\Local\Programs\Python\Python**\lib\site-packages\pip***
    C:\Python**\pip
    

    Then download get-pip.py.

    Finally, navigate to the folder where you downloaded it and run:

    python get-pip.py
    

    This procedure should reinstall pip and fix the issue.

    0 讨论(0)
  • 2020-12-11 17:19

    Pip is not only a standalone executable, it is also a python module.

    In fact in the python docs it directly recommends using the -m syntax for installing a package using pip.

    See https://docs.python.org/3.5/installing/index.html#basic-usage:

    The standard packaging tools are all designed to be used from the command line.

    The following command will install the latest version of a module and its dependencies from the Python Packaging Index:

    python -m pip install SomePackage
    

    My guess would have been that your system's pip (the executable) was being shadowed by the python2 version of the pip executable. But it sounds like you don't have pip (the module) installed such that your python3 executable can find it, so you may need to reinstall pip (the module) specifically.

    For that use python3 -m ensurepip (docs for ensurepip) which will install pip if it is not present from the persepctive of your python3 interpreter.

    The other issue could be that it's finding a file, executable or directory called pip in your current directory, and it is trying to treat that pip as a module, and it is not in fact a module.

    If it's not that I'm not sure. But it is definitely not because pip is not a module.

    0 讨论(0)
  • 2020-12-11 17:25

    pip is a standalone executable. If pip if in your path, you can just execute

    pip install mp3play
    

    If pip is not in your path, then you need to navigate to the directory where pip is located and then execute the above.

    If needed, add sudo to the command.

    The precise error you are encountered is due to pip being a package, but -m is used for executing modules.

    EDIT: pip also comes with several helpful alias functions that point to different Python installs. In general, pip points to your main Python install (the one you enter when simply executing python), pipV where V is a number such as 2 or 3 adds the install to your primary Python of version V (pip3 adds to your python3 environment). Finally there is pipV.S where V is the same as before and S is the subversion. For instance pip3.4 installs for Python 3.4.

    0 讨论(0)
  • 2020-12-11 17:25

    I had the same problem. I found that an old pip directory was left over from a python 2.7 install, at C:\Users\my-username\pip. This was causing python to try to load pip from there and fail.

    I removed that directory and my error has just become No module named pip.

    I haven't solved the problem yet, but I'm working through it at http://bugs.python.org/issue29586

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