Python has two different major versions, Python 2 and Python 3. We will use Python 3 throughout this course. While Python 3 is widely used, Python 2 is the default still on OS X, so we will have to install Python 3. We'll use a tool called pyenv
(https://github.com/pyenv/pyenv) that lets us install and easily manage different versions of Python on our machines.
We also need to install a tool to manage Python project dependencies: pipenv
(https://github.com/pypa/pipenv).
To install these, run each of these lines (one at a time) in your terminal.
brew install pyenv openssl readline xz zlib sqlite3
echo 'eval "$(pyenv init --path)"' >> ~/.zprofile
echo 'eval "$(pyenv init -)"' >> ~/.zshrc
pyenv install 3.12.0 #updated 10/30/23
pyenv global 3.12.0
After you do this, you’ll need to quit iTerm (⌘Q) and restart it (⌘-spacebar, then type “iterm” and press return).
If the above commands ran successfully, you should be able to run the following command and get output as shown :
❯ python --version
Python 3.12.0 #updated 10/30/23
<aside>
⚠️ If you run the above command and still see the wrong version of Python, run pyenv rehash
and then try again.
(If you want to understand more about what this command does, read this.)
</aside>
After you confirm that you are using the correct version of Python, run:
❯ pip install pipenv
If that command works successfully, you should be able to run the following command to check the version of pipenv and get output as shown:
❯ pipenv --version
pipenv, version 2022.9.24 #this is updated frequently, so it will be later than this date
❯ which pipenv
/Users/your-own-username-here/.pyenv/shims/pipenv
<aside>
🤔 What are pip
and pipenv
?
pip is a tool that will let us install Python packages (that is, code that other people have written that is "packaged" so that we can use in our own programs*)* from the Python Package Index. Another term you might hear for code someone else wrote that you can use is a library.
**pipenv is a tool that works with pip to install packages and **makes it easier to manage different packages for different projects.
</aside>
This seems like a lot of stuff! Managing your development environment for Python takes a good bit of work, but it's all part of the job.
🧩 Check out this article for a good overview about how the pieces fit together!
We'll need to configure our code editor to work with a new language.