Hello Everyone this is a simple guide on how to quickly set up python on a mac and be able to switch between versions using pyenv!
First Note that all Mac OS come with Python 2.7 out the gate which can be helpful to learn but You might want to use Python 3 for more serious development!
This Blog will help you set this up in a quick and simple fashion!
Step 1 - Set up Homebrew
You will first need homebrew installed to be able to install everything straight from terminal.
just copy and paste this into your terminal:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Step 2 - Install pyenv
Now we will install pyenv to help us manage and install different versions of Python, the pyenv docs describe its functionality as
"pyenv lets you easily switch between multiple versions of Python. Itβs simple, unobtrusive, and follows the UNIX tradition of single-purpose tools that do one thing well."
Use Brew install
brew install pyenv
Add pyenv initializer to shell startup script
echo 'eval "$(pyenv init -)"' >> ~/.bash_profile
Reload your profile
source ~/.bash_profile
Step 3 - Install Python using pyenv
## List of Python versions
You can look at a list of all the different python versions that
can be installed using the command
`pyenv install --list`
## Installing Selected Version
Once you have selected a version you want to use install it using
the command
`pyenv install <version>`
Step 4 - Switching to the installed version
## Viewing all installed versions
You can look at the list of all installed versions of python using
the command
`pyenv versions`
## Setting Global Version
Set the global or default python version using the command
`pyenv global <version>`
## Setting Local Version
Set the local version for the repo by cd'ing into the repo then
using the command
`pyenv local <version>`
## Checking Current Version in user
You can always check what version of Python is currently being used
by using the command
python -V
or python --version
Conclusion
pyenv is a great tool to use to easily manage and switch between Python
for more about pyenv look at their documentation here :
https://github.com/pyenv/pyenv/wiki
Top comments (2)
Thank you.
Please want to know if setting up a local version in a folder act like a virtualenv ?
Yeah kind of however its alot easier to set up python now than this