Xiuyu Cao
  • CV
  • Research
  • Blog

Table of Contents

  • 1 Create a Virtual Environment
  • 2 Activate the virtual environment
  • 3 Setup the environment
  • 4 Share your dependencies
  • 5 Install dependencies from requirements.txt

Python Workflow

Workflow
Coding
Setting up virtual environments and package management on macOS.
Author

Xiuyu Cao

Published

December 13, 2025

Modified

January 4, 2026

When working on multiple python projects, it’s important to create isolated environments for each project to avoid dependency conflicts. Here’s a recommended workflow using venv and pip.

Reference: Python Virtual Environments - Full Tutorial for Beginners

1 Create a Virtual Environment

On mac using Python 3, you can create a virtual environment under current working directory by running the following command in your terminal:

python3 -m venv env

2 Activate the virtual environment

source env/bin/activate

Simply type deactivate to exit the virtual environment when you’re done working.

3 Setup the environment

Use pip to install the pacakages you need for your project. For example: pip install matplotlib. Use pip list to show all installed packages in the virtual environment. You can use the requirements.txt file to install all the dependencies for your project. Refer to the Section 5 for more details.

4 Share your dependencies

To share your project’s dependencies with others, you can create a requirements.txt file by running:

pip freeze > requirements.txt

This file will list all the packages and their versions installed in your virtual environment.

5 Install dependencies from requirements.txt

After activating your virtual environment, you can install all the dependencies listed in the requirements.txt file by running:

pip install -r requirements.txt

 
Xiuyu Cao