🌑

Stephen Cheng

Create Virtual Environment for Python Project

 

Stephen Cheng

Intro

It is suggested to have a dedicated virtual environment for each Python/Django project, and one way to manage a virtual environment is venv, which is included in Python. The name of the virtual environment is your choice, in this tutorial we will call it myenv. Type the following in the command prompt:

Windows:

1
py -m venv myenv

Unix/MacOS:

1
python -m venv myenv

This will set up a virtual environment, and create a folder named “myenv” with subfolders and files.

Activate the Virtual Environment

You must activate the virtual environment every time you open the command prompt to work on your project. You can activate the environment by typing this command:

Windows:

1
myenv\Scripts\activate.bat

Unix/MacOS:

1
source myworld/bin/activate

Once the environment is activated, you will see this result in the command prompt:

Windows:

1
(myenv) C:\Users\Your Name>

Unix/MacOS:

1
(myenv) ... $

Deactivate the Virtual Environment

You can deactivate the virtual environment by typing this command:

1
deactivate

, , — Mar 12, 2023

Search

    Made with ❤️ and ☀️ on Earth.