Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

python

pip

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 the terminal: sudo python3 -m pip install mp3play

What is causing this and how can I fix it so that I can install the module mp3play?

like image 200
TheHarpoon Avatar asked Feb 22 '15 22:02

TheHarpoon


People also ask

How do I fix No module named pip error?

The Python "ModuleNotFoundError: No module named 'pip'" occurs when pip is not installed in our Python environment. To solve the error, install the module by running the python -m ensurepip --upgrade command on Linux or MacOS or py -m ensurepip --upgrade on Windows.

Why is pip install not working in Python?

One of the most common problems with running Python tools like pip is the “not on PATH” error. This means that Python cannot find the tool you're trying to run in your current directory. In most cases, you'll need to navigate to the directory in which the tool is installed before you can run the command to launch it.

How do I install pip in Python?

Step 1: Download the get-pip.py (https://bootstrap.pypa.io/get-pip.py) file and store it in the same directory as python is installed. Step 2: Change the current path of the directory in the command line to the path of the directory where the above file exists. Step 4: Now wait through the installation process. Voila!


1 Answers

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.

like image 65
mpacer Avatar answered Sep 26 '22 01:09

mpacer