2016-08-03 47 views
0

RHEL X64でPyInstallerを使用して単純なhello.pyを実行しようとしているときにエラーが発生しました。PyInstallerで生成されたバイナリを実行しているときにモジュールインポートエラーが発生しました

Pythonの2.7.12は、ALTは/ opt/pythonで設置

コンパイル出力です:

[[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") 

これは私が取得していますエラーです。

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 

これを引き起こしているかもしれない何か手掛かり?

自動生成Hello.specファイルは、次のようになります。

# -*- 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

「Pythonライブラリの使用/lib64/libpython2.7.so.1.0」は、Pythonインストールが/ opt/pythonにあり、対応するライブラリが/ opt/pythonにある場合に問題がある可能性があります/ libまたは類似のもの。 –

+0

あなたは正しいです!これはライブラリパスの問題です。 – Hec

答えて

1

pyInstallerのは--enable-shared and LDFLAGS=-Wl,-rpath=<path to python lib>してコンパイルするのpythonを必要とします。

に./configure --enable-共有--prefix =は/ opt/pythonの LDFLAGS = -Wl、-rpath =は/ opt /パイソン/

libに:私の場合は

追加リファレンス: https://bugs.python.org/issue27685

関連する問題