$ docker run -it image_name /bin/sh /code # /code # which pip /usr/local/bin/pip /code # pip list Package Version ----------- ------- asgiref 3.3.4 Django 3.2.4 mysqlclient 2.0.3 pip 21.1.2 pytz 2021.1 setuptools 57.0.0 sqlparse 0.4.1 wheel 0.36.2 WARNING: You are using pip version 21.1.2; however, version 21.1.3 is available. You should consider upgrading via the '/usr/local/bin/python -m pip install --upgrade pip' command.
$ docker-compose run --rm web pip list Creating django_web_run ... done Package Version ----------- ------- asgiref 3.3.4 Django 3.2.4 mysqlclient 2.0.3 pip 21.1.2 pytz 2021.1 setuptools 57.0.0 sqlparse 0.4.1 wheel 0.36.2 WARNING: You are using pip version 21.1.2; however, version 21.1.3 is available. You should consider upgrading via the '/usr/local/bin/python -m pip install --upgrade pip' command.
インストールしたパッケージは消えてなくなっています。
モジュールのアップデート
結果はなんとなくわかりますが、警告が出ていたpipをアップデートしてみます。
1 2 3 4 5 6 7 8 9 10 11 12 13
$ docker-compose run --rm web python -m pip install --upgrade pip Creating django_web_run ... done Requirement already satisfied: pip in /usr/local/lib/python3.9/site-packages (21.1.2) Collecting pip Downloading pip-21.1.3-py3-none-any.whl (1.5 MB) |████████████████████████████████| 1.5 MB 5.9 MB/s Installing collected packages: pip Attempting uninstall: pip Found existing installation: pip 21.1.2 Uninstalling pip-21.1.2: Successfully uninstalled pip-21.1.2 Successfully installed pip-21.1.3 WARNING: Running pip as root will break packages and permissions. You should install packages reliably by using venv: https://pip.pypa.io/warnings/venv
無事21.1.3にアップデートされたように見えます。
pip listで確認します。
1 2 3 4 5 6 7 8 9 10 11 12 13 14
$ docker-compose run --rm web python -m pip list Creating django_web_run ... done Package Version ----------- ------- asgiref 3.3.4 Django 3.2.4 mysqlclient 2.0.3 pip 21.1.2 pytz 2021.1 setuptools 57.0.0 sqlparse 0.4.1 wheel 0.36.2 WARNING: You are using pip version 21.1.2; however, version 21.1.3 is available. You should consider upgrading via the '/usr/local/bin/python -m pip install --upgrade pip' command.
volumes: mysql: driver: local site-packages: driver: local
この設定で試してみます。
動作確認
さきほどと同様にpip listから始めます
1 2 3 4 5 6 7 8 9 10 11 12 13 14
$ docker-compose run --rm web python -m pip list Creating django_web_run ... done Package Version ----------- ------- asgiref 3.3.4 Django 3.2.4 mysqlclient 2.0.3 pip 21.1.2 pytz 2021.1 setuptools 57.0.0 sqlparse 0.4.1 wheel 0.36.2 WARNING: You are using pip version 21.1.2; however, version 21.1.3 is available. You should consider upgrading via the '/usr/local/bin/python -m pip install --upgrade pip' command.
pipをアップデートしてみます。
1 2 3 4 5 6 7 8 9 10 11 12 13
$ docker-compose run --rm web python -m pip install --upgrade pip Creating django_web_run ... done Requirement already satisfied: pip in /usr/local/lib/python3.9/site-packages (21.1.2) Collecting pip Downloading pip-21.1.3-py3-none-any.whl (1.5 MB) |████████████████████████████████| 1.5 MB 3.3 MB/s Installing collected packages: pip Attempting uninstall: pip Found existing installation: pip 21.1.2 Uninstalling pip-21.1.2: Successfully uninstalled pip-21.1.2 Successfully installed pip-21.1.3 WARNING: Running pip as root will break packages and permissions. You should install packages reliably by using venv: https://pip.pypa.io/warnings/venv
無事できました。
pip listでアップデートされたままかどうか確認します。
1 2 3 4 5 6 7 8 9 10 11 12
$ docker-compose run --rm web python -m pip list Creating django_web_run ... done Package Version ----------- ------- asgiref 3.3.4 Django 3.2.4 mysqlclient 2.0.3 pip 21.1.3 pytz 2021.1 setuptools 57.0.0 sqlparse 0.4.1 wheel 0.36.2
WARNING: Running pip as root will break packages and permissions. You should install packages reliably by using venv: https://pip.pypa.io/warnings/venv
$ pip list Package Version --------------- -------- awscli 1.18.169 botocore 1.19.9 colorama 0.4.3 docutils 0.15.2 jmespath 0.10.0 pip 21.1.1 pyasn1 0.4.8 python-dateutil 2.8.1 PyYAML 5.3.1 rsa 4.5 s3transfer 0.3.3 setuptools 56.0.0 six 1.15.0 urllib3 1.25.11 WARNING: You are using pip version 21.1.1; however, version 21.1.3 is available. You should consider upgrading via the '/Users/user/.anyenv/envs/pyenv/versions/3.9.5/bin/python3.9 -m pip install --upgrade pip' command.
$ source venv/bin/activate (venv) $ pip list Package Version ---------- ------- pip 21.1.1 setuptools 56.0.0 WARNING: You are using pip version 21.1.1; however, version 21.1.3 is available. You should consider upgrading via the '/Users/user/github/django/venv/bin/python -m pip install --upgrade pip' command.
(venv) $ pip list Package Version ---------- ------- pip 21.1.3 setuptools 56.0.0
グローバル環境の確認
ここで一旦仮想環境を止めてみます。
1 2
(venv) $ deactivate $
pip listでインストール済パッケージ一覧を確認します。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
$ pip list Package Version --------------- -------- awscli 1.18.169 botocore 1.19.9 colorama 0.4.3 docutils 0.15.2 jmespath 0.10.0 pip 21.1.1 pyasn1 0.4.8 python-dateutil 2.8.1 PyYAML 5.3.1 rsa 4.5 s3transfer 0.3.3 setuptools 56.0.0 six 1.15.0 urllib3 1.25.11 WARNING: You are using pip version 21.1.1; however, version 21.1.3 is available. You should consider upgrading via the '/Users/user/.anyenv/envs/pyenv/versions/3.9.5/bin/python3.9 -m pip install --upgrade pip' command.
$ docker-compose up Starting django_db_1 ... done Starting django_web_1 ... done Attaching to django_db_1, django_web_1 (中略) web_1 | Watching for file changes with StatReloader web_1 | Performing system checks... web_1 | web_1 | System check identified no issues (0 silenced). web_1 | web_1 | You have 18 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions. web_1 | Run 'python manage.py migrate' to apply them. web_1 | June 24, 2021 - 12:27:25 web_1 | Django version 3.2.4, using settings 'composeexample.settings' web_1 | Starting development server at http://0.0.0.0:8000/ web_1 | Quit the server with CONTROL-C.
web_1 | You have 18 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions. web_1 | Run 'python manage.py migrate' to apply them.
$ docker-compose run --rm web python manage.py migrate Starting django_db_1 ... done Creating django_web_run ... done Operations to perform: Apply all migrations: admin, auth, contenttypes, sessions Running migrations: Applying contenttypes.0001_initial... OK Applying auth.0001_initial... OK Applying admin.0001_initial... OK Applying admin.0002_logentry_remove_auto_add... OK Applying admin.0003_logentry_add_action_flag_choices... OK Applying contenttypes.0002_remove_content_type_name... OK Applying auth.0002_alter_permission_name_max_length... OK Applying auth.0003_alter_user_email_max_length... OK Applying auth.0004_alter_user_username_opts... OK Applying auth.0005_alter_user_last_login_null... OK Applying auth.0006_require_contenttypes_0002... OK Applying auth.0007_alter_validators_add_error_messages... OK Applying auth.0008_alter_user_username_max_length... OK Applying auth.0009_alter_user_last_name_max_length... OK Applying auth.0010_alter_group_name_max_length... OK Applying auth.0011_update_proxy_permissions... OK Applying auth.0012_alter_user_first_name_max_length... OK Applying sessions.0001_initial... OK
マイグレーションが完了しました。
docker-compose upしたときのメッセージも確認します
1 2 3 4 5 6 7 8
web_1 | Watching for file changes with StatReloader web_1 | Performing system checks... web_1 | web_1 | System check identified no issues (0 silenced). web_1 | June 24, 2021 - 12:59:28 web_1 | Django version 3.2.4, using settings 'composeexample.settings' web_1 | Starting development server at http://0.0.0.0:8000/ web_1 | Quit the server with CONTROL-C.
python-build: use readline from homebrew Downloading Python-3.9.5.tar.xz... -> https://www.python.org/ftp/python/3.9.5/Python-3.9.5.tar.xz Installing Python-3.9.5... python-build: use readline from homebrew Installed Python-3.9.5 to /Users/user/.anyenv/envs/pyenv/versions/3.9.5
# If your ~/.profile sources ~/.bashrc, # the lines need to be inserted before the part # that does that. See the README for another option.
# If you have ~/.bash_profile, make sure that it # also executes the above lines -- e.g. by # copying them there or by sourcing ~/.profile
# Load pyenv into the shell by adding # the following to ~/.bashrc:
eval "$(pyenv init -)"
# Make sure to restart your entire logon session # for changes to profile files to take effect.
anyenvを利用しているためPATHが少し違いますので注意が必要です。
動作確認
早速動作確認をしてみます
1 2 3 4 5 6 7
$ python Python 3.7.9 (default, Nov 16 2020, 18:18:20) [Clang 10.0.0 (clang-1000.10.44.4)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> exit Use exit() or Ctrl-D (i.e. EOF) to exit >>> $
$ ls -a . .. $ pyenv local 3.9.5 $ ls -a . .. .python-version $ python Python 3.9.5 (default, Jun 8 2021, 23:01:54) [Clang 10.0.0 (clang-1000.10.44.4)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>>