[Python] pip configuration when package unusable after installation

PHIL
2 min readSep 2, 2022

--

The thing is the path of python/pip could be annoying.

pip has too many targets

It started when I pip upgrade some package in jupyter notebook. I found it weird that the package was still old version in jupyter. After I googled many pages I typed this command in the terminal.

pip show some_package
>> /usr/local/lib/python3.9/site-packages

And then it took me a while to realize that the path my jupyter notebook import packages from is

~/Library/Python/3.9/lib/python/site-packages

That is to say, pip has upgraded the package, but jupyter notebook read packages from another directory where the package is still old version. At first I thought it was jupyter’s problem, but it turned out jupyter only used the same environment as python’s in the computer.

For some reasons pip placed its download packages in two different locations on the computer. The directory that python imports package from is the “correct” directory, and the directory that pip was lastly placing was the “wrong” directory. The reason behind it could be a mystery. To enable python to import the package pip installs or upgrades, I need to modify pip’s download target directory.

where is pip.conf?

The suggested mathod is to modify pip.conf in pip’s directory. Here I encountered another problem. I could not find pip.conf

python3 -m pip config debug
>>
env_var:
env:
global:
/Library/Application Support/pip/pip.conf, exists: False
site:
/Library/Frameworks/Python.framework/Versions/3.9/pip.conf, exists: False
user:
~/.pip/pip.conf, exists: False
~/Library/Application Support/pip/pip.conf, exists: False

The above command disclosed possible paths of pip.conf. Yet, none exists in the computer. What’s next? Just create your own!

mkdir ~/Library/Application Support/pip
touch ~/Library/Application Support/pip/pip.conf
vi ~/Library/Application Support/pip/pip.conf

Inside pip.conf, one could put customized info inside to guide how pip should work. For me, I only wanted to specify the target install path.

[global]
target=path/of/yours (~/Library/Python/3.9/lib/python/site-packages for my situation)

This config would tell pip to download package into the “correct” directory (the directory where python imports packages from). That’s it! I saved pip.conf and programs in jupyter ran fine.

--

--