Search code examples
pythonpipsite-packages

How do I change the directory where pip installs packages?


I have a ploblem where pip installs packages in the wrong directory: C:\Users\mikke\AppData\Roaming\python\python311\sitepackages, but my python is installed in C:\Program Files\Python311. I'm pretty new to python and use pycharm as my IDE, the problem i have is that pycharm doesn't recognize any of the packages I install and I'm pretty sure it's because they are installed in the wrong directory.

First I tried to go on the internet to find answers on how to do this, but I couldn't find anthing. Then I tried to go into my system variables and found out I had two different varibles to python script and one of the variables had the path: C:\Users\mikke\AppData\Roaming\python\python311\scripts, so i deleted the one with the path i didn't want my packages to go to, but it didn't work. Then I tried to uninstall pip, with the command: python -m pip uninstall pip, it deleted the pip exe's in the scipts folder, but when i tried to install the packages again it still installed to the wrong directory.


Solution

  • PyCharm typically uses one of a selection of virtual environments, and this is selectable by project.

    For more information on how to locate the virtual environment for a given project and how to Install, uninstall, and upgrade packages, see the PyCharm documentation here.

    Essentially the process is:

    1. open project settings
    2. choose Python Interpreter
    3. click + icon to add a new Python package