我正在一个docker环境中运行一个Cookiecutter django项目,我想通过pip添加新的包。具体地说,我想添加:djangorestframework-jwt
当我这样做的时候:docker-compose -f local.yml run --rm django pip install,因为我得到:Successfully installed PyJWT-1.7.1 djangorestframework-jwt-1.11.0,所以它看起来会完美地工作。
现在的问题是它没有安装它。它在我运行pip freeze时不会出现,在pip list中也不会出现
然后,我尝试将其放入我的requirements.txt文件中,并使用以下命令运行它:docker-compose -f local.yml run --rm django pip install -r requirements/base.txt
同样的结果。它显示它已成功安装,但并未成功。我认为这可能是我的django版本和软件包的问题,但当我试图更新我的pip时,同样的情况也会发生。它说它更新了,但是当我运行pip install -upgrade pip时,我再次得到:You should consider upgrading via the 'pip install --upgrade pip' command.
我别无选择了。
我的要求:
-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-jwtpip 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 任何帮助都是非常感谢的!谢谢..。
发布于 2019-05-03 02:55:21
docker-compose run启动一个新容器并执行其中的命令。当与--rm标志一起使用时,容器在命令完成后被删除。
发生的情况是您创建了一个新的容器,并在该容器中安装了包或pip升级。一旦命令完成,容器就会被移除。
如果稍后运行类似docker-compose -f local.yml run --rm pip list的程序,将创建一个全新的容器,并在其中执行pip list,其中不会显示以前运行的包,因为它们安装在另一个容器中,而该容器已经被删除。
更好的方法是创建包含您的应用程序的docker image,并在docker构建过程中安装pip包。您可以在this question中检查样本
这样,无论何时从映像启动一个容器,它都会包含所有的包。
https://stackoverflow.com/questions/55958077
复制相似问题