Steven's Homepage

Virtual Environment for Python

I needed to set up a virtual environment while working through the book Python for Data Analysis, 3E by Wes McKinney[1]. There are examples in the book and a git repository[2] with a requirements.txt file.

These are the steps I used to set it up:

# Create a new virtual environment
$ python3 -m venv ~/virtualenvs/pydata_book

# Activate the virtual environment
$ source ~/virtualenvs/pydata_book/bin/activate

# Check what it will install
$ cat requirements.txt 

# Install with pip from a requirements.txt file
$ python -m pip install -r requirements.txt

# Create a new requirements.txt
$ python -m pip freeze > requirements.txt

# Deactivate the current virtual environment
$ deactivate

References

  1. Python for Data Analysis, 3E
  2. pydata-book
  3. venv — Creation of virtual environments
  4. pip - Users Guide