I am having trouble understanding why my QGraphicsPixmapItem is not showing up after I build the application using cx_freeze. Are there any known issues with that class and cx_freeze or am I missing some settings with cx_freeze? Here is the part that is creating and displaying the QGraphicsPixmapItem and after that is my setup.py for cx_freeze:
def partNo_changed(self):
self.scene.removeItem(self.previewItem)
partNumber = self.ui.partNo.text()
fileLocation = 'drawings\\FULL\\%s.svg' % partNumber
print(fileLocation)
pixmap = QtGui.QPixmap(fileLocation)
self.previewItem = QtGui.QGraphicsPixmapItem(pixmap)
self.previewItem.setPos(0, 0)
self.scene.addItem(self.previewItem)
self.ui.svgPreview.centerOn(self.previewItem)
and here is the setup.py script:
from cx_Freeze import setup, Executable
files = ['drawings\\FULL']
setup(
name = 'DBManager',
version = '1.0',
description = 'Makes and maintains the .csv database files.',
author = 'Brock Seabaugh',
options = {'build_exe': {'include_files':files, 'bin_path_includes':files}},
executables = [Executable('dbManager_publicDB.py')])
Everything else works in the program, this is the only thing that is not working(it works if I just run the .py script, but not when I run the exe). I get no errors when I build or run the exe. If someone could help with this that would be great. I am using Python v3.1 and cx_freeze v4.2.3 and PyQt v4.
So I found the answer to my question. Apparently the problem wasn't with the QGraphicsPixmapItem class, it was with the QtSvg portion of the application. Which threw me off because cx_freeze's output showed that the QtSvg Module was included when creating the executable, but that is not all that is needed by the program. It needs the qt.conf file also with it. All I had to do to fix the problem was go find the qt.conf file at '...\Python31\Lib\site-packages\PyQt4\bin\qt.conf' and copy that file to the directory where your application's executable is at and voilĂ , it works!
Related
cx_Freeze import _tkinter #if this fails your python may not be configurated for Tk.. ImportError: DLL load failed: %1 is not a valid win32 application
Hi! I created a word guessing/memorizing language practice program in tkinter, and i wanted to convert it to an executable app but i get errors again and again... I tried at least 10-15 different ways but it is still same. So i googled all the similar topics and tried every single suggestion but they did not work for me. I tried pyinstaller as well. It does not give an error but also it does not run the executed app either. When i click on the app.exe, black CMD screen appears then disappears and it creates the csv file to save the words. So i changed to cx_Freeze but it does not work either.
What have i tried?
For pyinstaller:
I converted my app.py to app.exe by using pyinstaller -F app.py and pyinstaller app.py, but none of them worked.
For cx_Freeze
1- I tried my old setup.py (which worked to convert my all games to .exe) but it did not work on this, i guess it is about tkinter. Because my games were written with pygame, i did not use tkinter for anything.
2 -I tried at least 10 different setup files shared by you guys on stackoverflow and other websites. But they did not work either.
3- I tried to set environment
4- I tried to specify environment
5- I copied tcl86t.dll and tk86t.dll files from the python dlls to my app directory and added them as included files in the setup.py
6- I deleted 64bit version and i only have 32bit version of python3.7
and more and more...
So this is my current setup.py
import sys,os
from cx_Freeze import setup, Executable
os.environ['TCL_LIBRARY'] = "C:\Python37\tcl\tcl8.6"
os.environ['TK_LIBRARY'] = "C:\Python37\tcl\tk8.6"
build_exe_options = {"packages": ["os"],"includes":["tkinter"],"include_files": []}
base = None
if sys.platform == "win32":
base = "Win32GUI"
setup( name = "App",
version = "0.1",
description = "My GUI application!",
options = {"build_exe": build_exe_options},
executables = [Executable("app.py", base=base)]
)
I use Windows7 64bit and Python 3.7.1 32bit and 3.7.0 64bit
So what should i do? I am stuck here. I really gave up and asking a new question on here. Please help me guys.. Thanks in advance.
I downloaded cx_Freeze because I'm trying to make a .exe file to share with my platoon and I've been reading through the docs as well as scrolling through cx_Freeze tutorial. After following both of those I still don't know why this isn't working for me. I'm on Python 3.6.2 and I have the path directly setup to the command line.
I tried to launch with setup.py and Julian date 2.py on the desktop and I tried adding them to same folder, but no matter what I try I get back this error when I type python setup.py build, python: can't open file 'setup.py': [Error2] no such file or directory or file exsists. Below is my setup.py code.
from cx_Freeze import setup, Executable
setup(name = "Julian date 2" ,
version = "0.1" ,
description = "" ,
executables = [Executable("Julian date 2.py")])
Another issue I ran into was trying to type cxfreeze Julian date 2.py --target-dir dist I get the error 'cxfreeze' is not recognized as an internal or external command, operable program or batch file.
When you type python setup.py build, you are supposed to be in the directory with setup.py and not anywhere else. So use the command cd to get there.
cx_freeze is not in your path variable so cxfreeze Julian date 2.py --target-dir dist will not work and you have to instead add it to your path (somehow) [not recommended]
Hope this helped.
P.S.
executables = [Executable("Julian date 2.py")]) takes base too. If you want a console application:
executables = [Executable("Julian date 2.py",base='None')])
Gui for windows:
executables = [Executable("Julian date 2.py",base='Win32GUI')])
And you forgot your exe options in setup(). I recommend adapting the setup.py script on cx_freeze doxs:
import sys
from cx_Freeze import setup, Executable
# Dependencies are automatically detected, but it might need fine tuning.
build_exe_options = {"packages": ["os"], "excludes": ["tkinter"]}
# GUI applications require a different base on Windows (the default is for a
# console application).
base = "None"
setup( name = "name",
version = "0.1",
description = " ",
options = {"build_exe": build_exe_options},
executables = [Executable("file.py", base=base)])
I solved the first issue, my file was named 'setup.py' and not just 'setup' as it's supposed to be...The name must be setup, the extension .py
Know it's DUMB, after hours, that was the problem...
I am currently trying to use cx_Freeze to create a .exe file for my python scripts.
First, do cx_freeze get all data on the folder into the build folder?
Secondly, I'm having an issue when launching the .exe file. The fact that the first file opens the second one could be the issue ?
The console opened and closed, according to another post on Stackoverflow, I created a .bat file containing :
myfilename.exe%1
pause
to check out what the issue is and I got this issue :
Issue
I've really no idea what to do next since I tried many things on the setup.py to make things working.
Here is the setup.py :
"""setup.py"""
from cx_Freeze import setup, Executable
import os
os.environ['TCL_LIBRARY'] = "C:\\Users\\Roukira\\AppData\\Local\\Programs\\Python\\Python36\\tcl\\tcl8.6"
os.environ['TK_LIBRARY'] = "C:\\Users\\Roukira\\AppData\\Local\\Programs\\Python\\Python36\\tcl\\tk8.6"
build_exe_options = {"includes": ["tkinter"]}
setup(name="todolist",
version="0.1",
description = "A simple to do list with differnt tabs per account.",
options = {"build_exe": build_exe_options},
executables = [Executable("login_system.py",base=None)])
I'm only using pillow as an external module but it doesn't seem to be the issue.
Thanks for your help by advance !
EDIT : I managed to fix it by adding the ddl missing files path inside the "include_files" option:
build_exe_options = {"packages": ["os", "tkinter"], "include_files": ["to_do_list.py","336sur525.gif","384sur540.gif",
"accounts.txt","button_hide_2.gif","button_quit_2.gif","choose.gif","icone.ico","user.gif",
r"C:\Users\Roukira\AppData\Local\Programs\Python\Python36\DLLs\tcl86t.dll",
r"C:\Users\Roukira\AppData\Local\Programs\Python\Python36\DLLs\tk86t.dll"]}
My script was using a subprocess.call function to call another script, so it didn't work after becoming .exe, I added the .py file inside the "include_files" and it worked as intended.
I am using Python 2.7 to build my application. Within it, I used few packages which are numpy, scipy, csv, sys, xlwt, time, wxpython and operator.
All the above packages are in 64-bit, and I am using python 2.7(64-bit version) in Aptana Studio 3(64-bit version) in Windows 7 Professional (64-bit version).
At last, I'd like to compile my project to an application using following code, the file name is py2exeTest.py:
from distutils.core import setup
import numpy # numpy is imported to deal with missing .dll file
import py2exe
setup(console=["Graphical_Interface.py"])
Then in cmd, I switched to the directory of the project and used following line to compile it:
python py2exeTest.py py2exe
Everything goes well, it generates an application under dist directory, and the application name is Graphical_Interface.exe.
I double clicked it, but there is a cmd window appears, and a python output windows flashes, then both of them disappeared. I tried to run the application as an administrator, the same outcome I've had.
May I know how to work this out?
Thanks!
EDIT:
I've managed to catch the error information that flashes on the screen. The error info I had is:
Traceback (most recent call last):
File "Graphical_Interface.py", line 397, in <module>
File "Graphical_Interface.py", line 136, in __init__
File "wx\_core.pyc", line 3369, in ConvertToBitmap
wx._core.PyAssertionError: C++ assertion "image.Ok()" failed at ..\..\src\msw\bitmap.cpp(802) in wxBitmap::CreateFromImage(): invalid image
I used one PNG image in the project, the code is like follows:
self.workflow = wx.Image("Work Flow.png", wx.BITMAP_TYPE_ANY).ConvertToBitmap()
wx.StaticBitmap(self.panel_settings, -1, self.workflow, (330,270), (self.workflow.GetWidth(), self.workflow.GetHeight()))
I tried to comment the above chunk out from the project, and the application works properly. However, I need the image to show up in the application.
May I know how to deal with it?
Thanks.
Hiding console window of Python GUI app with py2exe
When compiling graphical applications you can not create them as a console application because reasons (honestly can't explain the specifics out of my head), but try this:
from distutils.core import setup
import numpy
import py2exe
import wxpython
setup(window=['Graphical_Interface.py'],
options={"py2exe" { 'boundle_files' : 1}})
Also consider changing to:
http://cx-freeze.sourceforge.net/
It works with Python3 and supports multiple platforms.
A cx_freeze script would look something like:
import sys
from cx_Freeze import setup, Executable
# Dependencies are automatically detected, but it might need fine tuning.
build_exe_options = {"packages": ["os"], "excludes": ["tkinter"]}
# GUI applications require a different base on Windows (the default is for a
# console application).
base = None
if sys.platform == "win32":
base = "Win32GUI"
includefiles = ['/folder/image.png']
setup( name = "GUIprog",
version = "0.1",
description = "My GUI application!",
options = {"build_exe": build_exe_options, 'include_files' : includefiles},
executables = [Executable("Graphical_Interface.py", base=base)])
No worries, I've got the solution.
It turns out that the image is in the project folder rather than in the dist folder. So I have two solutions:
Copy the image into dist folder
Include the full path of the image in the code.
Thanks for your help.
What I'm trying to do is compile a program I've written in Python 2.7, using pygame, into a standalone app for Mac computers. I'm working on a PC running Windows 8 with no access to a mac, so tweaking the process has been difficult.
When I run the setup file from the command prompt, I get the "text flood" (similar to what py2exe gave me when it worked to compile the windows version) and the program appears to work. It creates build and dist folders, but the dist folder has no contents. When looking at the command prompt output, the last two lines are
BASE_CFLAGS = cfg['CFLAGS']
Key Error: 'CFLAGS'
This seems to happen when py2app is trying to create the application bundle.
Here is the setup.py file I've gotten to thus far:
"""
Script for building the example.
Usage:
python setup.py py2app
"""
from setuptools import setup
NAME = 'PetCute Slide Puzzle Test'
VERSION = '0'
plist = dict(
CFBundleIconFile=NAME,
CFBundleName=NAME,
CFBundleShortVersionString=VERSION,
CFBundleGetInfoString=' '.join([NAME, VERSION]),
CFBundleExecutable=NAME,
CFBundleIdentifier='Py2App and PyGam test',
)
setup(
data_files=['Dog1.jpg', 'Dog2.jpg', 'Dog3.jpg', 'Dog4.jpg', 'Dog5.jp', 'Dog6.jpg', 'Dog7.jpg', 'Dog8.jpg', 'Dog9.jpg', 'Dog10.jpg', 'Dog11.jpg', 'Dog12.jpg', 'Dog13.jpg', 'Dog14.jpg', 'Dog15.jpg', 'Dog16.jpg', 'AYearWithoutRain.ttf'],
app=[
dict(script="PetCute_slidepuzzle.py", plist=plist),
],
setup_requires=["py2app"],
)
The data_files lists out the pictures and text file that need to be bundled with the code. I got to this by adapting the alien.py example. Please let me know if any more info is needed!
It probably had an error during compilation. I suggest you make sure you have Numpy installed, its needed for py2app to compile Pygame programs.