简体   繁体   中英

PyInstaller cannot find libpython2.7.so when making binary?

I'm trying to make a binary version of a Python script using PyInstaller 2.0 on Linux. When I run:

$ python pyinstaller.py myscript.py

I get the error:

8907 INFO: Looking for Python library libpython2.7.so
Traceback (most recent call last):
...
  File "pyinstaller.py", line 91, in <module>
    raise IOError("Python library not found!")
IOError: Python library not found!

How can this be fixed?

I am using:

Linux #98-Ubuntu x86_64 GNU/Linux

With python 2.7. There are other Pythons on the system but I have it set that:

alias python="python2.7"

In the server I am using, there's only /usr/lib/python2.6 and not /usr/lib/python2.7 but python 2.7 is used routinely by me and is functional, etc. so I don't see it why it would be a problem to find its libraries. There is a /usr/local/lib/libpython2.7.a .

In the server I am using, there's only /usr/lib/python2.6 and not /usr/lib/python2.7 but python 2.7 is used routinely by me and is functional, etc. so I don't see it why it would be a problem to find its libraries. There is a /usr/local/lib/libpython2.7.a.

If there is no libpython2.7.so , of course it will be a problem to find that library.

The reason you're able to use the Python interpreter is probably that it's statically linked.

There are two ways to solve this.

First, you could just install the shared libraries for your Python 2.7. If you're using an older version of Ubuntu that came with, say, Python 2.6, and you installed 2.7 from the python2.7 package, this should just be a matter of installing libpython2.7 .

If you've gotten your 2.7 from some other source, the Ubuntu libpython2.7 package obviously won't work—or it'll work by installing a second copy of python2.7 , possibly overwriting some of the files you already have, and definitely confusing you. Either way, don't do it. Either get the rest of Python for your existing 2.7, or uninstall that 2.7 and use the Ubuntu packages. (For some Python distributions, "get the rest of it" is impossible, because if you install the shared libs, you get a dynamically-linked Python executable instead of your statically-linked one. In that case, you pretty much have to uninstall and reinstall.)

Second, you could use PyInstaller 's static-lib support. See ticket 420 for details, but the simple idea is that, if this is enabled, and PyInstaller thinks your platform should have a libpython2.7.so but can't find it, it will look for a libpython2.7.a and statically link that instead. Last time I needed this, it wasn't checked into trunk. From a quick glance at the ticket, it looks like the patch is now included, but disabled in default PyInstaller builds, and the milestone is set to 3.0, so, you may still have to manually build PyInstaller to get this to work.

One last thing: It's possible that you do have libpython2.7.so, but it's just installed somewhere weird like /opt/python27/lib or something, with /opt/python27 nowhere on your path, but /usr/local/bin/python27 can find it because it's explicitly built to get stuff out of /opt/python27 . This kind of thing tends to be a problem only for Mac users with MacPorts or Fink, not Linux users, but it's not impossible. You can look at the dl table for /usr/local/bin/python27 if you think this might be the issue.

There are 2 options: libpython*.so exists or doesn't exists on your system. You can check it by any find utility starting from root directory. In case the file already exists but still can't be found by PyInstaller: the most generic advice is just to open PyInstaller code and find the module that responsible to find this library. It can be done with simple editor. Than go to this module and edit him to understand what is wrong with your specific system. The code is simple and premature - it will take you ~ 5 minutes to understand the reason. In my case I just added LD_LIBRARY_PATH=/usr/local/lib to my user profile (.bash_profile) and ensured that this *.so file is inside. In case the file isn't on your system or you have incorrect version: just reinstall the python.

As @abarnert already said, the problem seems to be a static compilation of python. To solve this issue is needed to recompile python but adding the flag --enable-shared this time:

    [root@machine ~]# ./configure --prefix=/usr/local --enable-shared
    [root@machine ~]# make && make altinstall

Once you do this, you'll find the requested library ( libpython2.7.so.1.0 ) under /usr/local/lib path so don't forget to add that folder to the $LD_LIBRARY_PATH environment variable:

    [root@machine tmp]$ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM