LoginSignup
2
1

More than 3 years have passed since last update.

Mac環境ではじめるPython開発(環境構築編)

Last updated at Posted at 2020-05-06

はじめに

きっかけ

今までiOSアプリの開発にのみMacを使っていて、サーバーサイドの開発やドキュメント作成などはすべてWindowsでやってきたので、StayHomeのこの機会にMac一台で色々できるようになっておこう!ということで学習をはじめました。
学習内容をアウトプットすることで自分自身の理解を深めることを主目的としてQiitaに投稿します。

注意事項

  • 途中でなにかを深掘りしたくなったら脱線する場合があります。読みづらかったらすみません
  • 学習しながら書いているため、「あ、あれ必要だった」とか発生した場合は都度アップデートします

概要

学習全体のゴール

DjangoのREST frameworkを使用して作成したプログラムをAWS上で動作させる

学習ステップ

  1. Macに開発環境を構築する ←本記事の内容
  2. ローカルで動かす
  3. AWS(ECS)にデプロイして動かす

本ステップ開始時の環境

  • MacBook Air (Retina, 13-inch, 2019)
  • macOS Catalina 10.15.4
  • Python 2.7.16(MacにプリインストールされているPython)
  • zsh 5.7.1

本ステップでやること

※学習時の最新バージョン
- Homebrew 2.2.14をインストール
- pyenv 1.2.18をインストール
- Python 3.8.2をインストール
- venvで仮想環境を作成
- venvにDjango 3.0.5をインストール
- venvにdjangorestframework 3.11.0をインストール

本編

Homebrewをインストール

1.Homebrewがインストールされていないことを確認

% brew -v
zsh: command not found: brew

2.Homebrewのページからインストールコマンドをコピーして実行

% /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

3.インストールバージョンを確認

% brew -v
Homebrew 2.2.14
Homebrew/homebrew-core (git revision 73dc10; last commit 2020-05-03)

脱線:インストール時の標準出力を読んでみる

※実行時の環境によって出力される内容は変わります
※ユーザー名が出てくるところは書き換えてます

ここまではHomebrewのインストール作業の内容(変更があるものだけ)が出力されています。
スクリプト読む限り、オーナーの書き込み権限変更が必要となるディレクトリも検出された場合は出力されるようです。

  • インストール先
  • グループのパーミッション変更対象ディレクトリ
  • オーナー変更対象ディレクトリ
  • グループ変更対象ディレクトリ
  • 作成するディレクトリ
  • Command Line Tools for Xcodeをインストールする
==> This script will install:
/usr/local/bin/brew
/usr/local/share/doc/homebrew
/usr/local/share/man/man1/brew.1
/usr/local/share/zsh/site-functions/_brew
/usr/local/etc/bash_completion.d/brew
/usr/local/Homebrew
==> The following existing directories will be made group writable:
/usr/local/bin
/usr/local/include
/usr/local/lib
/usr/local/sbin
/usr/local/share
/usr/local/lib/pkgconfig
/usr/local/share/man
/usr/local/share/man/man1
/usr/local/share/man/man8
==> The following existing directories will have their owner set to ya8612tec:
/usr/local/bin
/usr/local/include
/usr/local/lib
/usr/local/sbin
/usr/local/share
/usr/local/lib/pkgconfig
/usr/local/share/man
/usr/local/share/man/man1
/usr/local/share/man/man8
==> The following existing directories will have their group set to admin:
/usr/local/bin
/usr/local/include
/usr/local/lib
/usr/local/sbin
/usr/local/share
/usr/local/lib/pkgconfig
/usr/local/share/man
/usr/local/share/man/man1
/usr/local/share/man/man8
==> The following new directories will be created:
/usr/local/etc
/usr/local/var
/usr/local/opt
/usr/local/share/zsh
/usr/local/share/zsh/site-functions
/usr/local/var/homebrew
/usr/local/var/homebrew/linked
/usr/local/Cellar
/usr/local/Caskroom
/usr/local/Homebrew
/usr/local/Frameworks
==> The Xcode Command Line Tools will be installed.

ここは実際のインストール作業(Homebrew以外)です。

  • オーナーのパーミッション変更
  • グループのパーミッション変更
  • オーナー変更
  • グループ変更
  • ディレクトリ作成
  • 作成したディレクトリに対して以下を実行
    • グループのパーミッション変更
    • オーナー変更
    • グループ変更
  • ユーザーキャッシュディレクトリを作成
  • 作成したユーザーキャッシュディレクトリに対して以下を実行
    • グループのパーミッション変更
    • オーナー変更
  • Command Line Tools for Xcodeをインストール
Press RETURN to continue or any other key to abort
Password:
==> /usr/bin/sudo /bin/chmod u+rwx /usr/local/bin /usr/local/include /usr/local/lib /usr/local/sbin /usr/local/share /usr/local/lib/pkgconfig /usr/local/share/man /usr/local/share/man/man1 /usr/local/share/man/man8
==> /usr/bin/sudo /bin/chmod g+rwx /usr/local/bin /usr/local/include /usr/local/lib /usr/local/sbin /usr/local/share /usr/local/lib/pkgconfig /usr/local/share/man /usr/local/share/man/man1 /usr/local/share/man/man8
==> /usr/bin/sudo /usr/sbin/chown ya8612tec /usr/local/bin /usr/local/include /usr/local/lib /usr/local/sbin /usr/local/share /usr/local/lib/pkgconfig /usr/local/share/man /usr/local/share/man/man1 /usr/local/share/man/man8
==> /usr/bin/sudo /usr/bin/chgrp admin /usr/local/bin /usr/local/include /usr/local/lib /usr/local/sbin /usr/local/share /usr/local/lib/pkgconfig /usr/local/share/man /usr/local/share/man/man1 /usr/local/share/man/man8
==> /usr/bin/sudo /bin/mkdir -p /usr/local/etc /usr/local/var /usr/local/opt /usr/local/share/zsh /usr/local/share/zsh/site-functions /usr/local/var/homebrew /usr/local/var/homebrew/linked /usr/local/Cellar /usr/local/Caskroom /usr/local/Homebrew /usr/local/Frameworks
==> /usr/bin/sudo /bin/chmod g+rwx /usr/local/etc /usr/local/var /usr/local/opt /usr/local/share/zsh /usr/local/share/zsh/site-functions /usr/local/var/homebrew /usr/local/var/homebrew/linked /usr/local/Cellar /usr/local/Caskroom /usr/local/Homebrew /usr/local/Frameworks
==> /usr/bin/sudo /usr/sbin/chown ya8612tec /usr/local/etc /usr/local/var /usr/local/opt /usr/local/share/zsh /usr/local/share/zsh/site-functions /usr/local/var/homebrew /usr/local/var/homebrew/linked /usr/local/Cellar /usr/local/Caskroom /usr/local/Homebrew /usr/local/Frameworks
==> /usr/bin/sudo /usr/bin/chgrp admin /usr/local/etc /usr/local/var /usr/local/opt /usr/local/share/zsh /usr/local/share/zsh/site-functions /usr/local/var/homebrew /usr/local/var/homebrew/linked /usr/local/Cellar /usr/local/Caskroom /usr/local/Homebrew /usr/local/Frameworks
==> /usr/bin/sudo /bin/mkdir -p /Users/ya8612tec/Library/Caches/Homebrew
==> /usr/bin/sudo /bin/chmod g+rwx /Users/ya8612tec/Library/Caches/Homebrew
==> /usr/bin/sudo /usr/sbin/chown ya8612tec /Users/ya8612tec/Library/Caches/Homebrew
==> Searching online for the Command Line Tools
==> /usr/bin/sudo /usr/bin/touch /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress
==> Installing Command Line Tools for Xcode-11.4
==> /usr/bin/sudo /usr/sbin/softwareupdate -i Command\ Line\ Tools\ for\ Xcode-11.4
Software Update Tool


Downloading Command Line Tools for Xcode
Downloaded Command Line Tools for Xcode
Installing Command Line Tools for Xcode
Done with Command Line Tools for Xcode
Done.
==> /usr/bin/sudo /bin/rm -f /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress
==> /usr/bin/sudo /usr/bin/xcode-select --switch /Library/Developer/CommandLineTools

さて、メインとなるHomebrewのインストールです。
ここは出力から読み取れることあまりなかったのでスクリプトもさらっと読みました。

  • /usr/local/Homebrew/ディレクトリへ移動
  • HomebrewをGitリポジトリからクローン(git initして、configにremoteの設定して、fetchしてました)
  • /usr/local/bin/の中に、/usr/local/Homebrew/bin/brewのシンボリックリンクを作成
  • brew updateコマンドで、home-brew/coreリポジトリをクローン
==> Downloading and installing Homebrew...
remote: Enumerating objects: 71, done.
remote: Counting objects: 100% (71/71), done.
remote: Compressing objects: 100% (71/71), done.
remote: Total 135770 (delta 13), reused 50 (delta 0), pack-reused 135699
Receiving objects: 100% (135770/135770), 32.76 MiB | 8.32 MiB/s, done.
Resolving deltas: 100% (99773/99773), done.
From https://github.com/Homebrew/brew
 * [new branch]      master     -> origin/master
 * [new tag]             0.1        -> 0.1
 * [new tag]             0.2        -> 0.2
 * [new tag]             0.3        -> 0.3
 * [new tag]             0.4        -> 0.4
 * [new tag]             0.5        -> 0.5
 * [new tag]             0.6        -> 0.6
 * [new tag]             0.7        -> 0.7
 * [new tag]             0.7.1      -> 0.7.1
 * [new tag]             0.8        -> 0.8
 * [new tag]             0.8.1      -> 0.8.1
 * [new tag]             0.9        -> 0.9
 * [new tag]             0.9.1      -> 0.9.1
 * [new tag]             0.9.2      -> 0.9.2
 * [new tag]             0.9.3      -> 0.9.3
 * [new tag]             0.9.4      -> 0.9.4
 * [new tag]             0.9.5      -> 0.9.5
 * [new tag]             0.9.8      -> 0.9.8
 * [new tag]             0.9.9      -> 0.9.9
 * [new tag]             1.0.0      -> 1.0.0
 * [new tag]             1.0.1      -> 1.0.1
 * [new tag]             1.0.2      -> 1.0.2
 * [new tag]             1.0.3      -> 1.0.3
 * [new tag]             1.0.4      -> 1.0.4
 * [new tag]             1.0.5      -> 1.0.5
 * [new tag]             1.0.6      -> 1.0.6
 * [new tag]             1.0.7      -> 1.0.7
 * [new tag]             1.0.8      -> 1.0.8
 * [new tag]             1.0.9      -> 1.0.9
 * [new tag]             1.1.0      -> 1.1.0
 * [new tag]             1.1.1      -> 1.1.1
 * [new tag]             1.1.10     -> 1.1.10
 * [new tag]             1.1.11     -> 1.1.11
 * [new tag]             1.1.12     -> 1.1.12
 * [new tag]             1.1.13     -> 1.1.13
 * [new tag]             1.1.2      -> 1.1.2
 * [new tag]             1.1.3      -> 1.1.3
 * [new tag]             1.1.4      -> 1.1.4
 * [new tag]             1.1.5      -> 1.1.5
 * [new tag]             1.1.6      -> 1.1.6
 * [new tag]             1.1.7      -> 1.1.7
 * [new tag]             1.1.8      -> 1.1.8
 * [new tag]             1.1.9      -> 1.1.9
 * [new tag]             1.2.0      -> 1.2.0
 * [new tag]             1.2.1      -> 1.2.1
 * [new tag]             1.2.2      -> 1.2.2
 * [new tag]             1.2.3      -> 1.2.3
 * [new tag]             1.2.4      -> 1.2.4
 * [new tag]             1.2.5      -> 1.2.5
 * [new tag]             1.2.6      -> 1.2.6
 * [new tag]             1.3.0      -> 1.3.0
 * [new tag]             1.3.1      -> 1.3.1
 * [new tag]             1.3.2      -> 1.3.2
 * [new tag]             1.3.3      -> 1.3.3
 * [new tag]             1.3.4      -> 1.3.4
 * [new tag]             1.3.5      -> 1.3.5
 * [new tag]             1.3.6      -> 1.3.6
 * [new tag]             1.3.7      -> 1.3.7
 * [new tag]             1.3.8      -> 1.3.8
 * [new tag]             1.3.9      -> 1.3.9
 * [new tag]             1.4.0      -> 1.4.0
 * [new tag]             1.4.1      -> 1.4.1
 * [new tag]             1.4.2      -> 1.4.2
 * [new tag]             1.4.3      -> 1.4.3
 * [new tag]             1.5.0      -> 1.5.0
 * [new tag]             1.5.1      -> 1.5.1
 * [new tag]             1.5.10     -> 1.5.10
 * [new tag]             1.5.11     -> 1.5.11
 * [new tag]             1.5.12     -> 1.5.12
 * [new tag]             1.5.13     -> 1.5.13
 * [new tag]             1.5.14     -> 1.5.14
 * [new tag]             1.5.2      -> 1.5.2
 * [new tag]             1.5.3      -> 1.5.3
 * [new tag]             1.5.4      -> 1.5.4
 * [new tag]             1.5.5      -> 1.5.5
 * [new tag]             1.5.6      -> 1.5.6
 * [new tag]             1.5.7      -> 1.5.7
 * [new tag]             1.5.8      -> 1.5.8
 * [new tag]             1.5.9      -> 1.5.9
 * [new tag]             1.6.0      -> 1.6.0
 * [new tag]             1.6.1      -> 1.6.1
 * [new tag]             1.6.10     -> 1.6.10
 * [new tag]             1.6.11     -> 1.6.11
 * [new tag]             1.6.12     -> 1.6.12
 * [new tag]             1.6.13     -> 1.6.13
 * [new tag]             1.6.14     -> 1.6.14
 * [new tag]             1.6.15     -> 1.6.15
 * [new tag]             1.6.16     -> 1.6.16
 * [new tag]             1.6.17     -> 1.6.17
 * [new tag]             1.6.2      -> 1.6.2
 * [new tag]             1.6.3      -> 1.6.3
 * [new tag]             1.6.4      -> 1.6.4
 * [new tag]             1.6.5      -> 1.6.5
 * [new tag]             1.6.6      -> 1.6.6
 * [new tag]             1.6.7      -> 1.6.7
 * [new tag]             1.6.8      -> 1.6.8
 * [new tag]             1.6.9      -> 1.6.9
 * [new tag]             1.7.0      -> 1.7.0
 * [new tag]             1.7.1      -> 1.7.1
 * [new tag]             1.7.2      -> 1.7.2
 * [new tag]             1.7.3      -> 1.7.3
 * [new tag]             1.7.4      -> 1.7.4
 * [new tag]             1.7.5      -> 1.7.5
 * [new tag]             1.7.6      -> 1.7.6
 * [new tag]             1.7.7      -> 1.7.7
 * [new tag]             1.8.0      -> 1.8.0
 * [new tag]             1.8.1      -> 1.8.1
 * [new tag]             1.8.2      -> 1.8.2
 * [new tag]             1.8.3      -> 1.8.3
 * [new tag]             1.8.4      -> 1.8.4
 * [new tag]             1.8.5      -> 1.8.5
 * [new tag]             1.8.6      -> 1.8.6
 * [new tag]             1.9.0      -> 1.9.0
 * [new tag]             1.9.1      -> 1.9.1
 * [new tag]             1.9.2      -> 1.9.2
 * [new tag]             1.9.3      -> 1.9.3
 * [new tag]             2.0.0      -> 2.0.0
 * [new tag]             2.0.1      -> 2.0.1
 * [new tag]             2.0.2      -> 2.0.2
 * [new tag]             2.0.3      -> 2.0.3
 * [new tag]             2.0.4      -> 2.0.4
 * [new tag]             2.0.5      -> 2.0.5
 * [new tag]             2.0.6      -> 2.0.6
 * [new tag]             2.1.0      -> 2.1.0
 * [new tag]             2.1.1      -> 2.1.1
 * [new tag]             2.1.10     -> 2.1.10
 * [new tag]             2.1.11     -> 2.1.11
 * [new tag]             2.1.12     -> 2.1.12
 * [new tag]             2.1.13     -> 2.1.13
 * [new tag]             2.1.14     -> 2.1.14
 * [new tag]             2.1.15     -> 2.1.15
 * [new tag]             2.1.16     -> 2.1.16
 * [new tag]             2.1.2      -> 2.1.2
 * [new tag]             2.1.3      -> 2.1.3
 * [new tag]             2.1.4      -> 2.1.4
 * [new tag]             2.1.5      -> 2.1.5
 * [new tag]             2.1.6      -> 2.1.6
 * [new tag]             2.1.7      -> 2.1.7
 * [new tag]             2.1.8      -> 2.1.8
 * [new tag]             2.1.9      -> 2.1.9
 * [new tag]             2.2.0      -> 2.2.0
 * [new tag]             2.2.1      -> 2.2.1
 * [new tag]             2.2.10     -> 2.2.10
 * [new tag]             2.2.11     -> 2.2.11
 * [new tag]             2.2.12     -> 2.2.12
 * [new tag]             2.2.13     -> 2.2.13
 * [new tag]             2.2.14     -> 2.2.14
 * [new tag]             2.2.2      -> 2.2.2
 * [new tag]             2.2.3      -> 2.2.3
 * [new tag]             2.2.4      -> 2.2.4
 * [new tag]             2.2.5      -> 2.2.5
 * [new tag]             2.2.6      -> 2.2.6
 * [new tag]             2.2.7      -> 2.2.7
 * [new tag]             2.2.8      -> 2.2.8
 * [new tag]             2.2.9      -> 2.2.9
HEAD is now at 3247f26a3 Merge pull request #7479 from sjackman/requirements
==> Homebrew is run entirely by unpaid volunteers. Please consider donating:
  https://github.com/Homebrew/brew#donations
==> Tapping homebrew/core
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core'...
remote: Enumerating objects: 54, done.
remote: Counting objects: 100% (54/54), done.
remote: Compressing objects: 100% (40/40), done.
remote: Total 716208 (delta 37), reused 24 (delta 14), pack-reused 716154
Receiving objects: 100% (716208/716208), 290.31 MiB | 10.29 MiB/s, done.
Resolving deltas: 100% (472259/472259), done.
Updating files: 100% (5224/5224), done.
Tapped 2 commands and 4982 formulae (5,249 files, 318.2MB).
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
No analytics data has been sent yet (or will be during this `install` run).

==> 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

脱線終わり。

pyenvをHomebrewでインストール

1.pyenvがインストールされていないことを確認

% pyenv -v
zsh: command not found: pyenv

2.インストール実行

% brew install pyenv

3.インストールバージョンを確認

% pyenv -v
pyenv 1.2.18

脱線:インストール時の標準出力を読んでみる

※実行時の環境によって出力される内容は変わります
※ユーザー名が出てくるところは書き換えてます

pyenvを入れるためにはautoconf / openssl@1.1 / pkg-config / readlineが必要ということです。

==> Installing dependencies for pyenv: autoconf, openssl@1.1, pkg-config and readline

autoconfをバイナリインストールしています。

==> Installing pyenv dependency: autoconf
==> Downloading https://homebrew.bintray.com/bottles/autoconf-2.69.catalina.bottle.4.tar.gz
==> Downloading from https://akamai.bintray.com/ca/ca510b350e941fb9395522a03f9d2fb5df276085d806ceead763acb
######################################################################## 100.0%
==> Pouring autoconf-2.69.catalina.bottle.4.tar.gz
🍺  /usr/local/Cellar/autoconf/2.69: 67 files, 3.0MB

openssl@1.1をバイナリインストールしています。いくつか注意事項があるようです。

  • 追加のCAファイルを配置したい場合は.pemで/usr/local/etc/openssl@1.1/certsに配置し、/usr/local/opt/openssl@1.1/bin/c_rehashコマンドを実行
  • openssl@1.1はCellerにのみインストールされ、/usr/local/へのシンボリックリンクは作成しない。
    これは、MacのHigh Sierraから標準がLibreSSLになっているため。もしopensslコマンドで使用したい場合はecho 'export PATH="/usr/local/opt/openssl@1.1/bin:$PATH"' >> ~/.zshrcコマンドを実行
  • コンパイラにパスを通すには、以下のコマンドを実行
    • export LDFLAGS="-L/usr/local/opt/openssl@1.1/lib"
    • export CPPFLAGS="-I/usr/local/opt/openssl@1.1/include"
==> Installing pyenv dependency: openssl@1.1
==> Downloading https://homebrew.bintray.com/bottles/openssl@1.1-1.1.1g.catalina.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/19/1926679569c6af5337de812d86f4dad2b21ff883ad3a5d2cd9e8836
######################################################################## 100.0%
==> Pouring openssl@1.1-1.1.1g.catalina.bottle.tar.gz
==> Caveats
A CA file has been bootstrapped using certificates from the system
keychain. To add additional certificates, place .pem files in
  /usr/local/etc/openssl@1.1/certs

and run
  /usr/local/opt/openssl@1.1/bin/c_rehash

openssl@1.1 is keg-only, which means it was not symlinked into /usr/local,
because macOS provides LibreSSL.

If you need to have openssl@1.1 first in your PATH run:
  echo 'export PATH="/usr/local/opt/openssl@1.1/bin:$PATH"' >> ~/.zshrc

For compilers to find openssl@1.1 you may need to set:
  export LDFLAGS="-L/usr/local/opt/openssl@1.1/lib"
  export CPPFLAGS="-I/usr/local/opt/openssl@1.1/include"

==> Summary
🍺  /usr/local/Cellar/openssl@1.1/1.1.1g: 8,059 files, 18MB

pkg-configをバイナリインストールしています。

==> Installing pyenv dependency: pkg-config
==> Downloading https://homebrew.bintray.com/bottles/pkg-config-0.29.2_3.catalina.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/80/80f141e695f73bd058fd82e9f539dc67471666ff6800c5e280b5af7
######################################################################## 100.0%
==> Pouring pkg-config-0.29.2_3.catalina.bottle.tar.gz
🍺  /usr/local/Cellar/pkg-config/0.29.2_3: 11 files, 623.7KB

readlineをバイナリインストールしています。いくつか注意事項があるようです。

  • readlineはCellerにのみインストールされ、/usr/local/へのシンボリックリンクは作成しない。
    これは、Macの標準(いつから変わったかはわからず)がlibeditになっているため。
  • コンパイラにパスを通すには、以下のコマンドを実行
    • export LDFLAGS="-L/usr/local/opt/readline/lib"
    • export CPPFLAGS="-I/usr/local/opt/readline/include"
  • pkg-configにパスを通すには、以下のコマンドを実行
    • export PKG_CONFIG_PATH="/usr/local/opt/readline/lib/pkgconfig"
==> Installing pyenv dependency: readline
==> Downloading https://homebrew.bintray.com/bottles/readline-8.0.4.catalina.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/6a/6ae1c8e7c783f32bd22c6085caa4d838fed7fb386da7e40ca47b87e
######################################################################## 100.0%
==> Pouring readline-8.0.4.catalina.bottle.tar.gz
==> Caveats
readline is keg-only, which means it was not symlinked into /usr/local,
because macOS provides BSD libedit.

For compilers to find readline you may need to set:
  export LDFLAGS="-L/usr/local/opt/readline/lib"
  export CPPFLAGS="-I/usr/local/opt/readline/include"

For pkg-config to find readline you may need to set:
  export PKG_CONFIG_PATH="/usr/local/opt/readline/lib/pkgconfig"

==> Summary
🍺  /usr/local/Cellar/readline/8.0.4: 48 files, 1.5MB

最後に、pyenvをバイナリインストールしています。ここまでに出力された注意事項が再度出力されています。

==> Installing pyenv
==> Downloading https://homebrew.bintray.com/bottles/pyenv-1.2.18.catalina.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/bd/bd9f719f153e9574dcc65dc7fea28a3816557bd46b0ff90ad8de43f
######################################################################## 100.0%
==> Pouring pyenv-1.2.18.catalina.bottle.tar.gz
🍺  /usr/local/Cellar/pyenv/1.2.18: 695 files, 2.5MB
==> Caveats
==> openssl@1.1
A CA file has been bootstrapped using certificates from the system
keychain. To add additional certificates, place .pem files in
  /usr/local/etc/openssl@1.1/certs

and run
  /usr/local/opt/openssl@1.1/bin/c_rehash

openssl@1.1 is keg-only, which means it was not symlinked into /usr/local,
because macOS provides LibreSSL.

If you need to have openssl@1.1 first in your PATH run:
  echo 'export PATH="/usr/local/opt/openssl@1.1/bin:$PATH"' >> ~/.zshrc

For compilers to find openssl@1.1 you may need to set:
  export LDFLAGS="-L/usr/local/opt/openssl@1.1/lib"
  export CPPFLAGS="-I/usr/local/opt/openssl@1.1/include"

For pkg-config to find openssl@1.1 you may need to set:
  export PKG_CONFIG_PATH="/usr/local/opt/openssl@1.1/lib/pkgconfig"

==> readline
readline is keg-only, which means it was not symlinked into /usr/local,
because macOS provides BSD libedit.

For compilers to find readline you may need to set:
  export LDFLAGS="-L/usr/local/opt/readline/lib"
  export CPPFLAGS="-I/usr/local/opt/readline/include"

For pkg-config to find readline you may need to set:
  export PKG_CONFIG_PATH="/usr/local/opt/readline/lib/pkgconfig"

脱線終わり。

pyenvの環境設定をシェル起動時に実行するようにしておく

1.pyenvのルートディレクトリを環境変数に設定(ここにPythonの各バージョンがインストールされていく)

echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc

2.pyenvのinitコマンドをzshrcに書いておく

echo 'eval "$(pyenv init -)"' >> ~/.zshrc

3..zshrcを読み込む(初回のみ手動実行)
シェル起動時に読み込まれる設定ファイルなので、ターミナル再起動したり、別タブで開いたりしてもよい。

source ~/.zshrc

pyenvでPython 3.8.2をインストール

1.バージョンを確認

% python -V
Python 2.7.16

2.インストール実行

% pyenv install 3.8.2

3.インストールしたバージョンを反映させる

pyenv rehash

4.Pythonのバージョンを切り替え

% pyenv global 3.8.2

5.pythonのパスを確認

% which python
/Users/ya8612tec/.pyenv/shims/python

6.バージョン確認

% python -V
Python 3.8.2

仮想環境の構築

1.作業ディレクトリにvenvで仮想環境を作成

% python -m venv python_study

2.仮想環境を有効化

% source python_study/bin/activate

(python_study) ya8612tec@xxxxxxxx python %みたいにプロンプトが変わったらOK

3.pipのバージョンを確認

% pip -V
pip 19.2.3 from /Users/yuusuke/Documents/Tech/python/python_study/lib/python3.8/site-packages/pip (python 3.8)

4.pipのバージョンアップ

% pip install --upgrade pip

5.pipのバージョンを確認

% pip -V                   
pip 20.1 from /Users/yuusuke/Documents/Tech/python/python_study/lib/python3.8/site-packages/pip (python 3.8)

6.wheelのインストール

% pip install wheel

Djangoのインストール

1.Django 3.0.5のインストール

% pip install django

2.djangorestframework 3.11.0のインストール

% pip install djangorestframework

おわりに

環境構築はこれで完了。コードの学習に入ります。

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1