Pyenv Virtual Environments Setup Guide
1. Installing Pyenv
More detailed instruction for installation can be found here for Mac/Linux and here for Windows.
Mac Installation
-
Install Homebrew (if not already installed):
-
Install Pyenv using Homebrew:
-
Configure the shell to use Pyenv:
- For Zsh (default on macOS):
-
For Bash:
-
Verify Installation:
Linux Installation
- Install Dependencies (Required for Pyenv to work properly):
On Debian/Ubuntu-based systems:
sudo apt update && sudo apt install -y make build-essential libssl-dev zlib1g-dev \
libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev \
libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev python3-openssl git
-
Install Pyenv:
-
Configure the shell to use Pyenv:
-
For Bash:
-
Verify Installation:
Windows Installation (Using Pyenv-Win)
-
Install Pyenv-Win
-
Add Pyenv to the system PATH: Open PowerShell and run:
-
Restart PowerShell and Verify Installation:
2. Setting Up Virtual Environments in Pyenv
Installing a Specific Python Version
To install a specific version of Python using Pyenv, run:
Replace3.9.7
with the desired Python version.
Listing Available Python Versions
To see installed Python versions:
To see all available Python versions:
3. Activating and Deactivating Virtual Environments
Creating a Virtual Environment
To create a new virtual environment:
Activating a Virtual Environment
To activate the environment:
Deactivating a Virtual Environment
To deactivate an environment:
4. Managing Packages Within a Virtual Environment
Installing Packages
Once inside an environment, install packages using:
Listing Installed Packages
To list all installed packages:
Updating Packages
To update all packages:
Removing a Package
To remove a package:
5. Deleting Virtual Environments
To delete an environment:
Force Deleting an Environment (Manually)
If needed, manually remove an environment:
(For Linux/Mac users, adjust the path accordingly.)For Windows:
Final Notes
- Always activate the correct virtual environment before running scripts.
- Use
pip install
for package management within environments. - Regularly update Pyenv with:
By following this guide, you’ll efficiently manage Python environments across Windows, Mac, and Linux using Pyenv!