Docker python2.7错误:ImportError:无法导入名称_remove_dead_weakref

时间:2018-02-01 02:40:39

标签: python python-2.7 docker

我有一个运行python应用程序的简单Dockerfile

FROM python:2.7

RUN addgroup eugene && useradd -u 52712 -g eugene -ms /bin/bash eugene

RUN mkdir /data && chown eugene:eugene /data
VOLUME /data
WORKDIR /workspace

# where bedrock code will be
ADD . /data

# Install any needed packages specified in requirements.txt
RUN pip install --trusted-host repoproxy-rtp.eng.netapp.com --index-url http://repoproxy-rtp.eng.netapp.com:8081/artifactory/api/pypi/python-package-index/simple -r /data/requirements.txt

USER eugene
# Run app.py when the cotainer launches
CMD ["python", "/data/app.py"]

似乎无法导入multiprocessing.py?

Traceback (most recent call last):
  File "/data/app.py", line 13, in <module>
    import multiprocessing
  File "/usr/local/lib/python2.7/multiprocessing/__init__.py", line 65, in <module>
    from multiprocessing.util import SUBDEBUG, SUBWARNING
  File "/usr/local/lib/python2.7/multiprocessing/util.py", line 37, in <module>
    import weakref
  File "/usr/local/lib/python2.7/weakref.py", line 14, in <module>
    from _weakref import (
ImportError: cannot import name _remove_dead_weakref

知道如何解决这个问题吗?我在容器外运行app.py没有问题

1 个答案:

答案 0 :(得分:0)

我遇到了同样的问题,但仍在寻找有效的解决方案。但是目前,我发现了一些使其可行的提示:

默认情况下,Docker内部的环境无法使用python命令。因此,我们可以采用这种方式(在我的情况下有效):

In [3545]: (df.loc[df.groupby('Cat')['Range'].idxmax(), 'Val'] = 
            df.groupby('Cat')['Val'].transform('min'))

In [3546]: df
Out[3546]: 
    Cat  Range  Val
0     1      0  1.0
2     1      2  1.5
3     1      3  2.0
5     1      5  1.0
6     2      0  1.5
7     2      5  2.0
8     2     10  0.5
9     2     15  2.8
10    2     20  0.5

我从这里得到的这个提示的想法是: https://github.com/sclorg/s2i-python-container/issues/345

P.S。我仍在尝试寻找一种方法来“打开:Dockerfile中的python ...