Search code examples
pythonpipseabornmodulenotfounderror

Module not found error in Python after pip install package --user


I had Permission Denied error when I installed seaborn (or any libray) library (pip install seaborn - on command prompt and Jupyter notebook). I tried pip install seaborn --user and it showed that Requirements already satisfied. However, when I try to import seaborn on jupyter notebook, it returns module not found error.


Solution

  • You're probably attempting to download package to a system folder where you don't have permission to write or modified, maybe it's due to modification on your pip.ini file which specify by default the packages location ?

    Check pip documentation and his topic about configuration here.

    Furhtermore, I advise you, if you start learning python and using pip package, to learn fundamental about the principle of virtualenv using venv lib here. VirtualEnv is a recommended practice in python who allow you to compartmentalize project in a specified place with a personal pip package directory and other things, these methods aim to avoid dependancy concurrence between projects and also avoid pip package permissions issue by downloading pip package only for your virutalenv.

    • Step by step to setup venv ( you should be in the root folder of your projet) :
    user@hostname > python3 -m venv venv
    user@hostname > source ./env/bin/activate
    (venv) user@hostname > python -m pip install foo-packages 
    
    • Or the second option but not recommended is to use sudo to install packages to the system folder :
    sudo@hostname > sudo python -m pip install foo-packages