I'd like to use Visual Studio Code to edit a Python program. To keep it portable, I'd like the Python program to be contained in a Python virtual environment. To keep the venv small I'd like to only install those things that the Python program needs (and to specifically NOT install things that VSCode needs).
I told VSCode which venv to use by setting the "python.pythonPath" variable in the settings.json file for my project (i.e., my Workspace Settings, not my User Settings). This works fine in the sense that I can run the program / debug the program.
VSCode wants to use flake8 to do some linting, and I 100% support this - I greatly appreciate the Python linting that VSCode & flake8 do :)
However, VSCode does this by installing the flake8 libraries into my program's virtual environment, NOT the computer-wide Python installation.
How can I set up VSCode to use the virtual environment for running & debugging the program, but install all the libraries it needs (flake8, rope, etc) into a different / system-wide Python directory?
You can do the installation of flake8
manually -- e.g. python3 -m pip install --user flake8
outside of your venv -- and then manually set the path to flake8
in your personal settings.json
file. That lets you run your code from your venv while installing flake8 for your user account (we don't recommend installing globally).
When we create a virtual environment, a file called as pyenv.cfg
is created in the virtual environment folder. Setting include-system-site-packages = true
in this file results in the virtual environment using global site packages.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With