Reputation: 6962
I have been trying to setup PySide/Qt for use with Python3.3. I have installed
PySide-1.2.0.win32-py3.3.exe
that I took from here and I have installed
qt-win-opensource-4.8.5-vs2010
that I took from here.
I generated .py
files from .ui
files (that I made using QtDesigner) using pyside-uic.exe
as is explained in PySide Wiki.
Making .py
files was working when I was using Qt5.1/QtCreator. I stopped using it when I found that I need to use Qt4.8 as explained on Qt-forums. With Qt4.8 it isn't working.
I want to package the GUI developed into .exe files using cx-freeze.
My problem in short
What are the correct tools to use to make .ui
with QtDesigner? How to convert them to .py
files for use in Python using PySide?
cx_freeze is able to make my normal files to .exe
Can it be used to convert the GUI made by Qt/PySide into .exe
files? Would Qt be needed on other computers where the .exe
of the GUI is distributed or would it be self-contained?
I used
cxfreeze testGUI.py --include-modules=PySide
to make the exe and related files. A directory dist
was created with many files. On running nothing happened. So I used command line to find out the reason. The errors are
Traceback (most recent call last):
File "C:\Python33\lib\site-packages\cx_Freeze\initscripts\Console3.py", line 27, in <module>
exec(code, m.__dict__)
File "testGUI.py", line 12, in <module>
File "C:\Python\32-bit\3.3\lib\importlib\_bootstrap.py", line 1558, in _find_and_load
File "C:\Python\32-bit\3.3\lib\importlib\_bootstrap.py", line 1525, in _find_and_load_unlocked
File "C:\Python33\lib\site-packages\PySide\__init__.py", line 55, in <module>
_setupQtDirectories()
File "C:\Python33\lib\site-packages\PySide\__init__.py", line 11, in _setupQtDirectories
pysideDir = _utils.get_pyside_dir()
File "C:\Python33\lib\site-packages\PySide\_utils.py", line 87, in get_pyside_dir
return _get_win32_case_sensitive_name(os.path.abspath(os.path.dirname(__file__)))
File "C:\Python33\lib\site-packages\PySide\_utils.py", line 83, in _get_win32_case_sensitive_name
path = _get_win32_long_name(_get_win32_short_name(s))
File "C:\Python33\lib\site-packages\PySide\_utils.py", line 58, in _get_win32_short_name
raise WinError()
FileNotFoundError: [WinError 3] The system cannot find the path specified.
Anyone knows what this stacktrace means?
There is a lot of win32
in here. But I have Windows 7 64-bit. I am using 32-bit Python and all modules were installed 32-bit. Could that cause a problem? I don't think it should as other exe I made for simple Python scripts were executing fine.
Upvotes: 3
Views: 4483
Reputation: 6962
PySide 1.2.1 was released. It has fixed the error. I checked it by installing the new version and using cx_freeze.
No error in packaging with cx_freeze 4.3.1(32-bit version for Python 3.3) used with Python 3.3.2(32-bit) and PySide 1.2.1(32-bit) on Windows 7(64-Bit). I used the command written in the question to package it. It worked successfully.
Upvotes: 0
Reputation: 591
Regarded FileNotFoundError, I had a problem packaging a python 3 application with this for a few days. On a windows 7 64 bit machine it worked fine. When I built it on win7 32bit and tried to run the .exe file, I got all those file errors. After seeing this thread I checked the versions of pyside. On the win64 it was 1.1.2 on the win32 it was 1.2.0 I uninstalled pyside 1.2.0 on win32 and downloaded and installed the 1.1.2 win32 version. It now works ok. This could be a stop gap measure until 1.2.1 is released.
Upvotes: 1
Reputation: 671
I'm doing something similar (however I'm in the progress of migrating from PyQt to PySide).
You should use pyside-uic to generate the code for the GUI after creating the UI files in QtCreator (If this were PyQt "pyuic gui.ui > gui.py" would produce the desired code, I assume pyside-uic has a similar behaviour). I then subclass this generated code to customise the user interface.
Yes, you can use cx_freeze with PyQt/PySide, you'll want to include PySide in the "includes" item in the build options.
Yes, you can create a completely self-contained executable - you won't need Python, Qt or anything else.
Here's the build I use from my PySide GUI application.
__author__ = 'AlexM'
import sys
from cx_Freeze import setup, Executable
import MyPySideGui
import PySide, os
base = None
if sys.platform == "win32":
base = "Win32GUI"
QGifRelDir = "imageformats\qgif4.dll"
PySideDir = (os.path.join(os.path.dirname(PySide.__file__),"plugins"))
shortcut_table = [
("App Shortcut", # Shortcut
"ProgramMenuFolder", # Directory_
"MyPySideGUI", # Name
"TARGETDIR", # Component_
"[TARGETDIR]MyPySideApp.exe", # Target
None, # Arguments
None, # Description
None, # Hotkey
None, # Icon
None, # IconIndex
None, # ShowCmd
'TARGETDIR' # WkDir
)
]
build_exe_options = {
"include_files" : ["documentTemplate.html", "loading.gif", (os.path.join(PySideDir,QGifRelDir), QGifRelDir)],
"packages" : ["CustomHelperPackage", "AnotherCustomPackage", "MyPySideGui"],
"includes" : ["PySide"],
"excludes" : ["tkinter"],
'optimize': 2,
}
# Now create the table dictionary
msi_data = {"Shortcut": shortcut_table}
# Change some default MSI options and specify the use of the above defined tables
bdist_msi_options = {'data': msi_data}
executables = [ Executable("MyPySideGui.py", base = base) ]
setup(
name = "MyFirstPySideApplication",
version = str(MyPySideGui.version),
description = "MyPySideApp.exe Demonstrates PySide guis.",
options = {
"build_exe": build_exe_options,
"bdist_msi": bdist_msi_options
},
executables = executables
)
This example might be slightly complicated for you, but you can find simpler examples on the cx_freeze project homepage.
I'm not getting the issues you or the other answer are getting, but then I'm using Python 3.3.1 with PySide 1.1.2.
Upvotes: 1
Reputation: 561
This error:
FileNotFoundError: [WinError 3] The system cannot find the path specified.
will be fixed in next pyside release (1.2.1). It will be released in next week.
btw: in case you don't want to generate custom bindings, you don't need to install qt, pyside installer contains all qt libraries and devel tools.
Upvotes: 5