2021/02/06
Python3インストール
Python3
# インストール
sudo apt-get install -y python3
sudo apt-get install -y python3-dev
sudo apt-get install -y python3-pip
sudo apt-get install -y python3-venv
sudo apt-get install -y python3-tk
# バージョン確認
python3 -V
# インストール先確認
which python3
# 仮想環境
## 仮想環境作成
python3 -m venv 仮想環境名
## 仮想環境削除
rm -Rf 仮想環境名
## 仮想環境に入る
source 仮想環境名/bin/activate
## 仮想環境から出る
deactivate
## ユーザーログイン時に仮想環境に強制的に入る
echo 'source 仮想環境名/bin/activate' >> ~/.bash_profile
# pip最新化
python3 -m pip install -U pip
# パッケージの追加
python3 -m pip install パッケージ名 # 脳死
python3 -m pip install パッケージ名==バージョン # バージョン指定
python3 -m pip install パッケージ名>=バージョン # バージョン以上
# パッケージの削除
python3 -m pip uninstall パッケージ名
# パッケージの更新
python3 -m pip install -U パッケージ名
# パッケージの一覧
python3 -m pip list
# パッケージの固定
python3 -m pip freeze > requirements.txt
python3 -m pip install -r requirements.txt
# 複数バージョンを維持
# 複数バージョンをインストール
sudo apt-get install -y python3.8
sudo apt-get install -y python3.9
# 複数バージョンを登録
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.9 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 2
# 複数バージョンの切替
sudo update-alternatives --config python3
# 複数バージョンの一覧
sudo update-alternatives --list python3
# webサーバー
python3 -m http.server 8080