Skip to content

Instantly share code, notes, and snippets.

@rupinder-developer
Last active October 26, 2022 14:00
Show Gist options
  • Select an option

  • Save rupinder-developer/f9527d6beebdf692d6e2620489e1c600 to your computer and use it in GitHub Desktop.

Select an option

Save rupinder-developer/f9527d6beebdf692d6e2620489e1c600 to your computer and use it in GitHub Desktop.

venv

The module used to create and manage virtual environments is called venv. venv will usually install the most recent version of Python that you have available. If you have multiple versions of Python on your system, you can select a specific Python version by running python3 or whichever version you want.

To create a virtual environment, decide upon a directory where you want to place it, and run the venv module as a script with the directory path:

python3 -m venv tutorial-env

This will create the tutorial-env directory if it doesn’t exist, and also create directories inside it containing a copy of the Python interpreter and various supporting files.

A common directory location for a virtual environment is .venv. This name keeps the directory typically hidden in your shell and thus out of the way while giving it a name that explains why the directory exists. It also prevents clashing with .env environment variable definition files that some tooling supports.

Once you’ve created a virtual environment, you may activate it.

On Windows, run:

tutorial-env\Scripts\activate.bat

On Unix or MacOS, run:

source tutorial-env/bin/activate

requirement.txt

pip3 freeze > requirements.txt 
pip3 install -r requirements.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment