17

I'm using Python 3.4.4 on Centos7.

I've created a python program on my local machine that makes use of qt modules. The program is running fine on my local machine. I'm now trying to create an executable with pyinstaller. I'm using the command:

pyinstaller main.py

I'm getting the following output:

40 INFO: PyInstaller: 3.2.1
40 INFO: Python: 3.4.4
41 INFO: Platform: Linux-3.10.0-327.36.3.el7.x86_64-x86_64-with-centos-7.3.1611-Core
41 INFO: wrote /home/neilharris/Documents/Python_Projects/transcoder/main.spec
42 INFO: UPX is not available.
44 INFO: Extending PYTHONPATH with paths
['/home/neilharris/Documents/Python_Projects/transcoder',
 '/home/neilharris/Documents/Python_Projects/transcoder']
44 INFO: checking Analysis
44 INFO: Building Analysis because out00-Analysis.toc is non existent
44 INFO: Initializing module dependency graph...
45 INFO: Initializing module graph hooks...
47 INFO: Analyzing base_library.zip ...
1869 INFO: Processing pre-find module path hook   distutils
3030 INFO: running Analysis out00-Analysis.toc
3039 INFO: Caching module hooks...
3046 INFO: Analyzing /home/neilharris/Documents/Python_Projects/transcoder/main.py
3089 INFO: Loading module hooks...
3089 INFO: Loading module hook "hook-xml.py"...
3353 INFO: Loading module hook "hook-encodings.py"...
3437 INFO: Loading module hook "hook-PyQt4.py"...
3438 INFO: Loading module hook "hook-distutils.py"...
3440 INFO: Loading module hook "hook-PyQt4.QtCore.py"...
3575 INFO: Loading module hook "hook-pydoc.py"...
3576 INFO: Loading module hook "hook-PyQt4.QtGui.py"...
3849 INFO: Looking for ctypes DLLs
3861 INFO: Analyzing run-time hooks ...
3867 INFO: Including run-time hook 'pyi_rth_qt4plugins.py'
3877 INFO: Looking for dynamic libraries
ldd: warning: you do not have execution permission for `/usr/local/lib/python3.4/site-packages/PyQt4/QtGui.so'
ldd: warning: you do not have execution permission for `/usr/local/lib/python3.4/site-packages/PyQt4/QtCore.so'
5115 INFO: Looking for eggs
5115 INFO: Python library not in binary depedencies. Doing additional searching...
Traceback (most recent call last):
  File "/usr/local/bin/pyinstaller", line 9, in <module>
    load_entry_point('PyInstaller==3.2.1', 'console_scripts', 'pyinstaller')()
  File "/usr/local/lib/python3.4/site-packages/PyInstaller/__main__.py", line 90, in run
    run_build(pyi_config, spec_file, **vars(args))
  File "/usr/local/lib/python3.4/site-packages/PyInstaller/__main__.py", line 46, in run_build
    PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
  File "/usr/local/lib/python3.4/site-packages/PyInstaller/building/build_main.py", line 788, in main
    build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
  File "/usr/local/lib/python3.4/site-packages/PyInstaller/building/build_main.py", line 734, in build
    exec(text, spec_namespace)
  File "<string>", line 16, in <module>
  File "/usr/local/lib/python3.4/site-packages/PyInstaller/building/build_main.py", line 212, in __init__
    self.__postinit__()
  File "/usr/local/lib/python3.4/site-packages/PyInstaller/building/datastruct.py", line 161, in __postinit__
    self.assemble()
  File "/usr/local/lib/python3.4/site-packages/PyInstaller/building/build_main.py", line 543, in assemble
    self._check_python_library(self.binaries)
  File "/usr/local/lib/python3.4/site-packages/PyInstaller/building/build_main.py", line 626, in _check_python_library
    raise IOError(msg)
OSError: Python library not found: libpython3.4m.so.1.0, libpython3.4mu.so.1.0, libpython3.4.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)

Does anyone know what the issue could be? Just to say I have python3-devel and python-devel installed (in relation to the suggestion at the end of the printed output.) Thanks

neilH
  • 3,320
  • 1
  • 17
  • 38

6 Answers6

16

for Linux system like your CentOS, try rebuild python to generated shared lib using:

env PYTHON_CONFIGURE_OPTS="--enable-shared" pyenv install 3.4.4

as said in pyenv offical doc

crifan
  • 12,947
  • 1
  • 71
  • 56
6

You must install python-dev for your python's version

for example:

Debian/Ubuntu - Python 2.7 ---> python2.7-dev

CentOs/RedHat - Python 3.4 ---> python34-devel

CentOs/RedHat - Python 2.7 ---> python27-devel

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. Some Python installations do not include a dynamic Python library by default (a static-linked one may be present but cannot be used). You may need to install a development package of some kind. Or, the library may exist but is not in a folder where PyInstaller is searching.

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.

Reference

RaminNietzsche
  • 2,683
  • 1
  • 20
  • 34
  • 1
    Hello,thanks for your response. This hasn't worked, I've added the path of my python3.4 library (/usr/local/lib/) to LD_LIBRARY_PATH. I've also tried copying this library to /usr/lib. I'm getting the same errors though. – neilH Mar 28 '17 at 11:16
  • 1
    please see http://stackoverflow.com/questions/7880454/python-executable-not-finding-libpython-shared-library and https://github.com/pyenv/pyenv/wiki/Home/_compare/45570ea%5E...45570ea – RaminNietzsche Mar 28 '17 at 12:13
  • I've performed a find command on my PC for files libpython3.4m.so.1.0, libpython3.4mu.so.1.0 and libpython3.4.so.1.0 and nothing has shown up. I'm guessing this might be the issue? Not sure how to resolve though – neilH Mar 28 '17 at 13:17
  • search libpython3.4m.so and if you can find it, make a link. – RaminNietzsche Mar 28 '17 at 13:22
  • ok, i've found the answer! I need to install python34-devel which I managed through yum. – neilH Mar 28 '17 at 13:31
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/139254/discussion-between-raminnietzsche-and-bms9nmh). – RaminNietzsche Mar 28 '17 at 13:39
2

I have solved this in the way below:

  1. check your system if it has libpython3.4m.so.1.0.

    • If yes, go to step 2.
    • If no, download it (I'm using anaconda python, so I have it in anaconda folder.)
  2. sudo cp /folder/to/your/libpython3.4m.so.1.0 /usr/lib

Neuron
  • 5,141
  • 5
  • 38
  • 59
  • Works like charm. Note there is an open [issue](https://github.com/pyinstaller/pyinstaller/issues/3885) on github regarding it. If anyone want to speed up things please post a like or comment on the [relevant place](https://github.com/pyinstaller/pyinstaller/issues/3885). – Geeocode Jan 31 '19 at 13:04
0

For developers who may face this issue, easily use conda virtual environments, by this you can specify the exact python version you need and there are not any concerns about libs! just install conda and create a new virtual environment with this command: conda create -n your_env_name python=needed_python_version(e.g.3.7.4)

Towhid Savari
  • 136
  • 1
  • 1
  • 7
0

Resolved this issue for Ubuntu 16.04 by running the following commands:

  1. sudo add-apt-repository ppa:deadsnakes/ppa
    • Please check if the above ppa is still valid, else add the latest ppa .
    • If you get the error "User or Item not added" it's probably a Firewall issue so contact your IT administrator to unblock the needed sites.
  2. sudo apt-get update
  3. sudo apt-get install python3.6
  4. sudo apt-get install python3.6-dev
  5. pip3 install pyinstaller
Neuron
  • 5,141
  • 5
  • 38
  • 59
pratibhamenon
  • 363
  • 2
  • 8
0

This error indicates that the Python "C binaries" cannot be found. These binaries are used to translate Python code into C code during compilation. Pyinstaller uses those files during compilation, and when it doesn't find them, that error is triggered.

By installing python and its dependency packages (such as python-devel) you may overcome that error. But this was not my case in RedHat operating systems. In my case, I had to manually resolve the dependency issues by finding all the "libpython" files and copying them to the /lib64 directory (being the directory where Pyinstaller looks during compilation)

find / -name libpython3* => 

  /opt/rh/rh-python38/root/usr/lib64/libpython3.8.so.rh-python38-1.0
  /opt/rh/rh-python38/root/usr/lib64/libpython3.so.rh-python38
  /opt/rh/rh-python38/root/usr/lib64/libpython3.8.so

cp -a /opt/rh/rh-python38/root/usr/lib64/libpython3.8.so.rh-python38-1.0 /lib64
cp -a /opt/rh/rh-python38/root/usr/lib64/libpython3.so.rh-python38 /lib64
cp -a /opt/rh/rh-python38/root/usr/lib64/libpython3.8.so /lib64

Execute again Pyinstaller command

Dorcioman
  • 499
  • 5
  • 6