Reputation: 43539
I'm using vscode, and my editor shows:
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?
Upvotes: 36
Views: 31251
Reputation: 2693
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:
CTRL + SHIFT + P
Python: Select Interpreter
PipEnv
Upvotes: 57
Reputation:
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
C:\Users\gasma\.virtualenvs\dungeon-generator-MV179gUf
If you open up this in the file explorer, you'll find exactly where the modules are being installed.
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
.
Upvotes: 2
Reputation: 5598
On windows machines start pipenv pipenv shell
then where python
to get the path to your scripts
Upvotes: 5
Reputation: 43539
As per Daniel Roseman's comment, all I needed to do what tell vscode
about the virtual environment created by pipenv
Upvotes: 3