Where does pipenv install packages?


I’m using vscode, and my editor shows:

enter image description here

The red is showing that it can’t import those packages. I’m using a pipenv virtual environment and for the life of me, I can’t figure out where it installs the packages.

If I could, I could just add that to $PYTHONPATH and life would be better.

Any help?

Asked By: Shamoon



As per Daniel Roseman’s comment, all I needed to do what tell vscode about the virtual environment created by pipenv

Answered By: Shamoon

pipenv installs packages in ~/.local/share/virtualenvs/

To find the complete path, you can run pipenv --venv

The easiest way to load this into VS Code is to:

  1. open the command palette CTRL + SHIFT + P
  2. search for Python: Select Interpreter
  3. Select the option indicated by PipEnv

enter image description here

Full documented steps

Answered By: forzagreen

On windows machines start pipenv pipenv shell then where python to get the path to your scripts

Answered By: Isaac Sekamatte


Answered By: feng

I spent like 2 hours trying to figure out what I was doing wrong (the files would run but the imports would not resolve). Turns out it’s surprisingly simple.

Go to the root of your project & open up a new terminal. Use the following commands to open a shell and get the location of the virtual environment.

>>> pipenv shell
>>> pipenv --venv


If you open up this in the file explorer, you’ll find exactly where the modules are being installed.

where tf are these modules

From here, you can create a new .vscode/settings.json file (still in your project directory) to let VS Code know what’s up.

In my case, I typed this in:

    "python.autoComplete.extraPaths": ["C:/Users/gasma/.virtualenvs/dungeon-generator-MV179gUf/Lib/site-packages"],
    "python.analysis.extraPaths": ["C:/Users/gasma/.virtualenvs/dungeon-generator-MV179gUf/Lib/site-packages"]

Make sure your replace the file paths with the one you got from running pipenv --venv. To run your project, just use python <file>.py, and to exit the virtual environment, simply type exit.

Answered By: Ad Charity
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.