Open In App

How to Install Virtual Environment in Python on MacOS?

Last Updated : 29 Oct, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

In this article, we will learn how to install Virtual Environment in Python on macOS. The virtualenv is a tool to create isolated Python environments. Since Python 3.3, a subset of it has been integrated into the standard library under the venv module. The venv module does not offer all features of this library, to name just a few more prominent:

  • is slower (by not having the app-data seed method),
  • is not as extendable,
  • cannot create virtual environments for arbitrarily installed python versions (and automatically discover these),
  • is not upgrade-able via pip,
  • does not have a rich programmatic API (describe virtual environments without creating them).

Installation:

Method 1: Using pip to install virtual environment Package

Follow the below steps to install the virtual environment package on macOS using pip:

Step 1: Install the latest Python3 in MacOS

Step 2: Check if pip3 and python3 are correctly installed.

python3 --version
pip3 --version

checking python and pip version in macos

Step 3: Upgrade your pip to avoid errors during installation.

pip3 install --upgrade pip

upgrading pip in macos

Step 4: Enter the following command to install virtual environment using pip3.

pip3 install virtualenv

installing virtual environment package on macOS using pip

Method 2: Using setup.py to install virtual environment

Follow the below steps to install the virtual environment package on macOS using the setup.py file:

Step 1: Download the latest source package of virtual environment for python3 from here.

curl https://files.pythonhosted.org/packages/dd/40/9bc1b32521f78c293c1f8ca423c725737dfa9d09640dbeec61cebca7c5f2/virtualenv-20.8.1.tar.gz > virtualenv.tar.gz

downloading the source package for virtual environment in macos

Step 2: Extract the downloaded package using the following command.

tar -xzvf virtualenv.tar.gz

extracting the virtualenv.tar.gz file in macos

Step 3: Go inside the folder and Enter the following command to install the package.

Note: You must have developer tools for XCode MacOS installed in your system

cd virtualenv-20.8.1
python3 setup.py install

installing virtual environment on macOS using the setup.py file

Verifying virtual environment installation on macOS:

Make the following import in your python terminal to verify if the installation has been done properly:

import virtualenv

Verifying virtual environment installation on macOS

If there is any error while importing the module then is not installed properly.


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads