How to create a virtual environment in Python3

To create a virtual environment, we must perform the following steps in this order:

Create a directory where the project will be:

  $ mkdir project_x

Enter the directory:

$ cd project_x

Create virtual environment (if you want to give it a special name, change the second ‘venv’, by the name you want):

$ python3 -m venv venv

Activate the created environment:

$ source bin/activate

To disable it (always in the same directory):

$ deactivate

Dependencies

To create the requirements file(good practice):

$ pip freeze > requirements.txt

To install the requirements:

$ pip install -r requirements.txt

Remove

If you want to delete the virtual environment completely, remove recursively the directory:

$ rm -r <name_of_your_venv>

😉

Related Posts

Leave a Reply

Your email address will not be published.