我正在尝试安装 C++ 包 simstring在 python docker 镜像上(python:latest 或 python:3.7)
我采取的步骤是按照存储库/我收集到的信息中的说明进行操作:
docker run -it python:latest /bin/bash
autoconf -i
apt-get install swig
git clone https://github.com/chokkan/simstring.git
cd simstring
./configure
cd swig/python
./prepare.sh --swig
python setup build_ext
这是我收到两个错误的地方:
/usr/bin/ld: cannot find -liconv
/usr/bin/ld: cannot find -lpython
不知何故,我需要将它们的位置传递给 build_ext 左右,但我找不到要链接的文件,也找不到如何链接它们。有任何想法吗? (不幸的是,Simstring-pure,python 包不是一个选项。)
更新
按照下面的优秀答案构建 docker 镜像后,我遇到了下一个障碍,看起来仍然找不到 iconv。顺便说一句,在 3.7 python 中,这甚至无法构建。但 3.8 就可以了。
docker run -it simstring
Python 3.8.0 (default, Oct 17 2019, 05:36:36)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import simstring
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/simstring.py", line 14, in swig_import_helper
return importlib.import_module(mname)
File "/usr/local/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 657, in _load_unlocked
File "<frozen importlib._bootstrap>", line 556, in module_from_spec
File "<frozen importlib._bootstrap_external>", line 1101, in create_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
ImportError: libiconv.so.2: cannot open shared object file: No such file or directory
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.8/site-packages/simstring.py", line 17, in <module>
_simstring = swig_import_helper()
File "/usr/local/lib/python3.8/site-packages/simstring.py", line 16, in swig_import_helper
return importlib.import_module('_simstring')
File "/usr/local/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
ImportError: libiconv.so.2: cannot open shared object file: No such file or directory
最佳答案
你可以使用这个 Dockerfile:
FROM python:3.8
RUN wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.16.tar.gz \
&& tar -xvzf libiconv-1.16.tar.gz \
&& cd libiconv-1.16 \
&& ./configure --prefix=/usr/local/lib \
&& make \
&& make install \
&& cd /usr/local/lib \
&& ln -s lib/libiconv.so libiconv.so \
&& ln -s libpython3.8.so.1.0 libpython.so \
&& ln -s lib/libiconv.so.2 libiconv.so.2
RUN apt-get update && apt-get install -y swig vim
RUN git clone https://github.com/chokkan/simstring.git
RUN cd simstring \
&& autoreconf -i \
&& ./configure \
&& cd swig/python \
&& ./prepare.sh --swig \
&& python setup.py build_ext \
&& python setup.py install
最后结果:
byte-compiling /usr/local/lib/python3.8/site-packages/simstring.py to simstring.cpython-38.pyc
running install_egg_info
Writing /usr/local/lib/python3.8/site-packages/simstring-1.1-py3.8.egg-info
关于python - 在 python docker 镜像上安装 simstring (SWIG),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58833290/