在 python docker 图像上安装 simstring (SWIG)
installing simstring (SWIG) on python docker image
我正在尝试在 python docker 映像上安装 C++ 程序包 simstring(python:最新或 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 左右,但我无法找到 link 的文件,也无法锻炼如何 link 它们。有任何想法吗? (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 docker 映像上安装 C++ 程序包 simstring(python:最新或 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 左右,但我无法找到 link 的文件,也无法锻炼如何 link 它们。有任何想法吗? (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