Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make VSCode use global python config, not virtual environment?

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?

like image 530
MikeTheTall Avatar asked Sep 05 '25 03:09

MikeTheTall


2 Answers

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).

like image 61
Brett Cannon Avatar answered Sep 07 '25 21:09

Brett Cannon


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.

enter image description here

like image 35
Pranav Kulkarni Avatar answered Sep 07 '25 21:09

Pranav Kulkarni