Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Fahmi Nurfikri
Fahmi Nurfikri

Posted on • Originally published atMedium

     

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 modeExit 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/.zprofileecho'eval "$(/opt/homebrew/bin/brew shellenv)"'>> /Users/fahminurfikri/.zprofileeval"$(/opt/homebrew/bin/brew shellenv)"
Enter fullscreen modeExit 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:

brewinstallpyenv
Enter fullscreen modeExit 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.

pyenvinstall--list
Enter fullscreen modeExit fullscreen mode

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

pyenvinstall3.9.15
Enter fullscreen modeExit 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 modeExit fullscreen mode

And the result will look like this.

* system(setby /home/user/.pyenv/version)  3.9.15
Enter fullscreen modeExit fullscreen mode

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

pyenv global 3.9.15
Enter fullscreen modeExit fullscreen mode

After that, check the Python version.

python--version# or python -V
Enter fullscreen modeExit 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 usepyenv install <version> and if you want to change the Python version, you can just usepyenv global <version>.

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Software Engineer | Machine Learning Engineer | Follow me on https://medium.com/@fahmisalman, https://github.com/fahmisalman and https://www.linkedin.com/in/fahmisalman/
  • Location
    Jakarta, Indonesia
  • Work
    Software Engineer
  • Joined

More fromFahmi Nurfikri

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp