Home > Net >  Activating Python Virtual Environment on Windows 11
Activating Python Virtual Environment on Windows 11

Time:12-31

I am trying to create a venv virtual enviroment for Python in Window's command prompt. I created the enviroment; however, I am having difficulties using it because when I run the "activate" command it is not working. I think the problem is related to that the virtual enviroment does not have a scripts file like other window machines do, but rahter a bin file which has the activate script. When I run the activate command with the bin in the file directory I still get an error.

enter image description here

I have been trying to solve the problem for the past 4-5 hours and am completely stuck. I tried destroying and reconstructing the virtual enviroment, I tried using different extensions (.bat, .exe, .ps1, and just \activate), and tried using powershell.

Please let me know if you have any ideas what I am doing wrong!

CodePudding user response:

Open a command prompt terminal by either searching command prompt in the Windows search bar, or press the Windows Key R and enter cmd.

Create the virtual environment in a desired directory using the following command:

python -m venv env

This will create a new folder called env inside the directory where you executed the command.

You can activate the created virtual environment by running the following command in the same directory where you executed the last command:

env/Scripts/activate

I hope this helps.

  • Related