[英]Can't install any pip package within my docker environment, since it won't be recognized
I am running a Cookiecutter django project in a docker environment and I would like to add new packages via pip. 我正在docker环境中运行Cookiecutter django项目,我想通过pip添加新软件包。 Specifically I want to add: djangorestframework-jwt
具体来说,我想添加: djangorestframework-jwt
When I do: docker-compose -f local.yml run --rm django pip install
it seems like it would be perfectly working because I get: Successfully installed PyJWT-1.7.1 djangorestframework-jwt-1.11.0
当我这样做时: docker-compose -f local.yml run --rm django pip install
似乎可以正常工作,因为我得到: Successfully installed PyJWT-1.7.1 djangorestframework-jwt-1.11.0
Now the problem is that it doesn't install it. 现在的问题是它没有安装它。 It doesn't appear when I run pip freeze
, and also not in pip list
当我运行pip freeze
,它也没有出现,并且不在pip list
Then I tried to put it into my requirements.txt file and run it with: docker-compose -f local.yml run --rm django pip install -r requirements/base.txt
然后,我尝试将其放入我的requirements.txt文件中,并使用以下命令运行它: docker-compose -f local.yml run --rm django pip install -r requirements/base.txt
Same result. 结果相同。 It says that it is successfully installed but it is not. 它表示已成功安装,但未成功安装。 I thought it might be a problem with my django version and the package, but the same happens when I try to update my pip. 我以为django版本和程序包可能有问题,但是当我尝试更新我的pip时也会发生同样的情况。 It says it updated, but when I run pip install -upgrade pip
I get again: You should consider upgrading via the 'pip install --upgrade pip' command.
它说它已更新,但是当我运行pip install -upgrade pip
我又得到了: You should consider upgrading via the 'pip install --upgrade pip' command.
I'm running out of options. 我没有其他选择了。
My requirements: 我的要求:
-r ./base.txt
Werkzeug==0.14.1 # https://github.com/pallets/werkzeug
ipdb==0.11 # https://github.com/gotcha/ipdb
Sphinx==1.7.5 # https://github.com/sphinx-doc/sphinx
psycopg2==2.7.4 --no-binary psycopg2 # https://github.com/psycopg/psycopg2
# Testing
# ------------------------------------------------------------------------------
pytest==3.6.3 # https://github.com/pytest-dev/pytest
pytest-sugar==0.9.1 # https://github.com/Frozenball/pytest-sugar
# Code quality
# ------------------------------------------------------------------------------
flake8==3.5.0 # https://github.com/PyCQA/flake8
coverage==4.5.1 # https://github.com/nedbat/coveragepy
# Django
# ------------------------------------------------------------------------------
factory-boy==2.11.1 # https://github.com/FactoryBoy/factory_boy
django-debug-toolbar==1.9.1 # https://github.com/jazzband/django-debug-toolbar
django-extensions==2.0.7 # https://github.com/django-extensions/django-extensions
django-coverage-plugin==1.5.0 # https://github.com/nedbat/django_coverage_plugin
pytest-django==3.3.2 # https://github.com/pytest-dev/pytest-django
djangorestframework-jwt==1.11.0 # https://github.com/GetBlimp/django-rest-framework-jwt
Output of pip list: 点列表的输出:
Package Version
------------------------ --------
alabaster 0.7.12
argon2-cffi 18.1.0
atomicwrites 1.3.0
attrs 19.1.0
Babel 2.6.0
backcall 0.1.0
certifi 2019.3.9
cffi 1.12.2
chardet 3.0.4
coreapi 2.3.3
coreschema 0.0.4
coverage 4.5.1
decorator 4.4.0
defusedxml 0.5.0
Django 2.0.7
django-allauth 0.36.0
django-coverage-plugin 1.5.0
django-crispy-forms 1.7.2
django-debug-toolbar 1.9.1
django-environ 0.4.5
django-extensions 2.0.7
django-model-utils 3.1.2
django-redis 4.9.0
django-widget-tweaks 1.4.3
djangorestframework 3.8.2
docutils 0.14
factory-boy 2.11.1
Faker 1.0.4
flake8 3.5.0
idna 2.8
imagesize 1.1.0
ipdb 0.11
ipython 7.4.0
ipython-genutils 0.2.0
itypes 1.1.0
jedi 0.13.3
Jinja2 2.10
MarkupSafe 1.1.1
mccabe 0.6.1
more-itertools 6.0.0
oauthlib 3.0.1
packaging 19.0
parso 0.3.4
pexpect 4.6.0
pickleshare 0.7.5
Pillow 5.2.0
pip 19.0.3
pluggy 0.6.0
prompt-toolkit 2.0.9
psycopg2 2.7.4
ptyprocess 0.6.0
py 1.8.0
pycodestyle 2.3.1
pycparser 2.19
pyflakes 1.6.0
Pygments 2.3.1
pyparsing 2.3.1
pytest 3.6.3
pytest-django 3.3.2
pytest-sugar 0.9.1
python-dateutil 2.8.0
python-slugify 1.2.5
python3-openid 3.1.0
pytz 2018.5
redis 3.2.1
requests 2.21.0
requests-oauthlib 1.2.0
setuptools 40.8.0
six 1.12.0
snowballstemmer 1.2.1
Sphinx 1.7.5
sphinxcontrib-websupport 1.1.0
sqlparse 0.3.0
termcolor 1.1.0
text-unidecode 1.2
traitlets 4.3.2
Unidecode 1.0.23
uritemplate 3.0.0
urllib3 1.24.1
wcwidth 0.1.7
Werkzeug 0.14.1
wheel 0.33.1
Any help is highly appreciated! 任何帮助深表感谢! Thanks... 谢谢...
docker-compose run
starts a new container and executes the command in it. docker-compose run
启动一个新容器并在其中执行命令。 When used with --rm
flag the container gets removed after command completes. 与--rm
标志一起使用时,命令完成后将删除容器。
What happens is you get a new container created, and packages installed, or pip upgraded, inside this container. 发生的事情是您在该容器中创建了一个新容器,并安装了软件包或升级了pip。 Once the command completes the container is removed. 命令完成后,将删除容器。
If later on you run something like docker-compose -f local.yml run --rm pip list
a brand new container will get created and pip list executed inside it, showing no packages from previous run since they were installed in a different container, which is already removed. 如果稍后再运行类似docker-compose -f local.yml run --rm pip list
的东西,则会创建一个全新的容器并在其中执行pip列表,这将显示以前运行的软件包,因为它们已安装在其他容器中,已被删除。
A better way would be to create docker image
that includes your application and install pip packages during docker build. 更好的方法是创建包含您的应用程序的docker image
,并在docker build期间安装pip软件包。 You can check a sample in this question 您可以在此问题中查看样本
This way any time you start a container from your image it will have all packages inside. 这样,每次从映像启动容器时,它将包含所有包。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.