Think about building a Python 3 environment in a Mac environment

Summary

The author's first single book "Python programming that can be enjoyed with Minecraft" (http://amzn.asia/fgFwQia) It seems that some readers are confused about building an environment in Amazon's review, so let's think about building an environment for Python 3 on Mac.

Environment construction with official binaries

Since the above-mentioned book uses the officially distributed binary, this time I will try to build the environment with the official binary. (There are various methods, and this method is not always correct. If you find any mistakes, please let us know in the comments.)

Step 1 Download Python

First, select "Download" on the official website (https://python.org). Then, the screen will look like image 1, so download Python 3.6.2. * Note 1: The download method differs depending on the browser. I downloaded it using Chrome </ b>

スクリーンショット 2017-08-11 1.33.51.png Image 1 Python download

When the download is complete, it will be in the finder's "Download" folder python-3.6.2-macosx10.6.pkg The file is saved. Note 2: The save location may have been changed depending on the browser settings (in the case of Chrome, there is an item called "Download" in the detailed settings of the environment settings). </ b>

If you can see this file in the folder (download in my case), Step 1 is complete.

Step 2 Install Python3

python-3.6.2-macosx10.6.pkg Double-click the file Then a screen like image 2 will be displayed.

Note 3 If you are not the administrator of the Mac you are trying to install, you may need an administrator password </ b>

スクリーンショット 2017-08-11 1.58.27.png Image 2
  1. When this image 2 is saved, click "Continue".
  2. Click "Continue" several times and the items "I do not agree" and "I agree" will appear on the screen. Click "Agree".
  3. After that, the screen for entering the administrator password will be displayed. Enter the password and click "Install".
  4. A screen will appear stating that the installation is complete

This completes Step 2.

Step 3 Start Python3

Start using the terminal software (hereinafter referred to as "terminal"). You can launch the terminal software in Finder's Go-> Utilities-> Terminal.

When you start it, a screen like image 3 will be displayed.

スクリーンショット 2017-08-11 2.17.05.png Image 3

When this screen is displayed python3Enter.

Note 4: If python3 does not start even if you enter the command python3, check that the entered characters are correct (the command is a secret word. If you do not say it correctly, it will not work) </ b>

If it works properly, it will start up like image 4.

スクリーンショット 2017-08-11 2.25.37.png Image 4

When quitting Python, enter ```exit () `` `. (As in image 5)

スクリーンショット 2017-08-11 2.42.13.png Image 5

This completes Step 3.

Note 1: What is a terminal? </ i> A terminal is software that allows you to operate the OS (Mac in this case) with commands (specific text strings).

Try to make Python3 work with a command called python

First, try typing `python` in the terminal. Curiously Python works. Let's take a closer look at the working Python screen. As shown in image 5, the characters Python 2.7.10 ~ should be displayed. The version to start is different.

スクリーンショット 2017-08-11 2.33.34.png Image 6

Note 5: A version called Python 2 series is installed on Mac as standard (actually, development of 2 series is scheduled to end. If you want to study new, please come to 3 series) </ b>

Well, it's a little difficult from here.

Enter `vi ~ / .bashrc` in the terminal as shown in image 7. Half-width space between vi and ~.

Note 6: Check if ~ / .bashrc after vi is entered in this way. Isn't it ~ / bashrc or /.bashrc? </ b>

スクリーンショット 2017-08-11 2.48.56.png Image 7

When the vi editor starts up, enter the following characters. For how to use Vi, refer to Qiita's article etc. For example: Vim course starting from knowledge 0

~/.bashrc


alias python=python3
alias pip=pip3

After editing .bashrc, edit the file called .bash_profile. Add `` `source ~ / .bashrc``` to the last line.

~/.bash_profile


export TERM=xterm

# Setting PATH for Python 3.6
# The original version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.6/bin:${PATH}"
export PATH
source ~/.bashrc

This completes the setting. (This post will be added as appropriate.)

Recommended Posts