git - 如何在 Dockerfile 中本地安装 pip 包?

标签 git github docker pip

我尝试从 github 克隆一个 python 包,然后使用 pip -e 将其安装在本地,如下所示:

RUN git clone https://github.com/st4lk/django-rest-social-auth.git
RUN pip install -e django-rest-social-auth

但我收到错误消息:

Step 6 : RUN pip install -e django-rest-social-auth
 ---> Running in 8943e688573f
Traceback (most recent call last):
  File "/usr/bin/pip", line 9, in <module>
    load_entry_point('pip==1.5.6', 'console_scripts', 'pip')()
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 356, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 2476, in load_entry_point
    return ep.load()
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 2190, in load
    ['__name__'])
  File "/usr/lib/python2.7/dist-packages/pip/__init__.py", line 74, in <module>
    from pip.vcs import git, mercurial, subversion, bazaar  # noqa
  File "/usr/lib/python2.7/dist-packages/pip/vcs/mercurial.py", line 9, in <module>
    from pip.download import path_to_url
  File "/usr/lib/python2.7/dist-packages/pip/download.py", line 25, in <module>
    from requests.compat import IncompleteRead
ImportError: cannot import name IncompleteRead

出了什么问题?


完整的Dockerfile供引用:

FROM debian:jessie

ADD . /workflows

# Install dependencies

RUN apt-get update && apt-get install -y \
    git \
    python-django \
    python-psycopg2 \
    python-django-celery \
    rabbitmq-server \
    python-django-jsonfield \
    python-pip

RUN pip install djangorestframework \
    python-social-auth

RUN git clone https://github.com/st4lk/django-rest-social-auth.git

RUN pip install -e django-rest-social-auth

# Get everything ready and run

RUN python /workflows/manage.py validate
RUN python /workflows/manage.py collectstatic --noinput

CMD python /workflows/manage.py runserver 0.0.0.0:8000

最佳答案

IncompleteRead 名称已从 https://github.com/kennethreitz/requests/commit/47d0517d66e8cf5832768262221f0357ae134ad1 中的 requests.compat 中删除.

完成 Dockerfile 的这一部分后...

RUN apt-get update && apt-get install -y \
    git \
    python-django \
    python-psycopg2 \
    python-django-celery \
    rabbitmq-server \
    python-django-jsonfield \
    python-pip

您拥有 Requests 版本 2.4.3 和 pip 1.5.6。这两个都相当老了。当您下次运行 pip install...

RUN pip install djangorestframework \
    python-social-auth

...这会将您的 Requests 包升级到 2.9.1,该版本不再与镜像中安装的旧版本 pip 兼容。

您可以通过安装更新​​版本的pip来避免此问题。 无需安装 python-pip 包,只需使用 easy_install 获取pip:

RUN apt-get update && apt-get install -y \
    git \
    python-django \
    python-psycopg2 \
    python-django-celery \
    rabbitmq-server \
    python-django-jsonfield

RUN easy_install pip

这将安装最新版本的 pip,它将与后续 Python 模块安装所需的 Requests 版本一起成功运行。

关于git - 如何在 Dockerfile 中本地安装 pip 包?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36357611/

相关文章:

git - 如何在每次从 master pull 后将本地更改应用到 git repo 而无需推送到 master

svg - 是否可以通过shields.io 徽章从nuget.org 获取下载计数?

docker - 在 Linux 机器中启动 minikube 需要使用 Google Container Registry 进行身份验证,为什么?

docker - 将Docker容器链接到另一个容器的子目录

git - "git push"和 "git push origin master"有什么区别?

docker - 在 .gitlab-ci.yml 中运行 docker-compose build

git - 如何将更改从一个分支推送到另一个分支?

git - 使用 gitolite 拒绝读取特定的存储库分支

git - 如何解除 git 文件夹的嵌套?

github - 如何使用 Github Actions 进行 SFTP?