1

我会尽量做到非常具体和翔实。为了地理空间/地理科学社区的利益,我想创建一个包含地球科学中使用的所有包的 Dockerfile。Dockerfile 建立在scipy-notebook docker- stack 之上。

问题:

我正在尝试构建 HPGL(地统计学的 Python 包)。

对于依赖项:我使用下载的 .deb 包构建了一些包apt-get,对于那些我无法安装的包。apt下面的 Dockerfile 显示了构建所有 HPGL 依赖项的步骤:

FROM jupyter/scipy-notebook

###
### HPGL - High Performance Geostatistics Library
###

USER root

RUN apt-get update && \
    apt-get install -y \ 
        gcc \
        g++ \
        libboost-all-dev

RUN apt-get update && \
    apt-get install -y \ 
        liblapack-dev \
        libblas-dev \
        liblapacke-dev

RUN apt-get update && \
    apt-get install -y \ 
        scons

RUN wget http://ftp.us.debian.org/debian/pool/main/libf/libf2c2/libf2c2_20090411-2_amd64.deb && \
    dpkg -i libf2c2_20090411-2_amd64.deb

RUN wget http://ftp.us.debian.org/debian/pool/main/libf/libf2c2/libf2c2-dev_20090411-2_amd64.deb && \
    dpkg -i libf2c2-dev_20090411-2_amd64.deb

RUN wget http://mirrors.kernel.org/ubuntu/pool/universe/c/clapack/libcblas3_3.2.1+dfsg-1_amd64.deb  && \
    dpkg -i libcblas3_3.2.1+dfsg-1_amd64.deb

RUN wget http://mirrors.kernel.org/ubuntu/pool/universe/c/clapack/libcblas-dev_3.2.1+dfsg-1_amd64.deb && \
    dpkg -i libcblas-dev_3.2.1+dfsg-1_amd64.deb

RUN wget http://ftp.us.debian.org/debian/pool/main/c/clapack/libclapack3_3.2.1+dfsg-1_amd64.deb  && \
    dpkg -i libclapack3_3.2.1+dfsg-1_amd64.deb

RUN wget http://ftp.us.debian.org/debian/pool/main/c/clapack/libclapack-dev_3.2.1+dfsg-1_amd64.deb && \
    dpkg -i libclapack-dev_3.2.1+dfsg-1_amd64.deb

RUN wget https://mirror.kku.ac.th/ubuntu/ubuntu/pool/main/l/lapack/libtmglib3_3.7.1-1_amd64.deb && \
    dpkg -i libtmglib3_3.7.1-1_amd64.deb

RUN wget http://ftp.us.debian.org/debian/pool/main/l/lapack/libtmglib-dev_3.7.1-1_amd64.deb && \
    dpkg -i libtmglib-dev_3.7.1-1_amd64.deb

RUN git clone https://github.com/hpgl/hpgl.git

RUN cd hpgl/src/ && \
    bash -c "source activate python2 && scons -j 2"

RUN cd hpgl/src/ && \
    bash -c "source activate python2 && python2 setup.py install"

RUN rm -rf hpgl \
    scons-2.5.0* \
    libf2c2_20090411-2_amd64.deb \
    libf2c2-dev_20090411-2_amd64.deb \
    libtmglib3_3.7.1-1_amd64.deb \
    libtmglib-dev_3.7.1-1_amd64.deb \
    libcblas3_3.2.1+dfsg-1_amd64.deb \
    libcblas-dev_3.2.1+dfsg-1_amd64.deb \
    libclapack3_3.2.1+dfsg-1_amd64.deb \
    libclapack-dev_3.2.1+dfsg-1_amd64.deb

USER $NB_USER

这运行顺利,我可以运行 Docker 容器并启动笔记本,但是当我在 Python 中导入 HPGL 时,我收到这个错误,我不知道发生了什么或如何解决这个问题:

---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
<ipython-input-1-604a7d0744ab> in <module>()
----> 1 import geo_bsd

/opt/conda/envs/python2/lib/python2.7/site-packages/HPGL_BSD-0.9.9-py2.7.egg/geo_bsd/__init__.py in <module>()
      2 
      3 
----> 4 from geo import *
      5 from sgs import sgs_simulation
      6 from sis import sis_simulation

/opt/conda/envs/python2/lib/python2.7/site-packages/HPGL_BSD-0.9.9-py2.7.egg/geo_bsd/geo.py in <module>()
      3 import ctypes as C
      4 
----> 5 from hpgl_wrap import _HPGL_SHAPE, _HPGL_CONT_MASKED_ARRAY, _HPGL_IND_MASKED_ARRAY, _HPGL_UBYTE_ARRAY, _HPGL_FLOAT_ARRAY, _HPGL_OK_PARAMS, _HPGL_SK_PARAMS, _HPGL_IK_PARAMS, _HPGL_MEDIAN_IK_PARAMS, __hpgl_cov_params_t, __hpgl_cockriging_m1_params_t, __hpgl_cockriging_m2_params_t, _hpgl_so
      6 from hpgl_wrap import hpgl_output_handler, hpgl_progress_handler
      7 

/opt/conda/envs/python2/lib/python2.7/site-packages/HPGL_BSD-0.9.9-py2.7.egg/geo_bsd/hpgl_wrap.py in <module>()
    144         _hpgl_so = NC.load_library('hpgl_d', __file__)
    145 else:
--> 146         _hpgl_so = NC.load_library('hpgl', __file__)
    147 
    148 _hpgl_so.hpgl_set_output_handler.restype = None

/opt/conda/envs/python2/lib/python2.7/site-packages/numpy/ctypeslib.pyc in load_library(libname, loader_path)
    148             if os.path.exists(libpath):
    149                 try:
--> 150                     return ctypes.cdll[libpath]
    151                 except OSError:
    152                     ## defective lib file

/opt/conda/envs/python2/lib/python2.7/ctypes/__init__.pyc in __getitem__(self, name)
    435 
    436     def __getitem__(self, name):
--> 437         return getattr(self, name)
    438 
    439     def LoadLibrary(self, name):

/opt/conda/envs/python2/lib/python2.7/ctypes/__init__.pyc in __getattr__(self, name)
    430         if name[0] == '_':
    431             raise AttributeError(name)
--> 432         dll = self._dlltype(name)
    433         setattr(self, name, dll)
    434         return dll

/opt/conda/envs/python2/lib/python2.7/ctypes/__init__.pyc in __init__(self, name, mode, handle, use_errno, use_last_error)
    360 
    361         if handle is None:
--> 362             self._handle = _dlopen(self._name, mode)
    363         else:
    364             self._handle = handle

OSError: /usr/lib/libf2c.so.2: undefined symbol: MAIN__

编辑1:

所以显然@Jean-François Fabre Here 指出了这个非常相似的问题!. 在那里,问题与文件有关,libf2c.so并按如下方式解决:

rm /usr/lib/libf2c.so && ln -s /usr/lib/libf2c.a /usr/lib/libf2c.so

@p929 在同一线程中解释了此解决方案:

它所做的实际上是删除动态库并为静态库创建别名。

现在,我知道我有同样的问题,但文件不同(/usr/lib/libf2c.so.2)。解决方案是“删除动态库并创建静态库的别名”。我用相同的静态库尝试过,/usr/lib/libf2c.a但没有成功。

4

2 回答 2

0

解决方案:

我终于通过在安装过程中将动态库更改为静态库来解决问题。HPGL 是使用scons 构建的。来自scons网站:

SCons 是一个开源软件构建工具 (...) 配置文件是 Python 脚本

所以我在调用构建 HPGL之前编辑了SConstruct文件。hpgl/srcscons

原始 SConstruct 文件来自hpgl/src

env = Environment(
    CPPDEFINES = cl_defines,
    CPPPATH = [ 
#       '/opt/boost_1_38_src/',
        'tnt_126',
        'geo_bsd/hpgl',
        'CLAPACK-3.1.1.1/INCLUDE' ],
    LIBS = ['stdc++', 'libgomp', 'pthread', 'lapack', 'f2c', 'tmglib', 'blas'],
    LIBPATH =  ['CLAPACK-3.1.1.1'], 
    )

我将列表 LIBS 更改为:

LIBS = ['stdc++', 'libgomp', 'pthread', 'lapack', File('/usr/lib/libf2c.a'), 'tmglib', 'blas'],

此解决方案由@BenG 在此线程中提出。

这种方式scons传递给g++我们想要的 libf2c 的静态库。部分构建:

g++ -o geo_bsd/_cvariogram.so -shared temp/release/geo_bsd/_cvariogram/ellipsoid.os temp/release/geo_bsd/_cvariogram/stack_layers.os temp/release/geo_bsd/_cvariogram/variograms.os -LCLAPACK-3.1.1.1 -lstdc++ -lgomp -lpthread -llapack /usr/lib/libf2c.a -ltmglib -lblas  
于 2017-07-29T23:27:17.440 回答
0

您是否尝试将 LIBS 中的名称从 'libf2c' 更改为 'f2c' ?

于 2017-07-30T22:14:13.470 回答