In my project folder I created venv folder.
python -m venv venv
When I in VS Code run command select python interpreter
my ven
I had the same problem and it was because PowerShell was not updated. Sometimes Windows preserve version 2.* and I had to manually download and install version 3. After that problem solved and I could use virtual environments very well.
In vscode select folder and create WS and it will work fine
P.S:
I have been using vs code for a while now and found an another way to show virtual environments in vs code.
Go to the parent folder in which venv
is there through command prompt.
Type code .
and Enter. [Working on both windows and linux for me.]
That should also show the virtual environments present in that folder.
Original Answer
I almost run into same problem everytime I am working on VS-Code using venv. I follow below steps, hope it helps:
Go to File > preferences > Settings
.
Click on Workspace settings
.
Under Files:Association
, in the JSON: Schemas
section, you will find Edit in settings.json
, click on that.
Update "python.pythonPath": "Your_venv_path/bin/python"
under workspace settings.
(For Windows): Update "python.pythonPath": "Your_venv_path/Scripts/python.exe"
under workspace settings.
Restart VSCode incase if it still doesn't show your venv.
I fixed the issue without changing the python path as that did not seem like the right solution for me. The following solution worked for me, hopefully it works for you as well :))
Activate your virtualenv (using source activate / activate.bat / activate.ps1 if using power shell)
C:\Users\<myUserName>\Videos\myFolder>django-project\Scripts\activate.bat
(django-project) C:\Users\<myUserName>\Videos\myFolder>
Navigate to your project directory and open vscode there.
(django-project) C:\Users\prash\Videos\myFolder\projects>code .
in VS Code, goto File --> Preferences --> Settings (dont worry you dont need to open the json file)
In the setting search bar search for virtual / venv and hit enter. You should find the below in the search bar:
Python: Venv Folders Folders in your home directory to look into for virtual environments (supports pyenv, direnv and virtualenvwrapper by default).
Add item, and then enter the path of the scripts of your virtuanenv which has the activate file in it. For example in my system, it is:
C:\Users\<myUserName>\Videos\myFolder\django-project\Scripts\
Save it and restart VS Code.
To restart, open cmd again, navigate to your project path and open vs code. (Note that your venv should be activated in cmd before you open vs code from cmd)
Command to open vs code from cmd:
code .
I was having the same issue until I worked out that I was trying to make my project directory and the virtual environment one and the same - which isn't correct.
I have a \Code\Python
directory where I store all my Python projects.
My Python 3 installation is on my Path.
If I want to create a new Python project (Project1) with its own virtual environment, then I do this:
python -m venv Code\Python\Project1\venv
Then, simply opening the folder (Project1) in Visual Studio Code ensures that the correct virtual environment is used.
I had the same problem and the solution was pretty easy:
"If you create a new conda environment while VS Code is running, use the Reload Window command to refresh the environment list shown with Python: Select Interpreter; otherwise you may not see the environment there. It might take a short time to appear; if you don't see it at first, wait 15 seconds then try using the command again."
That's written on Vscode site
Note: to Reload Window: ctrl+shift+p in Vscode, then write reload window