I am trying to activate the Python virtual environment using workon command in Visual Studio Code. Typing command workon is listing all the virtual environments already available, but when I am typing the command workon env-name to activate the environment, nothing is happing and I am also not getting any errors. Can someone help me with this problem?
-
"…when I am typing the command workon env-name to activate the environment, nothing is happing…" The environment is not activated? How do you know?phd– phd2021-02-11 13:58:35 +00:00Commented Feb 11, 2021 at 13:58
-
Because in the console, once the environment is activated, we usually see the environment name. Also, I tried to import the packages I have installed in that environment and could not.DumbCoder– DumbCoder2021-02-11 16:33:23 +00:00Commented Feb 11, 2021 at 16:33
3 Answers
If you have already created an environment outside the Visual Studio (via command promote) and trying to activate it from MS Visual Studio then most common cause is Powershell:
- Check the terminal window and check the command type we are using, by default it will be Powersheel,
- Change it to cmd and try again the command.
- May be it will work for you, I have got success after correcting it. Thanks.
Comments
I use the following method to use the command "workon" in the terminal of VS Code, and you could refer to it:
Install the module. (
pip install virtualenvwrapper-win)Create a "virtualenv" environment. (
mkvirtualenv name)If you use the new environment created, please install "virtualenv" or "virtualenvwrapper-win" in it.
Use the "workon" command. (
workon name)
Please use a terminal other than powershell in VS Code, because it does not activate the environment by default.
In addition, if you want to manage and use a virtual environment, it is very convenient to use python commands. (It is created without installing modules, and the created virtual environment exists in the project and displayed in the project structure.) You could refer to this docs: virtual environments in VS Code.
1 Comment
First, you should create a virtual environment outside(Using Cmd). Using the following two commands you can create a virtual environment. Replace <> with a name.
To install module - (pip install virtualenvwrapper-win)
To create virtual environment - (mkvirtualenv <>)
If you are still getting the error check the top right of the terminal window of VScode check whether command type is set as cmd(most probably be you'll have powershell). If not you have to change it to cmd.
Hope this will work.

