2012-07-04 11 views
5

をインポートすることはできません:はImportErrorがpyInstallerのフックディレクトリにpyInstallerの:exeファイルを実行している場合、スタンドアロンexeファイル(-F)を作成するには、Windows 7の最新<a href="http://www.pyinstaller.org/" rel="nofollow">pyinstaller</a>を使用して名前QtGui

ImportError: cannot import name QtGui

ための特別な処理がありますPyStideではなくPyQt4。

これを回避するための回避策などを試してみてください。

環境
Windows 7の64ビット
パイソン2.7 32ビット
PYTHONHOME = C:\ python27
PYTHONPATH = C:\ python27 \ LIB
PYTHONLIB = C:\ python27 \ LIBS \ python27.lib; C:\ python27 \ libに\のsite-packages

ステップ
1. http://releases.qt-project.org/pyside/1.1.1/PySide-1.1.1qt474.win32-py2.7.exeからPySideを追加します。 Cへ 2.解凍https://github.com/pyinstaller/pyinstaller/zipball/develop:\ pyinstaller1.5.1
3.ファイル名を指定して実行するだけ含むの.pyファイルに対して、以下のコマンド:

from PySide import QtGui 

[...またはQtCoreかまたは。]

実行

c:\pyinstaller1.5.1>pyinstaller.py -F import_test.py 
108 INFO: wrote c:\pyinstaller1.5.1\import_test.spec 
171 INFO: Testing for ability to set icons, version resources... 
296 INFO: ... resource update available 
312 INFO: UPX is not available. 
4321 INFO: checking Analysis 
4382 INFO: checking PYZ 
4430 INFO: checking PKG 
4446 INFO: building because c:\pyinstaller1.5.1\build\pyi.win32\import_test\import_test.exe.manifest changed 
4446 INFO: building PKG out00-PKG.pkg 
16782 INFO: checking EXE 
16782 INFO: rebuilding out00-EXE.toc because pkg is more recent 
16782 INFO: building EXE from out00-EXE.toc 
16799 INFO: Appending archive to EXE c:\pyinstaller1.5.1\dist\import_test.exe 

c:\pyinstaller1.5.1>dist\import_test.exe 
Traceback (most recent call last): 
    File "<string>", line 23, in <module> 
ImportError: cannot import name QtGui 

 
At the end of the PySide install (as admin), this message: 
    close failed in file object destructor: 
    sys.excepthook is missing 
    lost sys.stderr 
If that is about post install it can be handled manually: 
    c:>python.exe c:\Python27\Scripts\pyside_postinstall.py -install 
    Generating file C:\python27\qt.conf... 
    PySide installed in c:/python27/Lib/site-packages/PySide... 
    The PySide extensions were successfully installed. 

答えて

1

回避策。ないことが多い

# Various imports, whatever, using normal sys.path, for example: 
import os, sys, re, time, random 
import subprocess, psutil 

# Save sys.path 
sys_path_saved = sys.path 

# Limit sys.path for PySide import 
sys.path = ['c:\\python27\\lib\\site-packages'] 

# PySide imports with limited sys.path 
from PySide  import QtGui, QtCore 
from PySide.QtGui import QApplication, QLineEdit 
from PySide.QtCore import QSettings, Qt 

# Reset sys.path to original 
sys.path = sys_path_saved 

# Remainder of code... 

pyInstallerの1.5.1は、依存関係を見つけるの細かい仕事をする必要があり、これは働いていました。 しかし、.specでpathexまたはhiddenimportsを使用しようとする多くの試みはすべて失敗しました。 自分の環境変数を変更することもできませんでした。.eggからさまざまなモジュールファイルを手動で抽出することがありました。

しかし、PySideのインポートでは、上記のsys.pathの一時的な制限が有効な回避策でした。

アップデート:残念ながら、exeはPython/Pysideがインストールされたマシンでのみ動作し、Pythonを使用しないXPでは動作しません。

関連する問題