0

I'm new to python and have been learning how to use a virtual environment.

I followed the tutorial on youtube and created a virtual environment using this command:

python -m venv venv-testing

and tried to activate it using this command:

venv-testing\Scripts\activate.bat

I expected there was my virtual environment name in brackets that showed it activated, but it did nothing. It also didn't show error.

Can someone explain what exactly happened to me? I use Windows and PowerShell.

Thank you very much☺️

  • Here's what my powershell look like after try to activate the virtual environment https://i.stack.imgur.com/gLwap.png – Rosa Amalia Jan 12 '23 at 04:54
  • `./Scripts/Activate` run this in the venv-testing folder. It is only for PowerShell. If you want to do it from cmd then you will have to use full path to the `activate.bat` file. –  Jan 12 '23 at 04:56

1 Answers1

1

From PowerShell, you don't want to start the .bat.

You can, but that will start a new cmd process, in which your environment will activate, and then it will kill that process again.

Instead, you'll want to start the .ps1, i.e.:

venv-testing\Scripts\activate.ps1

This will activate the environment in your current PowerShell process, and the activation will persist after running the script.

Depending on your system's configuration, just running this may work:

venv-testing\Scripts\activate

But you may want to explicitly run the .ps1 instead, to avoid a situation where what you do works on some systems, but not on others.

Grismar
  • 27,561
  • 4
  • 31
  • 54