$ docker-compose run --rm web pip install --upgrade pip Creating django_web_run ... done Requirement already satisfied: pip in /usr/local/lib/python3.9/site-packages (21.1.3) Collecting pip Downloading pip-21.2.1-py3-none-any.whl (1.6 MB) |████████████████████████████████| 1.6 MB 39 kB/s Installing collected packages: pip Attempting uninstall: pip Found existing installation: pip 21.1.3 Uninstalling pip-21.1.3: Successfully uninstalled pip-21.1.3 Successfully installed pip-21.2.1 WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
$ docker-compose run --rm web python -m pipenv install Creating django_web_run ... done Creating a virtualenv for this project... Pipfile: /code/Pipfile Using /usr/local/bin/python3.9 (3.9.5) to create virtualenv... ⠇ Creating virtual environment...created virtual environment CPython3.9.5.final.0-64 in 518ms creator CPython3Posix(dest=/root/.local/share/virtualenvs/code-_Py8Si6I, clear=False, no_vcs_ignore=False, global=False) seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=/root/.local/share/virtualenv) added seed packages: pip==21.1.3, setuptools==57.1.0, wheel==0.36.2 activators BashActivator,CShellActivator,FishActivator,PowerShellActivator,PythonActivator,XonshActivator
✔ Successfully created virtual environment! Virtualenv location: /root/.local/share/virtualenvs/code-_Py8Si6I requirements.txt found, instead of Pipfile! Converting... ✔ Success! Warning: Your Pipfile now contains pinned versions, if your requirements.txt did. We recommend updating your Pipfile to specify the "*" version, instead. Pipfile.lock not found, creating... Locking [dev-packages] dependencies... Locking [packages] dependencies... Building requirements... Resolving dependencies... ✔ Success! Updated Pipfile.lock (1644d3)! Installing dependencies from Pipfile.lock (1644d3)... 🐍 ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉ 5/5 — 00:00:04 To activate this project's virtualenv, run pipenv shell. Alternatively, run a command inside the virtualenv with pipenv run.
実行が終わりました。PipfileとPipfile.lockも作成されています。
virtualenvについて
出力されたメッセージをみていて、気になる点がいくつかあります。
1 2
✔ Successfully created virtual environment! Virtualenv location: /root/.local/share/virtualenvs/code-_Py8Si6I
$ docker-compose run --rm web python -m pipenv --venv Creating django_web_run ... done No virtualenv has been created for this project(/code) yet! Aborted!
$ docker-compose run --rm web python -m pipenv uninstall --system --all Creating django_web_run ... done Creating a virtualenv for this project... Pipfile: /code/Pipfile Using /usr/local/bin/python3.9 (3.9.5) to create virtualenv... ⠇ Creating virtual environment...created virtual environment CPython3.9.5.final.0-64 in 521ms creator CPython3Posix(dest=/root/.local/share/virtualenvs/code-_Py8Si6I, clear=False, no_vcs_ignore=False, global=False) seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=/root/.local/share/virtualenv) added seed packages: pip==21.1.3, setuptools==57.1.0, wheel==0.36.2 activators BashActivator,CShellActivator,FishActivator,PowerShellActivator,PythonActivator,XonshActivator
✔ Successfully created virtual environment! Virtualenv location: /root/.local/share/virtualenvs/code-_Py8Si6I Un-installing all [dev-packages] and [packages]... Found 0 installed package, skip purging. Environment now purged and fresh!
$ docker-compose run --rm web python -m pip uninstall django Creating django_web_run ... done Found existing installation: Django 3.2.4 Uninstalling Django-3.2.4: Would remove: /usr/local/bin/django-admin /usr/local/bin/django-admin.py /usr/local/lib/python3.9/site-packages/Django-3.2.4.dist-info/* /usr/local/lib/python3.9/site-packages/django/* Proceed (Y/n)? Y Successfully uninstalled Django-3.2.4 WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
$ 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.