Activating Python Virtual Environment on Windows 11

Question:

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!

Asked By: Michael Napoli

||

Answers:

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:

cd env/Scripts && activate && cd ../../

I hope this helps.

Answered By: Mehrdad Moradi
python -m venv venv 

#To run this command prompt on python terminal to create a virtual environment

venvScriptsactivate 

#Run this command prompt on python terminal

Answered By: Rishi Singh
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.