Prepare a Python development environment! (Mac)
[Operation check environment](https://qiita.com/drafts/3840d0208306607a494a/edit#%E5%8B%95%E4%BD%9C%E7%A2%BA%E8%AA%8D%E7%92%B0 % E5% A2% 83 "Operation check ring") [Homebrew installation](https://qiita.com/drafts/3840d0208306607a494a/edit#homebrew%E3%82%A4%E3%83%B3%E3%82%B9%E3%83%88%E3%83%BC % E3% 83% AB "Operation check ring") [Install pyenv](https://qiita.com/drafts/3840d0208306607a494a/edit#pyenv%E3%82%92%E3%82%A4%E3%83%B3%E3%82%B9%E3%83% 88% E3% 83% BC% E3% 83% AB "Operation check ring") [Finally install Python](https://qiita.com/drafts/3840d0208306607a494a/edit#%E3%81%A4%E3%81%84%E3%81%ABpython%E3%82%92%E3%82% A4% E3% 83% B3% E3% 82% B9% E3% 83% 88% E3% 83% BC% E3% 83% AB "Operation check ring")
MacOS10.15.7
$brew --version
Please execute this command if
$Homebrew 2.2.10
If the message such as (may be slightly different) is displayed, proceed to the next stage. ↓ [Install pyenv] (https://qiita.com/drafts/3840d0208306607a494a/edit#pyenv%E3%82%92%E3%82%A4%E3%83%B3%E3%82%B9%E3%83%88%E3%83 % BC% E3% 83% AB "Operation check ring")
In other cases, please continue reading
Please go to this site and click the button ① in the image below to copy the command. ↓ https://brew.sh/index_ja
Then
"Finder"-> "Applications"-> "Utilities"-> "Terminal" Open the terminal as Enter the command you just copied from the site
This completes the Homebrew installation.
Next, let's install "pyenv" using Homebrew prepared in the previous chapter. First of all, make sure that pyenv is not installed. Try running the following command.
$pyenv -v
pyenv: command not found
The person who is displayed does not have pyenv installed yet. In other cases, pyenv is already installed. Let's jump to the link below. ↓ [Finally install Python](https://qiita.com/drafts/3840d0208306607a494a/edit#%E3%81%A4%E3%81%84%E3%81%ABpython%E3%82%92%E3%82% A4% E3% 83% B3% E3% 82% B9% E3% 83% 88% E3% 83% BC% E3% 83% AB "Operation check ring")
$brew install pyenv
And execute the command If there is no problem with this, the installation is completed. Let's run the following command to verify that pyenv was installed.
pyenv -v
pyenv 1.1.0
It is OK if the characters like (may be slightly different) are displayed!
In the next chapter, we will install Python using pyenv, but before that, let's set up the installed pyenv. Execute the following commands in order in the terminal. Nothing is displayed when I execute each, but there is no problem.
echo $SHELL
If the execution result of the above command is "/ bin / bash", execute the following four commands.
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile
echo 'eval "$(pyenv init -)"' >> ~/.bash_profile
source ~/.bash_profile
If the execution result is / bin / zsh, execute the following four commands.
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zshrc
echo 'eval "$(pyenv init -)"' >> ~/.zshrc
source ~/.zshrc
As for what I did, I added the setting code to the file ".bash_profile" or ".zshrc". You may not be sure what is happening, but you don't have to worry about it here. This completes the pyenv settings!
Now, let's install Python using the installed pyenv. The pyenv you just installed can install multiple versions of Python, so you need to choose the version of python. Now let's see what version of Python you can install. Try running the following command in your terminal.
pyenv install --list
I think that a lot of characters were displayed. If you scroll up the terminal, you will see a number that starts with a number like "3.6.5", as shown in the image below. Shown here are the currently installable versions of Python. Let's install the relatively new "3.6.5" this time. (If "3.6.5" is not displayed, you cannot install it. In that case, try installing the displayed version such as "3.5.0" instead.) First, execute the following command to install "3.6.5" Python.
pyenv install 3.6.5
It will take a while, but if the following screen is displayed, the installation is complete. Then try running the following command:
pyenv versions
With this command, you can see a list of currently installed Python. If "3.6.5" is displayed on the screen, you can confirm that the installation was successful. However, in this state, I will use the version of Python that is installed by default on the Mac instead of 3.6.5. Let's change the setting to use the version of Python installed this time by executing the following command.
pyenv global 3.6.5
You are now ready to use 3.6.5 Python! Let's check it by executing the following command.
python --version
If the settings are correct, you should see 3.6.5.
thank you for your hard work. This completes the introduction of python. If you get an error with a combination of other software, I will continue to publish articles from time to time, so please refer to that. https://qiita.com/yuttyaDX
Recommended Posts