⊗pyPmEvCr 92 of 128 menu

Creating a Virtual Environment in Python

The very first step when working with a virtual environment is to create a separate folder for the project. Let's make a folder project_venv, inside which the virtual environment will be created. Inside this folder, let's create another folder project1, in which the main working file with the code will be located - main.py:

  • /project_venv/
    • /project1/
      • main.py

Now you need to open the terminal and go to the project1 folder:

cd .\project_venv\project1\ # for Windows cd ./project_venv/project1/ # for Linux

After moving to the project1 folder with our project, you can already create a virtual environment. This is done using the command:

python -m venv .. # for Windows python3 -m venv .. # for Linux

The virtual environment will be created in the external folder project_venv, so in the command to the right of venv two dots are written, meaning the transition to the external folder. After the command is successfully executed, the system will automatically create a structure of service folders and files in the folder project_venv. For Windows OS it looks like this:

  • /project_venv/
    • /Include/
    • /Lib/
    • /project1/
      • main.py
    • /Scripts/
    • pyvenv.cfg

For Linux OS like this:

  • /project_venv/
    • /bin/
    • /include/
    • /lib/
    • /lib64/
    • /project1/
      • main.py
    • pyvenv.cfg

Create your project test_venv with a virtual environment.

English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline