Wednesday, July 17, 2024

How to switch to multiple versions of python similar to nvm in Node JS

pyenv is a good tool for this. Below are the steps to be performed. 

brew install pyenv

or

brew install pyenv-virtualenv

To list all the python versions, below can be used 

pyenv install --list

To install a new python version, below can be used

pyenv install <version>

For e.g. 

pyenv install 3.9.19

By default, the system Python version is used when you run the python command. To use a different version of Python, you can use pyenv to set the global version. To set the global Python version to a specific version, run the following command:

pyenv global <version>

pyenv global 3.9.19

In my case, it did not set the global environment to 3.9.19, 

As an alternative, created a virtual environment using the command below 

pyenv virtualenv 3.9.19 myenv2 

/Users/retheesh/.pyenv/versions/3.9.19/envs/myenv2/

Now 

Now from here, another virtual environment can be given , like this below 

cd to the folder that is required and run the belt 

/Users/retheesh/.pyenv/versions/3.9.19/envs/myenv2/bin/python -m venv venv

This creates a virtual environment with the desired python version.

references:

https://robiokidenis.medium.com/how-to-install-multiple-python-on-your-mac-d20713740a2d


No comments:

Post a Comment