12
VSCode, pipenv, python
I don't use python a lot and although I have all the VSCode plugins for python installed, when I load a project up, there are lots of "Problems" about missing python libraries. "unable to import"
The project works fine in the shell, I can run tests and all the things. All of the projects use pipenv
I want the missing python library warnings to disappear so I can use the "Problems" pane to find...er...real problems with the code
It seems (and I vaguely remember doing this in the past) it used to be the case that setting the pythonpath in the settings would fix this issue to a great extent. But now this does not work and the setting is marked as "deprecated"
The official docs for "Using Python environments in VS Code" are pretty good but they don't give an exact method for using pipenv. There are some good clues however. It seems that the key is to make a venv in the file folder .venv in the Project.
This work around is good for Linux or a Mac.
- go to the project directory in a shell. This can be any shell on the host, including the vscode terminal
- ensure that no virtual environment is in effect. The
deactivate
command can stop a virtual environment PIPENV_VENV_IN_PROJECT=1 pipenv shell
- say yes when VSCode asks "add this environment?"
- probably at this point you need to do
pipenv update
For projects with lots of dependencies, this will take a while - do a β§ β P "Developer: Reload Window"
I found that the project - as well as having a Pipfile - had a library in a "vendor" folder! To fix this make a file in the project directory called .env with the contents PYTHONPATH=vendor
If the folder has a different name to "vendor" set that in pythonpath
12