Nice to meet you. My name is Taro and I'm Qiita's first post. I've been a member of society for about 4 years, and as a developer I've been writing code for about two and a half years. Others are the type of person who defines requirements, is close to PM, consults for recruitment, and is fluttering.
At home, I rarely write Python using a desktop PC, I was developing business tools that I didn't want to do with gas, Somehow I wanted to get my hands on a Mac and bought a Macbook at the end of last year. I immediately decided to write a simple crawl tool in Python, but It took some time to build the environment unlike Windows, so This time (~~ miscellaneous ~~) I will leave what I did at that time as a memo. ~~ * If you just write the code locally, it seems that Python2 is included by default ~~
・ MacBook Pro (13-inch 2016) -MacOS Catalina Version 10.15.2 ・ Xcode Version 11.3
Goal
Build a Python 3 system environment
Display "Hello world!" In the terminal
What to do
Install as appropriate from the App store.
Copy and paste the installation command from Homebrew Official HP and execute it.
[Example]
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
When you execute it, you will be asked for return
and Password
, so enter them as appropriate.
If the installation is successful, the following log will be displayed.
(Omission)
Tapped 2 commands and 4889 formulae (5,148 files, 12.8MB).
Already up-to-date.
==> Installation successful!
==> Homebrew has enabled anonymous aggregate formulae and cask analytics.
Read the analytics documentation (and how to opt-out) here:
https://docs.brew.sh/Analytics
==> Homebrew is run entirely by unpaid volunteers. Please consider donating:
https://github.com/Homebrew/brew#donations
==> Next steps:
- Run `brew help` to get started
- Further documentation:
https://docs.brew.sh
At this time, if the following log is displayed and the installation fails, Go to Apple's Developer Page, download the required version of "Comand line tools for xcode", and then use the Homebrew command again. You can avoid this by executing.
(Omission)
xcode-select: error: invalid developer directory '/Library/Developer/CommandLineTools'
Failed during: /usr/bin/sudo /usr/bin/xcode-select --switch /Library/Developer/CommandLineTools
After successful installation, execute the following command to update Homebrew and check the version.
brew update
brew -v
The following log will be displayed.
user@host $ brew update
Already up-to-date.
user@host $ brew -v
Homebrew 2.2.4
Homebrew/homebrew-core (git revision 5889; last commit 2020-01-24)
pyenv is software that installs and version controls Python.
Install pyenv using Homebrew that you installed earlier.
brew install pyenv
If the installation is successful, you can check the version with the following command.
pyenv -v
user@host $ pyenv -v
pyenv 1.2.16
Install Python using pyenv.
This time I will also install the latest one.
pyenv install 3.8.1
After installation, change the version of Python you want to use to the one you have installed.
pyenv global 3.8.1
After making changes, check if the settings are reflected.
pyenv versions
If it is reflected, I think that "*" is displayed next to the version of Python to be used.
user@host $ pyenv versions
system
* 3.8.1 (set by /Users/***/.pyenv/version)
After that, please enter the following command to display it.
python3
print("Hello world!")
user@host $ python3
Python 3.8.1 (v3.8.1:1b293b6006, Dec 18 2019, 14:08:53)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> print("Hello world!")
Hello world!
This is the start of Python life on Mac. Thank you for your hard work!
Recommended Posts