pip 安装python-iptables报错 /bin/ld: cannot find -lpython3.6m
报错日志
# pip3 install --upgrade python-iptables
WARNING: Running pip install with root privileges is generally not a good idea. Try `pip3 install --user` instead.
Collecting python-iptables
Using cached https://files.pythonhosted.org/packages/35/e4/33e639b9e153c2d798d73342a96715a4edca6f46431d763b275a34b3aeca/python-iptables-1.0.1.tar.gz
Installing collected packages: python-iptables
Running setup.py install for python-iptables ... error
Complete output from command /usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-2qvrmx9k/python-iptables/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-mym_dl_9-record/install-record.txt --single-version-externally-managed --compile:
running install
running build
running build_py
creating build
creating build/lib.linux-x86_64-3.6
creating build/lib.linux-x86_64-3.6/iptc
copying iptc/__init__.py -> build/lib.linux-x86_64-3.6/iptc
copying iptc/easy.py -> build/lib.linux-x86_64-3.6/iptc
copying iptc/errors.py -> build/lib.linux-x86_64-3.6/iptc
copying iptc/ip4tc.py -> build/lib.linux-x86_64-3.6/iptc
copying iptc/ip6tc.py -> build/lib.linux-x86_64-3.6/iptc
copying iptc/util.py -> build/lib.linux-x86_64-3.6/iptc
copying iptc/version.py -> build/lib.linux-x86_64-3.6/iptc
copying iptc/xtables.py -> build/lib.linux-x86_64-3.6/iptc
running build_ext
building 'libxtwrapper' extension
creating build/temp.linux-x86_64-3.6
creating build/temp.linux-x86_64-3.6/libxtwrapper
gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -I/usr/include/python3.6m -c libxtwrapper/wrapper.c -o build/temp.linux-x86_64-3.6/libxtwrapper/wrapper.o
gcc -pthread -shared -Wl,-z,relro -g build/temp.linux-x86_64-3.6/libxtwrapper/wrapper.o -L/usr/lib64 -lpython3.6m -o build/lib.linux-x86_64-3.6/libxtwrapper.cpython-36m-x86_64-linux-gnu.so
/bin/ld: cannot find -lpython3.6m
collect2: error: ld returned 1 exit status
error: command 'gcc' failed with exit status 1
解决办法
可以看到引用动态链接库 /usr/lib64/python3.6m
失败,查看/usr/lib64/
发现有一个/usr/lib64/libpython3.6m.so.1.0
# ll /usr/lib64/libpython3.6m*
-rwxr-xr-x. 1 root root 3144192 Nov 17 2020 /usr/lib64/libpython3.6m.so.1.0
设置软连接
# ln -s /usr/lib64/libpython3.6m.so.1.0 /usr/lib64/libpython3.6m
再次安装成功
# pip3 install --upgrade python-iptables
WARNING: Running pip install with root privileges is generally not a good idea. Try `pip3 install --user` instead.
Collecting python-iptables
Using cached https://files.pythonhosted.org/packages/35/e4/33e639b9e153c2d798d73342a96715a4edca6f46431d763b275a34b3aeca/python-iptables-1.0.1.tar.gz
Installing collected packages: python-iptables
Running setup.py install for python-iptables ... done
Successfully installed python-iptables-1.0.1