3

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?

2
  • "…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? Commented 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. Commented Feb 11, 2021 at 16:33

3 Answers 3

5

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:

  1. Check the terminal window and check the command type we are using, by default it will be Powersheel,
  2. Change it to cmd and try again the command.
  3. May be it will work for you, I have got success after correcting it. Thanks.
Sign up to request clarification or add additional context in comments.

Comments

1

I use the following method to use the command "workon" in the terminal of VS Code, and you could refer to it:

  1. Install the module. (pip install virtualenvwrapper-win)

  2. Create a "virtualenv" environment. (mkvirtualenv name)

    enter image description here

    If you use the new environment created, please install "virtualenv" or "virtualenvwrapper-win" in it.

  3. Use the "workon" command. (workon name)

    enter image description here

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

Thanks a lot. Using default terminal instead of powershell worked for me.
0

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.

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.