Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (50.2k points)
Can anyone tell me how to create a virtual environment in Python?

1 Answer

0 votes
by (108k points)

For creating a virtual environment in Python, you can use pip.

  • For a Windows machine, you can follow the below steps:

First, update your pip:

py -m pip install --upgrade pip

Then, write the below code:

py -m pip --version

pip 9.0.1 from c:\Python36\lib\site-packages (Python 3.6.1)

  • For Linux or macOS, you can use the following:

Use the system pip to load the operating system into its memory:

Python3 -m pip install --user --upgrade pip 

Python3 -m pip --version 

pip 9.0.1 from $HOME/.local/lib/Python3.6/site-packages (Python 3.6)

Now, after installing pip, to create a virtual environment, you need to browse to your project’s folder and run venv. If you are having the Python 2 version, then you can just replace venv with virtualenv in the below commands. 

  • For Windows, the command is: 

py -m venv env

  • For macOS and Linux, the command is: 

Python3 -m venv env 

After creating the VMs, now, you have to activate them with the below commands.

  • For Windows: 

.\env\Scripts\activate

  • For macOS and Linux: 

source env/bin/activate 

If you are looking for an online course to learn Python, I recommend this Python Certification program by Intellipaat.

Related questions

0 votes
1 answer
asked Jan 21, 2021 in Python by ashely (50.2k points)
0 votes
1 answer
+1 vote
1 answer

Browse Categories

...