I have both 64-bit and 32-bit Python installed. I was trying to create a virtual environment using the 32-bit Python.exe file in VSCode. I selected that version in the Python: Select Interpreter for my workspace (i.e. the C:\Program Files (x86)\Python37-32\python.exe).
I then changed the launch.json file in the workspace to include the "python" interpreter:
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"python": "c:/Program Files (x86)/Python37-32/python.exe"
}
]
}
However, when I create the virtual environment:
py -3 -m venv 32_bit_env
The python interpreter it uses is the 64-bit version from C:\Program Files\Python37\python.exe as shown in the pyvenv.cfg:
home = C:\Program Files\Python37
Is there another location to change the directory for the python.exe file in the workspace? Thank you!
There are two concepts you are mixing: The Python Interpreter used by VS Code and the py
launcher. In addition to that, there is python
command. I will try to explain how they are configured and how they affect and what.
python
commandPATH
environment variable only. The first folder in the Process PATH
environment variable with python.exe
is used. Process PATH
is formed by combining User and System PATH variables when starting the process. Subprocesses, such as the integrated terminal of VS Code inherit the PATH
of the parent process during initialization.
home
key of the pyvenv.cfg
. Activating virtual environment modifies the PATH
of the shell.When you run python
command in a terminal.
py
commandThe py
command is the Python Launcher for Windows, added in Python 3.3.
First, these are checked in this order
where py
to locate)It will always use the latest installed version, if not specified otherwise.
python.pythonPath
In the .vscode\settings.json
, the python.pythonPath
key.
Python: Run Python File in Terminal
in VS CodeRun: Run Without Debugging
for .py file in VS CodeRun: Start Debugging
for .py file in VS CodeSpecifically, the python.pythonPath
setting does not affect to what happens, if you run py
or python
in the integrated terminal. It can only affect it if you have specified a virtual environment for python.pythonPath
, and launched new integrated terminal, and the virtual environment is activated. That is, there is no extra "magic" added VS Code or the VS Code integrated terminal.
The integrated terminal is (by default) just a regular Powershell. It has no clue about your python.pythonPath
settings in your VS Code.
You can create a virtual environent with python 3.7-32bit using
py -3.7-32 -m venv 32_bit_env
Or, the full filepath to the 32-bit v.3.7. python.exe
, assuming Powershell (hence &
):
& "C:\some\path\Python 3.7 32-bit\python.exe" -m venv 32_bit_env
You can check the full filepath with py -0p
, if you need to. Then, you can then make this virtual environment to be automatically activated in new VS Code integrated terminals, by editing the settings.json:
{
"python.pythonPath": "C:/tmp/someproj/my_venv/Scripts/python.exe"
}
Note that every \
in the entry has to be replaced with either \\
or /
. The python.pythonPath
has to be absolute.
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