- Check which python version you are using currently
which python3
- Install desired python version (python 3.8)
brew install python@3.8
- Create a virtual environment
virtualenv -p /opt/homebrew/bin/python3.8 myenv
This will create a new virtual environment named myenv that uses Python 3.8.
Execute below to install virtualenv
pip3 install virtualenv
- Activate the Virtual Environment
source myenv/bin/activate
- Install Packages or run any desired python script
With the virtual environment activated, you can now install the packages required for your project. To do this, use the pip package manager as you normally would.
For example, to install the requests
package, enter the following command:
pip3 install requests
This will install the requests
package in your virtual environment.
- Deactivate the Virtual Environment When you are finished working in the virtual environment, you can deactivate it using the following command:
deactivate
This will return you to your system’s default Python environment.