When I tried to convert my Pythonprogram into an exe with py2exe, first everything works fine until I tried to bundle all files into one single executable file. First all the images and sounds are not bundled, but in the distfolder. I have the same problem with a .dll file, witch I have to import manually for the programm to work. So how do I import all the files like images, dll's and sounds into the exe? Next when I try to execute the exe like this, it gives me this error in cmd:
Fatal Python error: (pygame parachute) Segmentation Fault
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
Here is my setup file:
from distutils.core import setup
import py2exe
import Tkinter as tk
from itertools import cycle
import pygame
import random
import glob
setup(
data_files=[("libogg-0.dll"),
('.', glob.glob('*.gif')),
('.', glob.glob('*.wav'))],
options = {"py2exe": {"includes": ['Tkinter', 'random', 'itertools', 'pygame'],
"excludes": ['AppKit', 'Carbon', 'Carbon.Files', 'Foundation', 'Numeric', 'OpenGL.GL', 'OpenGL.GLU', 'RandomArray', '_scproxy', '_sysconfigdata', 'copyreg', 'dummy.Process', 'numpy', 'opencv', 'pkg_resources', 'psyco', 'queue', 'test.__main__', 'test.event_test', 'test.test_utils', 'test.test_utils.async_sub', 'test.test_utils.run_tests', 'test.test_utils.test_runner', 'test.test_utils.unittest_patch', 'urllib.parse', 'vidcap', 'win32api', 'win32con', 'win32file', 'win32pipe', 'winreg','pygame.sdlmain_osx'],
"dll_excludes": ['OLEAUT32.dll','USER32.dll', 'IMM32.dll', 'SHELL32.dll', 'ole32.dll', 'COMDLG32.dll', 'COMCTL32.dll', 'ADVAPI32.DLL', 'WS2_32.dll', 'GDI32.dll', 'WINMM.DLL', 'KERNEL32.dll', 'SDL_ttf.dll', 'libogg-0.dll'],
"packages": ['pygame'],
"bundle_files": 1,
"compressed": True
}
},
console=['test.py'],
zipfile = None
)
If there is still something unclear, feel free to comment a answer. Sorry if my english is bad.
Related
I have a large Python project that I am working to make to an app, using Py2app. However, my main file includes a large number of imports, which cannot all be recognized by Py2app. Here is an example of the scale of this:
from Assets.Miscellaneous.formatting import Format
from Assets.Miscellaneous.inventory import InventoryCheck
from Assets.Health_Attack.stats import Stats
from Assets.Battle_System.battle_request import Battle_Request
from Assets.Health_Attack.items import Item
from maps import Position
from Assets.Health_Attack.merchants import Merchant
from Assets.Audio.audio_control import main_audio_loop
from Assets.Health_Attack.status_screen import print_status_screen
from Assets.Health_Attack.items import all_keys
from Assets.Miscellaneous.key_door_event import check_key_inventory, pass_door
from Assets.Visuals.neo_animation_system import show_graphic
from Assets.Miscellaneous.reset_game import full_reset
from Assets.Miscellaneous.neo_2_settings import settings
from Assets.Miscellaneous.bed_check import bed_check
from Assets.Miscellaneous.window_event import window_event
Here is my setup.py file:
from setuptools import setup
import os
APP = ['adventuregame.py']
DATA_FILES = [
'print_speed.txt', 'maps_data.py', 'current_enemy_health.txt', 'first_game.txt',
'map_size.txt', 'item_inventory_data.txt',
'audio_stop_check.txt', 'savedvariables.txt', 'player_stats.txt', 'inventory_data.txt',
'curr_pl_mat.txt', 'battle_happening.txt', 'money.txt', 'curr_pr_mat.txt',
'item_tracker.txt']
for index, item in enumerate(DATA_FILES):
DATA_FILES[index] =
"/Users/caspianahlberg/Desktop/Programming/Isolated_AG/Assets/Global_Vars/" + item
setup(
app=APP,
data_files=DATA_FILES,
setup_requires=['py2app']
)
I have a large number of text files that store data relating to the game that I am making. However, when running the executable generated, this error occurs:
FileNotFoundError: [Errno 2] No such file or directory: '/Users/caspianahlberg/Desktop/Programming/Isolated_AG/dist/adventuregame.app/Contents/Resources/Assets/Global_Vars/current_enemy_health.txt'
2020-03-17 00:21:01.094 adventuregame[42211:18386951] adventuregame Error
So, the problem is that somehow, everything is not compiled in some way. This text file is in the wrong directory, which I am not sure how it happened. Please provide some help for my problem, it's really frustrating to deal with myself!
Below is my setup file to setup a python wrapper. The issue I am having is that in my c code I am writing is making calls to clock_gettime for profiling reasons. The thing is when I try to import the module I get the following: error undefined symbol: clock_gettime. I understand that I need to compile with -lrt, but obviously my compiler is not getting that flag. What am I doing wrong?
from distutils.core import setup, Extension
import os
module1 = Extension('relaymod',
extra_compile_args = ["-lrt"], #flag so compiler links to realtime lib
sources=['relaymodule.c']
)
setup (name = 'relaymod',
version = '1.0',
description = "CTec Relay Board controller",
author='Richard Kelly',
url='site',
ext_modules=[module1])
EDIT:
looking at the distutils.core documentation I believe I need to set extra_link_args Below is my new change, but I am now getting this error: NameError: name 'extra_link_args' is not defined
EDIT2: ok the code below is now working. Had a few things going on. after I removed the build folder and rebuilt this worked.
from distutils.core import setup, Extension
import os
module1 = Extension('relaymod',
extra_link_args=["-lrt"],
sources=['relaymodule.c']
)
setup (name = 'relaymod',
version = '1.0',
description = "CTec Relay Board controller",
author='Richard Kelly',
url='site',
ext_modules=[module1])
you are missing the equal (=) you need to say extra_link_args=[your list of link args]
Updated per the comments:
delete the build folder before retrying
If I'm actually asking you for help, it's because I spend many hours for nothing into trying to fix my problem:
I would like to compile my python script into .exe:
(I am using Python 32 bits 3.1.4 and pygame)
I have 4 files: Class.pyc, _Class_game.pyc, _ressources.pyc et main.py
and a folder #ressources with all images and songs
This is my scritp setup.py:
import cx_Freeze
executables = [cx_Freeze.Executable("main.py"), base = "Win32GUI"]
cx_Freeze.setup(
name="Strike The square",
version = "2.0",
description = "Jeu Strike The Square, V2.1",
options={"build_exe": {"packages":["pygame"],
"include_files": ["_Class_.pyc","_Class_game.pyc","_ressources.pyc"]}},
executables = executables
)
This create a folder "exe.xin32-3.1" with python (compiled) and my game
Next, I use inno setup to build the installer and add the folder #ressources
On my computer, It works very well, but when one of my friend wants to play (he hasn't python and pygame), the game creates this error:
[Error][1]
Then...I think this error comes from windows' ressources but I don't know how can I fix it...
The option (in setup.py):
include_msvcr = True
Doesn't work...
Thanks for your answer and excuse my english...
Hawk_Eyes
PS: this my game imports
try:
import pygame,time, ctypes
from random import randint
from pygame.locals import *
from math import sqrt
from _ressources import Shared
except ImportError as e:
print("Erreur du chargement du module: {0}".format(e))
Not sure if this will help but this is a copy of my setup file, i have used this to compile Pygame, Pubnub and various things. notice i don't include the files i want to include. The setup auto finds the files needed.
import sys
from cx_Freeze import setup, Executable
exe = Executable(
script = r"launcher.py",
base = 'Win32GUI',
icon = None,
targetName = "launcher.exe"
)
setup(
version = "0.1",
description = "launcher",
author = "Joshua Nixon",
name = "launcher",
executables = [exe]
)
$ cd path/to/files
$ python file.py build
EDIT
I recently found you could create .MSI files using cx_freeze which are very nice for distributing. IF the program uses images then (because you cannot bundle images with the MSI (that i know of) you create a little function which downloads them on launch from imgur or some place))
setup.py for MSI
import sys
from cx_Freeze import setup, Executable
company_name = "JoshuaNixon"
product_name = "Test"
bdist_msi_options = {
'add_to_path': False,
'initial_target_dir': r'[ProgramFilesFolder]\%s' % (company_name),
}
if sys.platform == 'win32':
base = 'Win32GUI'
else:
base = None
exe = Executable(script='launcher.py',
base=base,
icon="mushroom.ico",
)
setup(name=product_name,
version='1.0.0',
description='blah',
executables=[exe],
options={'bdist_msi': bdist_msi_options})
$ cd path/to/files
$ python file.py bdist_msi
I am trying to convert a pyside app to an executable (.exe) on Windows using cx_freeze. The packaging works with no problem, but when starting the generated .exe file, I get the following error:
ImportError: could not import module "PySide.QtXml"
When I try to convert the app shipped with cx_Freeze\Samples\PyQt4, it runs with no problems.
In this sample application there is just a simple QDialog called, but in my application I used QtDesigner for GUI design and I load it with PySide UiLoader directly in my py.file:
class MainWindow(QtGui.QMainWindow):
def __init__(self,parent=None):
QMainWindow.__init__(self)
loader = QUiLoader()
self.ui = loader.load('xxxx.ui',self)
QMetaObject.connectSlotsByName(self)
setup.py
from cx_Freeze import setup, Executable
# Dependencies are automatically detected, but it might need
# fine tuning.
buildOptions = dict(packages = [], excludes = [])
import sys
from cx_Freeze import setup, Executable
from PySide import QtXml
base = 'Win32GUI' if sys.platform=='win32' else None
options = {
'build_exe': {
'includes': 'atexit'
}
}
build_exe_options = {
'includes': ['atexit'],
}
executables = [
Executable('xxx.py', base=base)
]
setup(name='xxx',
version = '0.10',
description = 'First try',
options = dict(build_exe = buildOptions),
executables = executables)
In my opinion there's some problem using UiLoader when converting with cx_freeze but I have no clue how to overcome this issue.
This seems to be an old question. Still I am answering as it would help someone who is looking for a solution.
The solution is so simple that you just need to add "PySide.QtXml" to the includes list. After this your setup.py will look like this
build_exe_options = {
'includes': ['atexit'],
'packages': ['PySide.QtXml'],
}
I am trying to use cx-freeze to create a static self-contained distribution of my app (The Spye Python Engine, www.spye.dk), however, when I run cx-freeze, it says:
Missing modules:
? _md5 imported from hashlib
? _scproxy imported from urllib
? _sha imported from hashlib
? _sha256 imported from hashlib
? _sha512 imported from hashlib
? _subprocess imported from subprocess
? configparser imported from apport.fileutils
? usercustomize imported from site
This is my setup.py:
#!/usr/bin/env python
from cx_Freeze import setup, Executable
includes = ["hashlib", "urllib", "subprocess", "fileutils", "site"]
includes += ["BaseHTTPServer", "cgi", "cgitb", "fcntl", "getopt", "httplib", "inspect", "json", "math", "operator", "os", "os,", "psycopg2", "re", "smtplib", "socket", "SocketServer", "spye", "spye.config", "spye.config.file", "spye.config.merge", "spye.config.section", "spye.editor", "spye.framework", "spye.frontend", "spye.frontend.cgi", "spye.frontend.http", "spye.input", "spye.output", "spye.output.console", "spye.output.stdout", "spye.pluginsystem", "spye.presentation", "spye.util.html", "spye.util.rpc", "ssl", "stat,", "struct", "subprocess", "sys", "termios", "time", "traceback", "tty", "urllib2", "urlparse", "uuid"]
includefiles=[]
excludes = []
packages = []
target = Executable(
# what to build
script = "spye-exe",
initScript = None,
#base = 'Win32GUI',
targetDir = r"dist",
targetName = "spye.exe",
compress = True,
copyDependentFiles = True,
appendScriptToExe = False,
appendScriptToLibrary = False,
icon = None
)
setup(
version = "0.1",
description = "No Description",
author = "No Author",
name = "cx_Freeze Sample File",
options = {"build_exe": {"includes": includes,
"excludes": excludes,
"packages": packages
#"path": path
}
},
executables = [target]
)
Please note that I clearly specify the missing modules in the includes list.
How do I fix this?
Missing modules aren't necessarily a problem: a lot of modules try different imports to accommodate different platforms or different versions of Python. In subprocess, for example, you can find this code:
if mswindows:
...
import _subprocess
cx_Freeze doesn't know about this, so it will try to find _subprocess on Linux/Mac as well, and report it as missing. Specifying them in includes doesn't change anything, because it's trying to include them, but unable to find them.
It should build a file anyway, so try running that and seeing if it works.
I guess, you can not simply += on lists.
You should probably use the list method extend - otherwise the original list will not be modified:
includes.extend(["BaseHTTPServer", "<rest of your modules>"])
EDIT: (Thank #ThomasK)
+= works fine - I only had an online Python interpreter that did not work correctly. (I have no python install on my Windows installation so I had to check online).