CentOS7打包PyInstaller出现OSError问题解决方案

这篇博客主要讲述了在遇到Python运行时找不到库文件libpython3.7m.so.1.0的问题时,如何通过重新配置和安装Python来解决。作者指出在CentOS系统中不需要像Debian/Ubuntu那样安装python3-dev,并详细指导了使用`./configure --prefix=/usr/local/python3 --enable-shared`参数重新编译Python,以及后续的`ldconfig`配置步骤,以确保Python能正确找到共享库。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

先上报错情况


```powershell
OSError: Python library not found: libpython3.7m.so.1.0, libpython3.7mu.so.1.0, libpython3.7.so.1.0
This would mean your Python installation doesn't come with proper library files.
This usually happens by missing development package, or unsuitable build parameters of Python installation.

* On Debian/Ubuntu, you would need to install Python development packages
* apt-get install python3-dev
* apt-get install python-dev
* If you're building Python by yourself, please rebuild your Python with `--enable-shared` (or, `--enable-framework` on Darwin)
首先,centos下不需要python3-dev,因为压根没有,那个是Debian/Ubuntu下才有的,所以先不考虑,
然后看**OSError: Python library not found: libpython3.7m.so.1.0**找不到这个,这个是重点,一会要解决。再看这个提示--enable-shared,让我们安装的时候带上这个参数,因为安装python的时候,我没有加,所以,要重装Python,使用

`./configure --prefix=/usr/local/python3 --enable-shared`
然后`make && make install`就好了

现在再次打开python的时候,会报错,
~~ImportError: libpython3.7m.so.1.0: cannot open shared object file: No such file or directory~~ 
需要使用

```powershell

echo "/usr/local/python3/lib/" >> /etc/ld.so.conf
ldconfig 
```powershell
然后运行,ok,可以运行,打包也没问题了
新手发文,不太会排版,抱歉
Traceback (most recent call last): File "/usr/local/python3/bin/pyinstaller", line 8, in <module> sys.exit(_console_script_run()) File "/usr/local/python3/lib/python3.7/site-packages/PyInstaller/__main__.py", line 194, in _console_script_run run() File "/usr/local/python3/lib/python3.7/site-packages/PyInstaller/__main__.py", line 180, in run run_build(pyi_config, spec_file, **vars(args)) File "/usr/local/python3/lib/python3.7/site-packages/PyInstaller/__main__.py", line 61, in run_build PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs) File "/usr/local/python3/lib/python3.7/site-packages/PyInstaller/building/build_main.py", line 1019, in main build(specfile, distpath, workpath, clean_build) File "/usr/local/python3/lib/python3.7/site-packages/PyInstaller/building/build_main.py", line 944, in build exec(code, spec_namespace) File "/root/test/2.spec", line 20, in <module> noarchive=False, File "/usr/local/python3/lib/python3.7/site-packages/PyInstaller/building/build_main.py", line 429, in __init__ self.__postinit__() File "/usr/local/python3/lib/python3.7/site-packages/PyInstaller/building/datastruct.py", line 184, in __postinit__ self.assemble() File "/usr/local/python3/lib/python3.7/site-packages/PyInstaller/building/build_main.py", line 764, in assemble self._check_python_library(self.binaries) File "/usr/local/python3/lib/python3.7/site-packages/PyInstaller/building/build_main.py", line 834, in _check_python_library python_lib = bindepend.get_python_library_path() File "/usr/local/python3/lib/python3.7/site-packages/PyInstaller/depend/bindepend.py", line 1018, in get_python_library_path raise IOError(msg) OSError: Python library not found: libpython3.7mu.so.1.0, libpython3.7.so, libpython3.7m.so.1.0, libpython3.7m.so, libpython3.7.so.1.0 This means your Python installation does not come with proper shared library files. This usually happens due to missing development package, or unsuitable build parameters of the Python installation. * On Debian/Ubuntu, you need to install Python development packages: * apt-get install python3-dev * apt-get install python-dev * If you are building Python by yourself, rebuild with `--enable-shared` (or, `--enable-framework` on macOS).
07-13
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值