2016-08-03 8 views
0

Ich erhalte einen Fehler beim Versuch, eine einfache hello.py mit PyInstaller auf RHEL X64 zu versuchen.Fehler beim Importieren des Moduls beim Ausführen von PyInstaller generierte Binärdatei

Python 2.7.12 ist alt installiert in/opt/Python

Compilation Ausgang:

[[email protected] CommandManager]# pyinstaller Hello.py 
21 INFO: PyInstaller: 3.2 
21 INFO: Python: 2.7.12 
22 INFO: Platform: Linux-3.10.0-327.22.2.el7.x86_64-x86_64-with-redhat-7.2-Maipo 
62 INFO: wrote /home/myuser/CommandManager/Hello.spec 
66 INFO: UPX is not available. 
107 INFO: Extending PYTHONPATH with paths 
['/home/myuser/CommandManager', '/home/myuser/CommandManager'] 
107 INFO: checking Analysis 
108 INFO: Building Analysis because out00-Analysis.toc is non existent 
108 INFO: Initializing module dependency graph... 
110 INFO: Initializing module graph hooks... 
148 INFO: running Analysis out00-Analysis.toc 
155 INFO: Caching module hooks... 
158 INFO: Analyzing /home/myuser/CommandManager/Hello.py 
160 INFO: Loading module hooks... 
161 INFO: Loading module hook "hook-encodings.py"... 
1493 INFO: Looking for ctypes DLLs 
1493 INFO: Analyzing run-time hooks ... 
1500 INFO: Looking for dynamic libraries 
1801 INFO: Looking for eggs 
1801 INFO: Python library not in binary depedencies. Doing additional searching... 
1827 INFO: Using Python library /lib64/libpython2.7.so.1.0 
1899 INFO: Warnings written to /home/myuser/CommandManager/build/Hello/warnHello.txt 
1983 INFO: checking PYZ 
1983 INFO: Building PYZ because out00-PYZ.toc is non existent 
1983 INFO: Building PYZ (ZlibArchive) /home/myuser/CommandManager/build/Hello/out00-PYZ.pyz 
2465 INFO: checking PKG 
2465 INFO: Building PKG because out00-PKG.toc is non existent 
2465 INFO: Building PKG (CArchive) out00-PKG.pkg 
2648 INFO: Bootloader /opt/python/lib/python2.7/site-packages/PyInstaller/bootloader/Linux-64bit/run 
2648 INFO: checking EXE 
2649 INFO: Building EXE because out00-EXE.toc is non existent 
2649 INFO: Building EXE from out00-EXE.toc 
2690 INFO: Appending archive to ELF section in EXE /home/myuser/CommandManager/build/Hello/Hello 
2991 INFO: checking COLLECT 
2992 INFO: Building COLLECT because out00-COLLECT.toc is non existent 
2993 INFO: Building COLLECT out00-COLLECT.toc 

Hello.py:

print("Hello") 

Dies ist der Fehler Ich erhalte:

mod is NULL - structTraceback (most recent call last): 
    File "/opt/python/lib/python2.7/struct.py", line 1, in <module> 
    from _struct import * 
ImportError: /home/myuser/CommandManager/dist/Hello/_struct.so: undefined symbol: PyUnicodeUCS2_AsEncodedString 
mod is NULL - pyimod02_archiveTraceback (most recent call last): 
    File "/tmp/pip-build-xDjNbD/pyinstaller/PyInstaller/loader/pyimod02_archive.py", line 28, in <module> 
ImportError: No module named struct 
mod is NULL - pyimod03_importersTraceback (most recent call last): 
    File "/tmp/pip-build-xDjNbD/pyinstaller/PyInstaller/loader/pyimod03_importers.py", line 24, in <module> 
ImportError: No module named pyimod02_archive 
Traceback (most recent call last): 
    File "site-packages/PyInstaller/loader/pyiboot01_bootstrap.py", line 15, in <module> 
ImportError: No module named pyimod03_importers 
Failed to execute script pyiboot01_bootstrap 

Irgendeine Ahnung, was das verursachen könnte?

Die automatisch generierte Hello.spec Datei sieht wie folgt aus:

# -*- mode: python -*- 

block_cipher = None 


a = Analysis(['Hello.py'], 
      pathex=['/home/myuser/CommandManager'], 
      binaries=None, 
      datas=None, 
      hiddenimports=[], 
      hookspath=[], 
      runtime_hooks=[], 
      excludes=[], 
      win_no_prefer_redirects=False, 
      win_private_assemblies=False, 
      cipher=block_cipher) 
pyz = PYZ(a.pure, a.zipped_data, 
      cipher=block_cipher) 
exe = EXE(pyz, 
      a.scripts, 
      exclude_binaries=True, 
      name='Hello', 
      debug=False, 
      strip=False, 
      upx=True, 
      console=True) 
coll = COLLECT(exe, 
       a.binaries, 
       a.zipfiles, 
       a.datas, 
       strip=False, 
       upx=True, 
       name='Hello') 
+1

Line "mit Python-Bibliothek /lib64/libpython2.7.so.1.0" könnte ein Problem hinweisen, wenn die Python-Installation in/opt/Python befindet und die entsprechende Bibliothek in/opt/python/lib oder etwas ähnliches. –

+0

Sie haben Recht! Es ist ein Problem mit dem Bibliothekspfad. – Hec

Antwort

1

PyInstaller Python mit --enable-shared and LDFLAGS=-Wl,-rpath=<path to python lib> kompiliert werden muss.

In meinem Fall:

configure --enable-shared prefix =/opt/Python LDFLAGS = -Wl, -rpath =/opt/Python/lib

Weitere Referenz: https://bugs.python.org/issue27685

Verwandte Themen