问题
I am using Debian 9, python 3.7.3 and cx_Freeze 6.0b1. I spent some time installing cx_Freeze on Windows 7 and Debian, I managed to compile the script on both platforms.
When I share it, the Windows version runs, but the Linux version raises an error about missing dependencies. The app is still looking for the files in the absolute path, and I don't understand why.
When I run cx_Freeze, the .so
file are copied to the output directory.
My compiled program:
import numpy as np
import matplotlib.pyplot as plt
f=open('hello.txt','w')
f.write('Hello World')
f.close()
y=lambda x:np.sqrt(x)
x=range(10)
plt.plot(x,y(x))
plt.show()
My setup.py
program:
from cx_Freeze import setup, Executable
exclude = []
executables = [
Executable('hello.py', base=None, targetName='Hello')]
includes=["encodings"]
include_files=[]
includes=[]
packages=["numpy","matplotlib"]
setup(
name = "Hello",
version = "1 ",
description = "Hello World",
options = {'build_exe':{"packages":packages, "include_files":include_files,'excludes':exclude,'includes':includes}},
executables = executables
)
Error while trying to execute the app on a second computer:
Traceback (most recent call last):
File "/home/ansart/anaconda3/lib/python3.7/site-packages/cx_Freeze/initscripts/__startup__.py", line 14, in run
File "/home/ansart/anaconda3/lib/python3.7/site-packages/cx_Freeze/initscripts/Console.py", line 26, in run
File "hello.py", line 1, in <module>
File "/home/ansart/anaconda3/lib/python3.7/site-packages/numpy/__init__.py", line 140, in <module>
File "/home/ansart/anaconda3/lib/python3.7/site-packages/numpy/_distributor_init.py", line 34, in <module>
ImportError: libmkl_rt.so: cannot open shared object file: No such file or directory
Error while trying to execute the app on a third computer:
Traceback (most recent call last):
File "/home/ansart/anaconda3/lib/python3.7/site-packages/cx_Freeze/initscripts/__startup__.py", line 14, in run
File "/home/ansart/anaconda3/lib/python3.7/site-packages/cx_Freeze/initscripts/Console.py", line 26, in run
File "hello.py", line 1, in <module>
File "/home/ansart/anaconda3/lib/python3.7/site-packages/numpy/__init__.py", line 140, in <module>
File "/home/ansart/anaconda3/lib/python3.7/site-packages/numpy/_distributor_init.py", line 33, in <module>
File "/home/ansart/anaconda3/lib/python3.7/site-packages/numpy/_distributor_init.py", line 18, in __enter__
File "/home/ansart/anaconda3/lib/python3.7/ctypes/__init__.py", line 7, in <module>
ImportError: libffi.so.6: cannot open shared object file: No such file or directory
List of files in the directory:
total 97649
-rwxrwxrwx 1 vansart 197121 3464464 juin 11 14:55 Hello
-rwxrwxrwx 1 vansart 197121 11 juin 11 17:28 hello.txt
drwxrwxrwx 1 vansart 197121 0 juin 12 08:33 imageformats/
drwxrwxrwx 1 vansart 197121 0 juin 12 08:33 lib/
-rwxrwxrwx 1 vansart 197121 840264 janv. 17 21:31 libblosc.so.1
-rwxrwxrwx 1 vansart 197121 3452736 juin 7 16:48 libcrypto.so.1.1
-rwxrwxrwx 1 vansart 197121 409720 juin 7 16:48 libdbus-1.so.3
-rwxrwxrwx 1 vansart 197121 225424 août 27 2018 libexpat.so.1
-rwxrwxrwx 1 vansart 197121 99936 janv. 19 19:34 libexslt.so.0
-rwxrwxrwx 1 vansart 197121 40864 nov. 8 2017 libffi.so.6
-rwxrwxrwx 1 vansart 197121 324384 juin 7 16:48 libfontconfig.so.1
-rwxrwxrwx 1 vansart 197121 778224 août 24 2018 libfreetype.so.6
-rwxrwxrwx 1 vansart 197121 819744 août 17 2018 libgcc_s.so.1
-rwxrwxrwx 1 vansart 197121 5925928 août 18 2018 libgfortran.so.4
-rwxrwxrwx 1 vansart 197121 1321984 juin 7 16:48 libglib-2.0.so.0
-rwxrwxrwx 1 vansart 197121 16200 août 28 2018 libgthread-2.0.so.0
-rwxrwxrwx 1 vansart 197121 4085608 juin 7 16:48 libhdf5.so.103
-rwxrwxrwx 1 vansart 197121 26215496 nov. 16 2017 libicudata.so.58
-rwxrwxrwx 1 vansart 197121 3227376 nov. 16 2017 libicui18n.so.58
-rwxrwxrwx 1 vansart 197121 2041320 nov. 16 2017 libicuuc.so.58
-rwxrwxrwx 1 vansart 197121 263880 nov. 9 2017 libjpeg.so.9
-rwxrwxrwx 1 vansart 197121 173408 mai 16 2018 liblzma.so.5
-rwxrwxrwx 1 vansart 197121 6628244 mars 14 21:00 libmkl_rt.so
-rwxrwxrwx 1 vansart 197121 272240 nov. 28 2018 libncursesw.so.6
-rwxrwxrwx 1 vansart 197121 296792 mars 12 20:41 libpcre.so.1
-rwxrwxrwx 1 vansart 197121 252920 janv. 11 20:20 libpng16.so.16
-rwxrwxrwx 1 vansart 197121 4270856 juin 7 16:48 libQt5Core.so.5
-rwxrwxrwx 1 vansart 197121 386744 déc. 12 09:48 libQt5DBus.so.5
-rwxrwxrwx 1 vansart 197121 519048 déc. 12 09:48 libQt5EglFSDeviceIntegration.so.5
-rwxrwxrwx 1 vansart 197121 3954056 déc. 12 09:48 libQt5Gui.so.5
-rwxrwxrwx 1 vansart 197121 1183672 déc. 12 09:48 libQt5Network.so.5
-rwxrwxrwx 1 vansart 197121 305760 déc. 12 09:48 libQt5Svg.so.5
-rwxrwxrwx 1 vansart 197121 5440440 déc. 12 09:48 libQt5Widgets.so.5
-rwxrwxrwx 1 vansart 197121 14640 déc. 12 09:48 libQt5X11Extras.so.5
-rwxrwxrwx 1 vansart 197121 971848 déc. 12 09:48 libQt5XcbQpa.so.5
-rwxrwxrwx 1 vansart 197121 864776 août 17 2018 libquadmath.so.0
-rwxrwxrwx 1 vansart 197121 372072 août 28 2018 libreadline.so.7
-rwxrwxrwx 1 vansart 197121 42336 nov. 27 2017 libsnappy.so.1
-rwxrwxrwx 1 vansart 197121 395472 mars 28 2018 libsodium.so.23
-rwxrwxrwx 1 vansart 197121 1233456 mars 12 20:13 libsqlite3.so.0
-rwxrwxrwx 1 vansart 197121 695960 mars 7 16:42 libssl.so.1.1
-rwxrwxrwx 1 vansart 197121 9536208 août 17 2018 libstdc++.so.6
-rwxrwxrwx 1 vansart 197121 1970968 juin 7 16:48 libtcl8.6.so
-rwxrwxrwx 1 vansart 197121 550704 janv. 28 21:29 libtiff.so.5
-rwxrwxrwx 1 vansart 197121 266064 juin 7 16:48 libtinfow.so.6
-rwxrwxrwx 1 vansart 197121 1580952 août 28 2018 libtk8.6.so
-rwxrwxrwx 1 vansart 197121 18472 janv. 11 2018 libuuid.so.1
-rwxrwxrwx 1 vansart 197121 215392 avr. 13 2018 libxcb.so.1
-rwxrwxrwx 1 vansart 197121 24552 avr. 13 2018 libxcb-dri2.so.0
-rwxrwxrwx 1 vansart 197121 23736 avr. 13 2018 libxcb-dri3.so.0
-rwxrwxrwx 1 vansart 197121 154312 avr. 13 2018 libxcb-glx.so.0
-rwxrwxrwx 1 vansart 197121 13784 avr. 13 2018 libxcb-present.so.0
-rwxrwxrwx 1 vansart 197121 34912 avr. 13 2018 libxcb-sync.so.1
-rwxrwxrwx 1 vansart 197121 45936 avr. 13 2018 libxcb-xfixes.so.0
-rwxrwxrwx 1 vansart 197121 1714896 janv. 19 16:11 libxml2.so.2
-rwxrwxrwx 1 vansart 197121 297000 juin 7 16:48 libxslt.so.1
-rwxrwxrwx 1 vansart 197121 133384 nov. 21 2018 libz.so.1
-rwxrwxrwx 1 vansart 197121 731928 févr. 1 13:16 libzmq.so.5
-rwxrwxrwx 1 vansart 197121 696896 nov. 6 2018 libzstd.so.1.3.7
-rwxrwxrwx 1 vansart 197121 0 juin 12 11:31 list.txt
drwxrwxrwx 1 vansart 197121 0 juin 12 08:33 mpl-data/
drwxrwxrwx 1 vansart 197121 0 juin 12 08:33 platforms/
回答1:
Try to manually copy all the lib*.so.*
files into the lib
subdirectory of the frozen application before sharing. Does this solve your problem? If yes, you could automatize this step using shutil.copy2
at the end of your setup.py
script for example.
Regarding your comment:
The app is still looking for the files in the absolute path, and I don't understand why
I guess you refer to the paths appearing in the tracebacks. These are filenames attached to code objects which presumably do not get actualized when the frozen application is moved. You can let cx_Freeze replace these absolute paths through relative ones by adding an entry
'replace_paths': [("*", "")]
to the build_exe
option dictionary in the setup.py
script. See issue #247 on the cx_Freeze repository and the links therein.
来源:https://stackoverflow.com/questions/56559453/how-to-fix-numpy-dependencies-path-on-a-python-3-7-3-script-on-linux-frozen-with