By using virtualenv, can avoid installing modules globally
pip install virtualenv
python -m venv env- Where second argument is the location to create the virtual environment... Typically this is a directory in the project named
env - Said directory should be added to
.gitignore
- Where second argument is the location to create the virtual environment... Typically this is a directory in the project named
-
Unix
- activate
source env/bin/activate
- check if succesfully activated
which python- should point to
envdirectory (.../env/bin/python)
- should point to
- activate
-
Windows
- Powershell
- activate
.\env\bin\activateActivate.ps1- script will likely fail to run (if not running PS as admin) with message
cannot be loaded because running scripts is disabled on this system. To workaround this, can change permissions of current Powershell session.Set-ExecutionPolicy Unrestricted -Scope Process
- script will likely fail to run (if not running PS as admin) with message
- check if sucessfully activated
where.exe python- should point to
envdirectory (...\env\bin\python.exe)
- should point to
- activate
- Powershell
deactivate
pip install packageName
pip install -r requirements.txt- where
-rflag is equivalent to--requirementand tells pip that file argument is a requirements file
- where
pip freeze- export list of all installed packages and their versions