Update Python on Mac from 2 to 3

Overview

This article walks you through the steps of a beginner developing a coupon distribution service for the iPhone with a RESTful API and swift. It is a very detour implementation because it was implemented while examining the technical elements one by one.

Python is already installed on the Mac, but even as of OS 10.15, it is an older version. When it comes to actually writing Python, everyone seems to have been updated to 3 series. So I also updated to 3 series, so I will record the procedure at that time.

Reference URL

https://prog-8.com/docs/python-env

Work environment

Mac OS 10.15 Catalina Fixed network line

Python update procedure

The recommended procedure for Mac environment is as follows.

Check the currently installed version of Python

First, check the Python version of your Mac just in case. Open a terminal and enter the following command to display the version.

$ Python -V

The version installed on my Mac was 2.7.16, a series of 2.

Homebrew installation

_ We recommend that you update Xcode to the latest version in advance. In my case, when I tried to install Homebrew with Xcode 10.3 (the latest version is 11.1 at the time of work), the update of "Command tools for Xcode 11" running during installation did not complete successfully, and I updated Xcode to the latest version. It disappeared when I updated to. _

Homebrew is a tool that installs and manages packages such as middleware required for development. Only compatible with Mac. Now, install Homebrew.

Go to Homebrew Site and copy the installation script displayed on the top page.

brew-web.png

Paste the copied script into the terminal and run it. You may be prompted to enter the Enter key or Mac password along the way. In addition, updates such as "Command tools for Xcode 11" may be executed. If the Homebrew installation is successful, you will see something like this in your terminal.

brew-install-success-m.png

Make sure Homebrew is installed in your terminal. Execute the command to display the version, and if the version is displayed, the installation is successful.

$ brew -v

Install pyenv using Homebrew

pyenv is a tool for installing Python. First, install pyenv using Homebrew.

$ brew install pyenv
pyenv-installing_m.png

The installation was completed in a minute or two. Make sure it is installed. Execute the command to confirm the version, and if it is displayed, the installation is successful.

$ pyenv -v

Set pyenv

To install python with pyenv, you need to add settings to a file called ".bash_profile" on your Mac. Use the command to add the code for configuration. Execute three commands. If you can set it well with the command, nothing will be displayed.

$ echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile
$ echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile
$ echo 'eval "$(pyenv init -)"' >> ~/.bash_profile

Install Python using pyenv

First, check the version of python that can be installed. Execute the following command to display the list of versions.

$ pyenv install --list
python-versions-list-01_m.png

This time I decided to install 3.7.5rc1. The reason for choosing 3.7 series is that it is a major version of Python 3 series with some minor updates. 3.7 series The latest 3.7.5 rc1 was selected. The 3.8 series still has only 3.8.0 and 3.8-dev, so I'll take a look.

Install Python 3.7.5rc1 with the following command.

$ pyenv install 3.7.5rc1
python-installed_m.png

Check with the command whether it was installed.

$ pyenv versions

Then, the installed Python version is displayed, but the one with "system (~") is marked with "*". In this state, the installed Python is not enabled. Enable it. Requires a global setting. If not set, an older version will be used in the system. The command is as follows.

$ pyenv global 3.7.5rc1

Run the pyenv versions command again to verify that the settings have been reflected. If the globally set Python version is enabled, the globally set Python version will be displayed when you execute the command to check the Python version.

$ python -V
python-setting-and-check_m.png

This completes the Python update.

Next, let's write a simple Python program and run it

Recommended Posts

Update Python on Mac from 2 to 3
Update python on Mac to 3.7-> 3.8
Preferences to generate animated GIFs from Python on Mac
python on mac
Steps to install python3 on mac
How to update Google Sheets from Python
How to erase Python 2.x on Mac.
Connecting from python to MySQL on CentOS 6.4
Changes from Python 3.0 to Python 3.5
Changes from Python 2 to Python 3.0
Install Python on Mac
Install Python 3 on Mac
Install Python 3.4 on Mac
How to rebuild python environment from pyenv on Mac environment (El Capitan)
Use Tor to connect from urllib2 [Python] [Mac]
Post from Python to Slack
Install pygame on python3.4 on mac
How to update Python Tkinter to 8.6
Anaconda updated from 4.2.0 to 4.3.0 (python3.5 updated to python3.6)
Handling of python on mac
Install pandas 0.14 on python3.4 [on Mac]
Update python-social-auth from 0.1.x to 0.2.x
Notes on installing Python on Mac
Connect to sqlite from python
Steps to install the latest Python on your Mac
From python to running instance on google cloud platform
I want to AWS Lambda with Python on Mac!
Call Matlab from Python to optimize
Building a Python environment on Mac
Python 3.6 on Windows ... and to Xamarin.
How to install mysql-connector-python on mac
Create folders from '01' to '12' with python
Steps to install matplotlib on Mac
Introduction to Python Hands On Part 1
Notes on using MeCab from Python
Post from python to facebook timeline
Convert wma to mp3 on Mac
Create a Python environment on Mac (2017/4)
[Lambda] [Python] Post to Twitter from Lambda!
Python environment construction memo on Mac
Install Python 3.7 Anaconda on MAC, but Python 2
Install python3 on Mac (El Capitan)
How to install OpenCV on Mac
Update monitoring of dmesg (/ dev / kmsg) from python on Linux
Python update (2.6-> 2.7)
Python (from first time to execution)
Post images from Python to Tumblr
Environment construction of python3.8 on mac
Connect to centos6 on virtualbox with ssh connection from Mac
Notes on accessing dashDB from python
If Python 3.5.0 installation fails on Mac
Update applications running on Django 1.7 to Django 1.8
Python to switch from another language
I tried changing the python script from 2.7.11 to 3.6.0 on windows10
Introduction to Python Django (2) Mac Edition
Did not change from Python 2 to 3
Things to note when running Python on EC2 from AWS Lambda
I want to know if you install Python on Mac ・ Iroha
Simple code to call a python program from Javascript on EC2
[Python + heroku] From the state without Python to displaying something on heroku (Part 1)
[Python + heroku] From the state without Python to displaying something on heroku (Part 2)