我在Linux中安装了python
$ which python
/grid/common/pkgs/python/v2.7.6/bin/python
我也有pyinstaller
$ which pyinstaller
/grid/common/pkgs/python/v2.7.6/bin/pyinstaller
现在,我在/ home / username / test /目录中创建了一个示例python文件hello.py
print "Hello World!!"
使用pyinstaller,当我尝试使用以下命令为其创建可执行文件时,我得到了
IOError:找不到Python库:libpython2.7mu.so.1.0, libpython2.7.so.1.0,libpython2.7m.so.1.0
$ pyinstaller hello.py
532 INFO: PyInstaller: 3.2.1
532 INFO: Python: 2.7.6
534 INFO: Platform: Linux-2.6.18-371.el5-x86_64-with-redhat-5.10-Tikanga
536 INFO: wrote /home/username/test/hello.spec
591 INFO: UPX is not available.
602 INFO: Extending PYTHONPATH with paths
['/home/username/test', '/home/username/test']
602 INFO: checking Analysis
602 INFO: Building Analysis because out00-Analysis.toc is non existent
603 INFO: Initializing module dependency graph...
639 INFO: Initializing module graph hooks...
757 INFO: running Analysis out00-Analysis.toc
819 INFO: Caching module hooks...
858 INFO: Analyzing /home/username/test/hello.py
859 INFO: Loading module hooks...
860 INFO: Loading module hook "hook-encodings.py"...
6735 INFO: Looking for ctypes DLLs
6736 INFO: Analyzing run-time hooks ...
6741 INFO: Looking for dynamic libraries
7285 INFO: Looking for eggs
7286 INFO: Python library not in binary depedencies. Doing additional searching...
Traceback (most recent call last):
File "/grid/common/pkgs/python/v2.7.6/bin/pyinstaller", line 9, in <module>
load_entry_point('PyInstaller==3.2.1', 'console_scripts', 'pyinstaller')()
File "/grid/common/pkgs/python/v2.7.6/lib/python2.7/site-
packages/PyInstaller-3.2.1-py2.7.egg/PyInstaller/__main__.py", line 90, in run
run_build(pyi_config, spec_file, **vars(args))
File "/grid/common/pkgs/python/v2.7.6/lib/python2.7/site-
packages/PyInstaller-3.2.1-py2.7.egg/PyInstaller/__main__.py", line 46, in
run_build PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
File "/grid/common/pkgs/python/v2.7.6/lib/python2.7/site-
packages/PyInstaller-3.2.1-py2.7.egg/PyInstaller/building/build_main.py",
line 788, in main
build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
File "/grid/common/pkgs/python/v2.7.6/lib/python2.7/site-
packages/PyInstaller-3.2.1-py2.7.egg/PyInstaller/building/build_main.py",
line 734, in build
exec(text, spec_namespace)
File "<string>", line 16, in <module>
File "/grid/common/pkgs/python/v2.7.6/lib/python2.7/site-
packages/PyInstaller-3.2.1-py2.7.egg/PyInstaller/building/build_main.py",
line 212, in __init__
self.__postinit__()
File "/grid/common/pkgs/python/v2.7.6/lib/python2.7/site-
packages/PyInstaller-3.2.1-py2.7.egg/PyInstaller/building/datastruct.py",
line 161, in __postinit__
self.assemble()
File "/grid/common/pkgs/python/v2.7.6/lib/python2.7/site-
packages/PyInstaller-3.2.1-py2.7.egg/PyInstaller/building/build_main.py",
line 543, in assemble
self._check_python_library(self.binaries)
File "/grid/common/pkgs/python/v2.7.6/lib/python2.7/site-
packages/PyInstaller-3.2.1-py2.7.egg/PyInstaller/building/build_main.py",
line 626, in _check_python_library
raise IOError(msg)
IOError: Python library not found: libpython2.7mu.so.1.0, libpython2.7.so.1.0, libpython2.7m.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)
请任何人告诉我如何解决此错误并使用该错误创建一个可执行文件。
答案 0 :(得分:0)
您似乎安装了非标准的python
:
我在Linux中安装了python
$ which python /grid/common/pkgs/python/v2.7.6/bin/python
这可能导致pyinstaller
无法从您的系统中找到libpython
文件。在pyinstaller
文档的When Things Go Wrong部分中:
这些错误之一可能令人困惑,但是:
IOError("Python library not found!")
PyInstaller需要捆绑Python库,该库是 Python解释器的主要部分,链接为动态负载 图书馆。该文件的名称和位置取决于 平台正在使用中。
在Linux和Python 2.7上,当您安装python2.7-dev
时,这些libpython*
文件通常在 / usr / lib / x86_64-linux-gnu / 下找到:< / p>
$ apt-get install python2.7-dev
$ find /usr/lib -name libpython*
/usr/lib/python2.7/config-x86_64-linux-gnu/libpython2.7-pic.a
/usr/lib/python2.7/config-x86_64-linux-gnu/libpython2.7.a
/usr/lib/python2.7/config-x86_64-linux-gnu/libpython2.7.so
/usr/lib/x86_64-linux-gnu/libpython2.7.a
/usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0
/usr/lib/x86_64-linux-gnu/libpython2.7.so.1
/usr/lib/x86_64-linux-gnu/libpython2.7.so
在我的机器上,当我运行pyinstaller
而未设置任何其他选项时,它会自动使用 / usr / lib / x86_64-linux-gnu 中的libpython
:
1632 INFO: Python library not in binary dependencies. Doing additional searching...
1654 INFO: Using Python library /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0
对于您使用非标准路径的情况,该帮助页面也提供了解决方案:
PyInstaller查找python库的位置是 在不同的操作系统中有所不同,但是
/lib
和/usr/lib
是 在大多数系统中已检查。如果您无法在其中放置python库, 尝试在环境变量中设置正确的路径 在Linux中为LD_LIBRARY_PATH
,在OS X中为DYLD_LIBRARY_PATH
。
现在,我不知道您是如何在系统上安装Python的,所以不知道您的libpython
文件在哪里(或什至根本不存在)。您可以做的是:
libpython
文件的路径
find /path/to/pkgs -name libpython*
libpython
文件,则需要先安装。
apt-get install python2.7-dev
libpython*
文件的路径添加到LD_LIBRARY_PATH
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/path/to/dir/with/libpython
在旁注中,我不熟悉Azure DevOps(如标题中所述),但我不建议将python
(以及所有其他deps /程序包)安装到某些非标准路径,尤其是当您需要其他引用它的工具时。