目次
文書の過去の版を表示しています。
Python のインストール
Linux 編
殆どの Linux には既に Python が入っています。
$ python3 -V Python 3.8.1
Windows 編
- Welcome to Python.orgのDownload Python | Python.orgより最新バージョンをダウンロードしてくる。(ここでは python-3.8.1-amd64.exe を使用する。)
- ダウンロードした python-3.8.1-amd64.exe を実行して、[Customize installation] をクリックする。
- Advanced Options の [v]Install for all users にチェックを入れて Customize install location を C:\Python38 に変更する。(お好みで…)
- [Install] をクリックする。
- インストールが終わったら [Disable path length limit] をクリックしておく。
- タスクバーの「ここに入力して検索」に sysdm.cpl を入力して Enter キーを押す。
- 「システムのプロパティ」の「詳細設定」タブの[環境変数]ボタンを押して「環境変数」画面を開く。
- システム環境変数の Path に Python のフォルダ(C:\Python38;C:\Python38\Scripts;)を追加する。
Path:
C:\Python38;C:\Python38\Scripts;C:\Program Files...
- コマンドラインにて動作確認を行う。
> python -V Python 3.8.1
> python -VV Python 3.8.1 (tags/v3.8.1:1b293b6, Dec 18 2019, 23:11:46) [MSC v.1916 64 bit (AMD64)]
- pip をアップグレードする。
> python -m pip install --upgrade pip
Collecting pip Using cached https://files.pythonhosted.org/packages/54/0c/d01aa759fdc501a58f431eb594a17495f15b88da142ce14b5845662c13f3/pip-20.0.2-py2.py3-none-any.whl Installing collected packages: pip Found existing installation: pip 19.2.3 Uninstalling pip-19.2.3: Successfully uninstalled pip-19.2.3 Successfully installed pip-20.0.2
> pip -V pip 20.0.2 from c:\python38\lib\site-packages\pip (python 3.8)
Python 2.7/3.8 の共存
- Python 2.7 と Python 3.8 をインストールする。(2.7 と 3.8 のインストールの順番はどちらからでも良い)
- Python 2.7 は C:\Python27 に全てのユーザー共通でインストールする。
- Python 3.8 は C:\Python38 に全てのユーザー共通でインストールする。
- 環境変数の設定を行う。
- タスクバーの「ここに入力して検索」に sysdm.cpl を入力して Enter キーを押す。
- 「システムのプロパティ」の「詳細設定」タブの[環境変数]ボタンを押して「環境変数」画面を開く。
- 「環境変数」画面の [システム環境変数] の Path をダブルクリックする。
- 存在しない場合は [新規] ボタンを押して以下のパスを追加する。
C:\Python38\ C:\Python38\Scripts\ C:\Python27\Scripts\
- Path を設定したら [OK] ボタンで「環境変数名の編集」を閉じる。
- 「環境変数」画面の [システム環境変数] の [新規] ボタンを押して以下の環境変数を登録する。
変数名: PY_PYTHONPATH 変数値: 3
- 「環境変数」画面の [OK] ボタンを押して変更を反映させる。
- コマンドプロンプト (cmd) を実行して Python の起動確認を行う。
> py Python 3.8.1 (tags/v3.8.1:1b293b6, Dec 18 2019, 23:11:46) [MSC v.1916 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> Ctrl + Z で Enter を押して終了 > py -2 Python 2.7.17 (v2.7.17:c2f86d86e6, Oct 19 2019, 21:01:17) [MSC v.1500 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> Ctrl + Z で Enter を押して終了
- pip の起動確認を行う。
> pip -V pip 20.0.2 from c:\python38\lib\site-packages\pip (python 3.8) > pip2 -V pip 19.2.3 from c:\python27\lib\site-packages\pip (python 2.7) > pip3 -V pip 20.0.2 from c:\python38\lib\site-packages\pip (python 3.8)
- pip list を実行する。
> pip2 list DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support Package Version ---------- ------- pip 20.0.2 setuptools 41.2.0 virtualenv 16.7.4 > pip3 list Package Version ---------- ------- pip 20.0.2 setuptools 41.2.0
- 以下の警告が出る場合は Python 2/3 の pip を更新する。
WARNING: You are using pip version 19.2.3, however version 20.0.2 is available. You should consider upgrading via the 'python -m pip install --upgrade pip' command.
Python 2 の pip を更新
> py -2 -m pip install --upgrade pip DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support Collecting pip Using cached https://files.pythonhosted.org/packages/54/0c/d01aa759fdc501a58f431eb594a17495f15b88da142ce14b5845662c13f3/pip-20.0.2-py2.py3-none-any.whl Installing collected packages: pip Found existing installation: pip 19.2.3 Uninstalling pip-19.2.3: Successfully uninstalled pip-19.2.3 Successfully installed pip-20.0.2
Python 3 の pip を更新
> py -m pip install --upgrade pip Collecting pip Using cached https://files.pythonhosted.org/packages/54/0c/d01aa759fdc501a58f431eb594a17495f15b88da142ce14b5845662c13f3/pip-20.0.2-py2.py3-none-any.whl Installing collected packages: pip Found existing installation: pip 19.2.3 Uninstalling pip-19.2.3: Successfully uninstalled pip-19.2.3 Successfully installed pip-20.0.2
- .py の拡張子関連付けを Python 3.8 に設定する。
参考文献
Linux & Mac (pythonbrew) 編
ここでは pythonbrew を使って python をインストールします。
python のインストール
python 2.7.3 をインストールする。
$ pybrew install 2.7.3 Downloading Python-2.7.3.tgz as /Users/tomoyan/.pythonbrew/dists/Python-2.7.3.tgz ######################################################################## 100.0% Extracting Python-2.7.3.tgz into /Users/tomoyan/.pythonbrew/build/Python-2.7.3 This could take a while. You can run the following command on another shell to track the status: tail -f "/Users/tomoyan/.pythonbrew/log/build.log" Patching Python-2.7.3 Installing Python-2.7.3 into /Users/tomoyan/.pythonbrew/pythons/Python-2.7.3 Downloading distribute_setup.py as /Users/tomoyan/.pythonbrew/dists/distribute_setup.py ######################################################################## 100.0% Installing distribute into /Users/tomoyan/.pythonbrew/pythons/Python-2.7.3 Installing pip into /Users/tomoyan/.pythonbrew/pythons/Python-2.7.3 Installed Python-2.7.3 successfully. Run the following command to switch to Python-2.7.3. pythonbrew switch 2.7.3
python を切り替える
$ pybrew switch 2.7.3 Switched to Python-2.7.3 $ python -V Python 2.7.3
python 3.2.3 をインストールする。
$ pybrew install 3.2.3 Downloading Python-3.2.3.tgz as /Users/tomoyan/.pythonbrew/dists/Python-3.2.3.tgz ######################################################################## 100.0% Extracting Python-3.2.3.tgz into /Users/tomoyan/.pythonbrew/build/Python-3.2.3 This could take a while. You can run the following command on another shell to track the status: tail -f "/Users/tomoyan/.pythonbrew/log/build.log" Installing Python-3.2.3 into /Users/tomoyan/.pythonbrew/pythons/Python-3.2.3 Downloading distribute_setup.py as /Users/tomoyan/.pythonbrew/dists/distribute_setup.py ######################################################################## 100.0% Installing distribute into /Users/tomoyan/.pythonbrew/pythons/Python-3.2.3 Installing pip into /Users/tomoyan/.pythonbrew/pythons/Python-3.2.3 Installed Python-3.2.3 successfully. Run the following command to switch to Python-3.2.3. pythonbrew switch 3.2.3
python を切り替える
$ pybrew switch 3.2.3 Switched to Python-3.2.3 $ python -V Python 3.2.3