Skip to content

Instantly share code, notes, and snippets.

@gembin
Last active January 25, 2018 15:51
Show Gist options
  • Save gembin/90e063762b27bb8ff863d62e61ec22dd to your computer and use it in GitHub Desktop.
Save gembin/90e063762b27bb8ff863d62e61ec22dd to your computer and use it in GitHub Desktop.
Python 3 Creation of virtual environments (3.5+)

Creating virtual environment

python3 -m venv /path/to/new/virtual/environment

NOTE:

  • Changed in version 3.5: The use of venv is now recommended for creating virtual environments.
  • Deprecated since version 3.6: pyvenv was the recommended tool for creating virtual environments for Python 3.3 and 3.4, and is deprecated in Python 3.6.

Activate a virtual environment

cd /path/to/new/virtual/environment
source bin/activate

Deactivate a virtual environment

deactivate

Install requirements

pip3 install -r requirements.txt

Export Output installed packages

pip freeze will produce a similar list of the installed packages, but the output uses the format that pip install expects.

pip3 freeze > requirements.txt

List installed packages

Display all of the packages installed in the virtual environment:

pip3 list --format=columns
# or
pip3 freeze
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment