DEV Community

Fahmi Nurfikri
Fahmi Nurfikri

Posted on • Originally published at Medium

3

How to Install Python Pyenv on macOS

One of the hardest processes to learning Python for beginners is installing Python. Sometimes it was a version problem, the machine doesn’t recognize commands, etc.

I was included with people who deal with those problems. My solution at that time was just to install the Anaconda package. But since the Anaconda package size is too big for what I need, I feel that method is too overkill for me.

After searching for a while, I got the solution to this problem, and the solution is Pyenv.

What is Pyenv?

Basically, Pyenv is a tool to simplify installation and version changing in Python. It helps developers quickly install or change the Python version without needing to change the whole system.

In this post, I will show you how to install Pyenv and manage the Python version.

Installing Homebrew

If Homebrew hasn’t been installed on your computer, run this command in the terminal.

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Enter fullscreen mode Exit fullscreen mode

It will take a while. After the installation process is done, it will show you a message like this.

Homebrew installation

For the next step, we will need to copy the text highlighted above to the terminal.

echo '# Set PATH, MANPATH, etc., for Homebrew.' >> /Users/fahminurfikri/.zprofile
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/fahminurfikri/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"
Enter fullscreen mode Exit fullscreen mode

When the process is finished, restart the terminal, and Homebrew is already installed on your computer.

Installing PyEnv using Homebrew

Once Homebrew is installed, we can use it to install Pyenv. This can be done by running the command below:

brew install pyenv
Enter fullscreen mode Exit fullscreen mode

Once the installation progress is finished, you can check it by using the command pyenv versions on your terminal. The output would be like this.

pyenv installation

If the output doesn’t show an error, then we can continue to the Python installation. To see the available Python version, you can use this command.

pyenv install --list
Enter fullscreen mode Exit fullscreen mode

For example, I will install Python 3.9.15. So the command will be like this.

pyenv install 3.9.15
Enter fullscreen mode Exit fullscreen mode

Don’t worry if your terminal doesn’t return anything, the process takes a while. Maybe you can leave it for a while to make coffee or something.

If the installation is already done, you can verify if the Python version is already installed, you can use the:

pyenv versions
Enter fullscreen mode Exit fullscreen mode

And the result will look like this.

* system (set by /home/user/.pyenv/version)
  3.9.15
Enter fullscreen mode Exit fullscreen mode

The * means that the system is the default Python version. To set Python 3.9.15 as the default Python, use the command:

pyenv global 3.9.15
Enter fullscreen mode Exit fullscreen mode

After that, check the Python version.

python --version  # or python -V
Enter fullscreen mode Exit fullscreen mode

If the Python version is 3.9.15 or whatever Python version you install, then the Python installation is a success. If you want to add another Python version, you can just use pyenv install <version> and if you want to change the Python version, you can just use pyenv global <version>.

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more →

Top comments (0)

Sentry growth stunted Image

If you are wasting time trying to track down the cause of a crash, it’s time for a better solution. Get your crash rates to zero (or close to zero as possible) with less time and effort.

Try Sentry for more visibility into crashes, better workflow tools, and customizable alerts and reporting.

Switch Tools 🔁

👋 Kindness is contagious

Engage with a sea of insights in this enlightening article, highly esteemed within the encouraging DEV Community. Programmers of every skill level are invited to participate and enrich our shared knowledge.

A simple "thank you" can uplift someone's spirits. Express your appreciation in the comments section!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found this useful? A brief thank you to the author can mean a lot.

Okay