2

I have python installed in Linux

$ which python
/grid/common/pkgs/python/v2.7.6/bin/python

and I also have pyinstaller

$ which pyinstaller
/grid/common/pkgs/python/v2.7.6/bin/pyinstaller

Now I have created a sample python file hello.py in /home/username/test/ directory

print "Hello World!!"

Using pyinstaller, when I am trying to create an executable for it using the following command, I am getting

IOError: Python library not found: 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)

Please anyone tell me how to resolve this error and create a single executable using it.

Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
孔祥瑞
  • 21
  • 1
  • 3

1 Answers1

0

You seem to have a non-standard python installation:

I have python installed in Linux

$ which python 
/grid/common/pkgs/python/v2.7.6/bin/python

That probably causes pyinstaller to fail to find the libpython files from your system. From the When Things Go Wrong section of the pyinstaller docs:

One of these errors can be puzzling, however: IOError("Python library not found!") PyInstaller needs to bundle the Python library, which is the main part of the Python interpreter, linked as a dynamic load library. The name and location of this file varies depending on the platform in use.

On Linux and for Python 2.7, when you install python2.7-dev, those libpython* files are normally found under /usr/lib/x86_64-linux-gnu/:

$ 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

On my machine, when I ran pyinstaller without setting any other options, it does automatically used the libpython from /usr/lib/x86_64-linux-gnu:

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 

For your case with a non-standard path, that same help page also offers a solution:

The places where PyInstaller looks for the python library are different in different operating systems, but /lib and /usr/lib are checked in most systems. If you cannot put the python library there, try setting the correct path in the environment variable LD_LIBRARY_PATH in Linux or DYLD_LIBRARY_PATH in OS X.

Now, I don't know how you installed Python on your system, so I don't know where your libpython files are (or if they even exist at all). What you can do is:

  1. Find the path to the libpython files
    • Maybe it's under /grid/common/pkgs/python/v2.7.6/lib ?
    • You can do find /path/to/pkgs -name libpython*
  2. If there are no libpython files, you need to install it first.
    • On Linux, this is normally done by apt-get install python2.7-dev
  3. Add the path to the libpython* files to your LD_LIBRARY_PATH

On a sidenote, I am not familiar with Azure DevOps (as you indicated in your title), but I do NOT recommend installing python (and all other deps/packages) to some non-standard paths, especially when you require other tools that refer to it.

Gino Mempin
  • 25,369
  • 29
  • 96
  • 135