DEV Community

Cover image for Setup IOS Machine To Run A Higher Version Of Python By Default.
Clayton_yolo
Clayton_yolo

Posted on

Setup IOS Machine To Run A Higher Version Of Python By Default.

$ python -- version

MacOS comes generally with python 2.7 installed, which is deprecated as of January first 2020. However there are some dependencies on MacOS that might require python 2.7 to be available, which means we can’t uninstall the 2.7 version to replace it with a higher updated version.
Thankfully, Pyenv allows us to have different versions of python installed in our machine. We’re goin to install our desired updated version of python and have it running as the default specific version on our MacOs machine.
First of all, we’re going to install HombeBrew as package manager using the terminal. Once HomeBrew is installed, let’s install the Pyenv package by running the command: brew install Pyenv.

Now, Let’s configure our terminal so it can use Pyenv whenever we start a new instance. Let’s initialize Pyenv by running the command pyenv init in the terminal. This will tell us what we need to do to initialize our Pyenv every time we start a new terminal window. Your terminal should look like this after running the pyenv init command:

Alt Text

Let’s copy the eval “$(pyenv init -)” line and add it to this file that is located at the ~/.zshrc path. This is a path to a file on our system, the file might not exist, and if it doesn’t exist, we need to create it, and we need to add the eval line to it.

We can do that by typing nano ~/.zshrc in our terminal, if you’re using an older version of MacOs, you might have bashrc instead of zshrc as your file path location.
Once, the nano text editor is opened, paste the eval “$(pyenv init -)” command then save it. It will create the new file for us.

Next let’s use Pyenv to install the version of python that we want, i’ll do it with the 3.8.2 version, you guys can chose the version of python you want. Run the command: pyenv install 3.8.2. Pyenv is going to download and install the specified python version on our system.

Finally, let’s configure Pyenv to use this version by default whenever we use the terminal. This way, we still have python 2.7 installed on the system for those applications that need it, and we can use python 3.8 when we’re developing.
We can configure the default version of python in Pyenv by modifying a text file. We do this by running the command: echo 3.8.2 > ~/.pyenv/version.

Alt Text

You should be all set up and ready to code. Happy Coding 🎉

Top comments (0)