Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rupeshtiwari/89b929fd6b71d8372461161cc40dcb22 to your computer and use it in GitHub Desktop.
Save rupeshtiwari/89b929fd6b71d8372461161cc40dcb22 to your computer and use it in GitHub Desktop.
how to use different python version from command line

Steps to use different python version from console

  1. Check which python version you are using currently
which python3 
  1. Install desired python version (python 3.8)
brew install python@3.8
  1. 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
  1. Activate the Virtual Environment
source myenv/bin/activate
  1. 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.

  1. 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment