[Django] Setting up a virtual environment
Why create a virtual environment?
It separates the modules that will be used for a project from the files on the computer. For example, for a specific project, you might need an older version of Django. Also, if virtual environment is not used, it might be hard to keep track of all the installed modules.
For Windows:
1. Create a project directory
2. Create a virtual environment
If virtualenv is not installed, it should be installed as follows.
It is also a good idea to keep pip updated using
Now, inside the project folder, create a virtual environment.
Here, -m is to import module, venv is the virtual environment module, and myvenv is an arbitrary name.
3. Activate the virtual environment
To deactivate, simply enter
4. Install modules
Install the necessary modules, in this case the latest version of Django.
and use pip freeze to check the installed modules in the virtual environment.
5. Connecting virtual environment in PyCharm
In File - Settings - Python Interpreter - Add - Existing Interpreter - Select Scripts/python.exe
Leave a comment