I read this Stack Overflow post on a similar issue, but the suggestions there don't seem to be working. I installed Visual Studio Code on my Windows machine and added the Python extension. Then I changed the Python path for my project to C:\Users\username\.conda\envs\tom\python.exe
. The .vscode/settings.json
has this in it:
{
"python.pythonPath": "C:\\Users\\username\\.conda\\envs\\tom\\python.exe"
}
The status bar in Visual Studio Code also shows:
But when I do conda env list
even after doing conda activate tom
in the terminal I get the output:
# conda environments:
#
base * C:\ProgramData\Anaconda3
tom C:\Users\username\.conda\envs\tom
Instead of:
# conda environments:
#
base C:\ProgramData\Anaconda3
tom * C:\Users\username\.conda\envs\tom
Also the packages not installed in base don't get imported when I try python app.py
. What should I do?
where python
runs, but it doesn't give any output.
Also,
import os
import sys
os.path.dirname(sys.executable)
gives
'C:\\Python38'
Firstly, open the command palette using Ctrl + Shift + P. Secondly, Select Python: select Interpreter. Now, Select Enter interpreter path. We have to add the path where the env is, the default location will be C:\Users\YourUserName\Anaconda3\envs\env_name.
Select and activate an environment# To select a specific environment, use the Python: Select Interpreter command from the Command Palette (Ctrl+Shift+P).
Reload Window from Command Palette, select base:conda as python interpreter then press Ctrl+Shift+` to open a new integrated Terminal, conda environment should be activated automatically in it.
Ctrl+Shift+P and search “ Terminal ”. In the Terminal window, you can see “conda activate <env>” command already executed, and the terminal is under your conda environment. The second way is to have manual control of switching the conda environment in the terminal. To achieve this, we need to make VSCode terminal recognize the “conda” commands.
One is to Create New Integrated Terminal (In Active Workspace) and the terminal would activate the conda environment based on the Python interpreter you specified in python.pythonPath. The other one is manually run “conda activate <env>” in the terminal. Ctrl+Shift+P and search “ Terminal ”.
The command to start the anaconda prompt in terminal should look something like this: C:<path-to-conda-installation>Scriptsactivate.bat C:<path-to-conda-installation>. This activates conda default environment, once you are in there you can change environment with the activatecommand: conda activate <your-env-name>.
First, open the Anaconda prompt ( How to access Anaconda command prompt in Windows 10 (64-bit) ), and type: To activate your virtual environment. Then to open Visual Studio Code in this active environment, type
I was facing the same issue for a long time and nothing seemed to work. Out of nowhere, VS Code suggested me the following in a notification prompt:
We noticed you're using a conda environment. If you are experiencing issues with this environment in the integrated terminal, we recommend that you let the Python extension change "terminal.integrated.inheritEnv" to false in your user settings.
I clicked yes
on it and worked. You can also manually set this in your settings.json as follows:
Shift + Command + P
to open command palette."terminal.integrated.inheritEnv": false
I was helped by switching the terminal from powershell to cmd
First, open the Anaconda prompt (How to access Anaconda command prompt in Windows 10 (64-bit)), and type:
conda activate tom
To activate your virtual environment.
Then to open Visual Studio Code in this active environment, type
code
And it should work.
conda init
.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