Virtual Environment
A virtual environment is a Python environment such that the Python interpreter, libraries and scripts installed into it are isolated from those installed in other virtual environments.
Resources:
This way, you donβt run into those stupid dependencies issues. Another way to fix that would be using Docker, but thatβs for another time.
if you just use virtualenv
, you can run
virtualenv venv
# If the above doesnt work, do this
python3 -m virtualenv venv
# To activate the virtual environment
source venv/bin/activate
To activate in windows, use
C:\> <venv>\Scripts\activate.bat
Folder structure
venv/
β
βββ bin/
β βββ Activate.ps1
β βββ activate
β βββ activate.csh
β βββ activate.fish
β βββ pip
β βββ pip3
β βββ pip3.10
β βββ python
β βββ python3
β βββ python3.10
β
βββ include/
β
βββ lib/
β β
β βββ python3.10/
β β
β βββ site-packages/
β β
β βββ _distutils_hack/
β β
β βββ pip/
β β
β βββ pip-22.0.4.dist-ino/
β β
β βββ pkg_resources/
β β
β βββ setuptools/
β β
β βββ setuptools-58.1.0.dist-info/
β β
β βββ distutils-precedence.pth
β
βββ pyvenv.cfg
PyCharm Virtual Environment
In PyCharm, it is a bit different. We configure it within PyCharm, it will create a folder called venv/
instead of env/
. (on Windows)
To activate the virtual environment, just run
# Windows
./venv/Scripts/activate
# Mac
source venv/bin/activate
Install packages in virtual environments
Once you are in the virtual environment, you can install the right packages.
Ex: pip install speechRecognition
Export to requirements.txt
Finally, once you are done installing all of the relevant packages, you can simply run
pip freeze > requirements.txt
This will be how other users install the relevant Python packages.