Use pipenv whenever possible in vscode

Viewed 1612

How could I force vscode to always find and prefer pipenv's virtual environment for python instead of the python's global settings?

When I create a pipenv environment on my workspace, it keeps using the global python version at /usr/bin/python (as defined in settings as "python.pythonPath": "/usr/bin/python") but I wonder how could I switch to something like ~/.local/share/virtualenvs/Selenium-10eAXqZ4/bin/python automatically when there is Pipenv environment detected.

Is this even possible? If this is how can I configure it?

(I'm not talking about simply overriding the python.pythonPath with local .vscode/settings.json I need this to detect the path from pipenv automatically when it exists for the current project)

1 Answers

Add PIPENV_VENV_IN_PROJECT=1 to your environment and the .venv folder will be added to your project root. VSCode has zero problems picking up Python from there. (I find it also very convenient to have everything in one place and not spread around on the entire disk.)

Related