修复ImportError:无法在ARM的Docker容器(基于arm32v7 / python)中运行的python 3.5中导入名称'TestCase'

时间:2019-03-29 11:45:13

标签: python docker arm

我正在尝试在Nitrogen6x主板(ARMv7架构)上的docker容器中运行tensorflow。 我使用以下dockerfile安装python 3.5和tensorflow的一些依赖项(从prebulit滚轮):

FROM arm32v7/python:3.5.7-stretch

RUN apt-get update && \
 apt-get -y install openjdk-8-jdk automake autoconf && \
 apt-get -y install curl zip unzip libtool swig libpng-dev zlib1g-dev pkg-config git g++ wget xz-utils

RUN curl https://bootstrap.pypa.io/get-pip.py | python3; exit 0 && curl https://bootstrap.pypa.io/get-pip.py | python3
RUN pip3 install --extra-index-url=https://www.piwheels.org/simple --user keras_applications==1.0.7 --no-deps
RUN pip3 install --extra-index-url=https://www.piwheels.org/simple --user keras_preprocessing --no-deps
RUN pip3 install --extra-index-url=https://www.piwheels.org/simple --upgrade --force-reinstall --no-deps setuptools; exit 0 && pip3 install --extra-index-url=https://www.piwheels.org/simple --upgrade --force-reinstall --no-deps setuptools
RUN pip3 install --extra-index-url=https://www.piwheels.org/simple --upgrade --force-reinstall --no-deps wheel; exit 0 && pip3 install --extra-index-url=https://www.piwheels.org/simple --upgrade --force-reinstall --no-deps wheel

COPY files /opt/tensorflow

RUN apt-get -y install libhdf5-serial-dev libhdf5-dev
RUN pip install h5py

RUN cd /opt/tensorflow \
 && pip install tensorflow-1.13.1-cp35-none-linux_armv7l.whl

CMD ["/bin/sh"]

一些信息说明为什么要在Dockerfile中执行我的操作: 由于一个已知的pip错误导致以下错误消息

Traceback (most recent call last):
  File "/usr/local/bin/pip3", line 6, in <module>
    from pip._internal import main
ImportError: cannot import name 'main'

我需要使用https://bootstrap.pypa.io/get-pip.py提供的点子版本。 此外,我需要重新安装setuptools和wheel,因为否则会出现以下错误:

Collecting h5py
  Downloading https://files.pythonhosted.org/packages/43/27/a6e7dcb8ae20a4dbf3725321058923fec262b6f7835179d78ccc8d98deec/h5py-2.9.0.tar.gz (287kB)
    Complete output from command python setup.py egg_info:
    /usr/local/lib/python3.5/distutils/dist.py:261: UserWarning: Unknown distribution option: 'setup_requires'
      warnings.warn(msg)
    /usr/local/lib/python3.5/distutils/dist.py:261: UserWarning: Unknown distribution option: 'install_requires'
      warnings.warn(msg)
    usage: -c [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
       or: -c --help [cmd1 cmd2 ...]
       or: -c --help-commands
       or: -c cmd --help

    error: invalid command 'egg_info'

每次我尝试重新安装软件包时,都会收到与以下错误类似的错误:

Could not install packages due to an EnvironmentError: [Errno 2] No such file or directory: '/tmp/pip-uninstall-xri7_n6a/easy_install.py'

因此,我运行了两次reinstall命令。


使用给定的Dockerfile,我可以构建docker容器,但是由于以下错误,我无法导入某些python模块:

Python 3.5.7 (default, Mar 20 2019, 12:13:45)
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import keras_preprocessing
>>> import keras_applications
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/root/.local/lib/python3.5/site-packages/keras_applications/__init__.py", line 98, in <module>
    from . import vgg16
  File "/root/.local/lib/python3.5/site-packages/keras_applications/vgg16.py", line 16, in <module>
    from . import imagenet_utils
  File "/root/.local/lib/python3.5/site-packages/keras_applications/imagenet_utils.py", line 9, in <module>
    import numpy as np
  File "/usr/local/lib/python3.5/site-packages/numpy/__init__.py", line 187, in <module>
    from .testing import Tester
  File "/usr/local/lib/python3.5/site-packages/numpy/testing/__init__.py", line 10, in <module>
    from unittest import TestCase
ImportError: cannot import name 'TestCase'
>>>

是否有任何解决方法/如何解决此错误的想法。 预先感谢。

0 个答案:

没有答案