Vlad Iordache
Vlad Iordache

Reputation: 528

Python not using proper pip

I'm running CentOS 8 that came with native Python 3.6.8. I needed Python 3.7 so I installed Python 3.7.0 from sources. Now, python command is unknown to the system, while commands python3 and python3.7 both use Python 3.7.

All good until now, but I can't seem to get pip working.

Command pip returns command not found, while python3 -m pip, python3.7 -m pip, python3 -m pip3, and python3.7 -m pip3 return No module named pip. Only pip command that works is pip3.

Now whatever package I install via pip3 does not seem to install properly. Example given, pip3 install tornado returns Requirement already satisfied, but when I try to import tornado in Python 3.7 I get ModuleNotFoundError: No module named 'tornado'. Not the same thing can be said when I try to import it in Python 3.6, which works flawlessly. From this, I understand that my pip only works with Python 3.6, and not with 3.7.

Please tell me how can I use pip with Python 3.7, thank you.

Upvotes: 0

Views: 51

Answers (2)

Ali Jabbary
Ali Jabbary

Reputation: 1

I think the packages you install will be installed for the previous version of Python. I think you should update the native OS Python like this:

  1. Install the python3.7 package using apt-get sudo apt-get install python 3.7
  2. Add python3.6 & python3.7 to update-alternatives: sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1 sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2
  3. Update python3 to point to Python 3.7: `sudo update-alternatives --config python3
  4. Test the version: python3 -V

Upvotes: 0

Lior Cohen
Lior Cohen

Reputation: 5745

It looks like your python3.7 does not have pip.

Install pip for your specific python by running python3.7 -m easy_install pip.

Then, install packages by python3.7 -m pip install <package_name>

Another option is to create a virtual environment from your python3.7. The venv brings pip into it by default.

You create venv by python3.7 -m venv <venv_name>

Upvotes: 1

Related Questions