Introduction
Python virtual environment is a tool used to isolate different Python environments on a single machine. This is useful when working on projects that have different requirements, or when you want to avoid conflicting packages in your global Python environment.
Achievements
virtualenvCommand- Activate Virtual Environment
- Exit Virtual Environment
- Assgin Python Version
Creating Virtual Environment
First, let us create a Python virtual environment.
virtualenv venv
Now we have a virtual environment named "venv". Next, we can install Python packages in the virtual environment.

Using Virtual Environment
Now, we use the source command to activate the virtual environment:
source venv/bin/activate

Then, we install a third-path package:
pip install pygame

pygame is success installed in this environment.
pip list

Finally, use deactivate command to exit the virtual environment:

We can see pygame is not installed in the main environment.

Different Python Versions
We can also create a virtual environment using the Python version we want.
e.g. create a Python3 virtual environment, first, we must know where the Python3 is:
which python3

then we can use -p to assign it:
virtualenv -p /usr/bin/python3 venv3

Summary
Congratulations! You have completed the Python Virtual Environment Lab.
In this lab, you learned how to:
- Create a Python virtual environment.
- Use PyPI package manager to install packages in a Python virtual environment.
- Manage different Python virtual environments.



