SoFunction
Updated on 2024-11-13

The pip method of installing packages by specifying the python location

Because of the multiple versions of pip installed on your computer, and the fact that different pip corresponds to different pythons, sometimes when you use pip install to install a certain package, it may not be installed in the desired location.

Specifically, on my computer, when running pip --version, the output is as follows

pip 9.0.1 from /opt/anaconda3/lib/python3.6/site-packages (python 3.6)

When running sudo pip --version, the output is as follows

pip 18.0 from /usr/local/lib/python3.5/dist-packages/pip (python 3.5)

When I use the command pip install scedar, it prompts a problem with permissions, and then when I add sudo permissions to install sudo pip install scedar, it installs in a python 3.5 package, whereas I'm actually using python 3.6, and so it prompts a message that the package doesn't exist when importing.

To solve this problem, just use the command -t to specify the installation path during installation, as follows

sudo pip install -t /opt/anaconda3/lib/python3.6/site-packages scedar

This will install the required packages in the specified location, solving the python version error problem

Above this pip specify python location to install packages is all I have to share with you, I hope to give you a reference, and I hope you support me more.