py2exe packing data files - python

I have an app to pack that contains an image as data file and I tried to run this setup.py script:
from distutils.core import setup
import py2exe
import matplotlib
file_dati=[]
file_dati.append(matplotlib.get_py2exe_datafiles())
file_dati.append(('img1','C:\Users\MZompetta.000\Desktop\20130114_assortimenti\img1.gif'))
setup(console=[{"script": "Int_assortimenti.py"}],
options = {
"py2exe": {
"dll_excludes": ["libzmq.dll", "MSVCP90.dll"]
}
}, data_files=file_dati
)
but I obtain this error:
AttributeError: 'tuple' object has no attribute 'split'
the error is referred to the line: data_files=file_dati
I tried other ways to compose the data_files but no way.
Anyone can help me?

import os
import logging
from distutils.core import setup
import py2exe
import matplotlib
import shutil
distDir = "dist"
# Remove the build and dist folders
shutil.rmtree("build", ignore_errors=True)
shutil.rmtree("dist", ignore_errors=True)
try:
os.mkdir(os.path.abspath(distDir))
except:
logging.exception('')
data_files = matplotlib.get_py2exe_datafiles()
shutil.copyfile('C:\Users\MZompetta.000\Desktop\20130114_assortimenti\img1.gif', os.path.join(distDir, "img1.gif"))
setup(
options = {"py2exe": {
"dll_excludes": ["libzmq.dll", "MSVCP90.dll"],
"dist_dir": distDir,
}
}
data_files = data_files,
console=[{"script": "Int_assortimenti.py"}],
)

Related

Possible uiloader issue when converting pyside app using cx_freeze

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'],
}

Including logging.conf in setup.py?

In my package_name subdirectory (one below "setup.py") I have a "logging.conf" file.
How do I include it in my setup?
Attempt
from distutils.sysconfig import get_python_lib
data_files=[(path.join(get_python_lib(), package_name),
path.join(path.dirname(__file__), package_name, 'logging.conf'))
Preferably it should be something simple like:
data_files = [(package_name, path.join('.', package_name, 'logging.conf'))]
Error
error: can't copy 'c': doesn't exist or not a regular file
Do you want to include logging.conf within your package distribution? Use the package_data argument to setup():
setup(
name = "package-name",
packages = ["packagename"],
package_data= {
"packagename": [
"resources/foo.bar",
"resources/static/css/*",
"README.md",
"logging.conf"
]},
...
)

Python compress all files/images/sounds in one executable file with py2exe

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.

py2exe change application name output

I am working on my first Python project and I need compile with py2exe. I wrote this setup.py code :
from distutils.core import setup
import py2exe
import sys
import os
if len(sys.argv) == 1:
sys.argv.append("py2exe")
setup( options = {"py2exe": {"compressed": 1, "optimize": 2,"dll_excludes": "w9xpopen.exe",'dist_dir': "myproject", "ascii": 0, "bundle_files": 1}},
zipfile = None,
console = [
{
"script": "myapplication.py", ### Main Python script
"icon_resources": [(0, "favicon.ico")] ### Icon to embed into the PE file.
}
],)
os.system('upx -9 dist/*.exe')
os.system("rmdir /s /q build")
os.system("del /q *.pyc")
The setup code is working, but I need to change the name of the compiled application from myapplication to project.exe. What options for py2exe change the name of output application?
Add "dest_base" : "app_name" to your console dict as such:
console = [
{
"script": "myapplication.py", ### Main Python script
"icon_resources": [(0, "favicon.ico")], ### Icon to embed into the PE file.
"dest_base" : "app_name"
}]

py2exe doesn't import the os module?

So, basically, I'm trying to make my Python 2.7 script into an EXE. Here is my setup.py:
from distutils.core import setup
import py2exe
import os
setup(
options = {
"py2exe":{
"includes": ["os"]
}
},
name = "Anansi CalcPad",
version = "0.35",
description = "Anansi CalcPad is a three-tiered application that provides a journal, calculator, and news aggregator in one.",
author = "Cody Dostal",
author_email = "cody#seafiresoftware.org",
url = "http://seafiresoftware.org/wordpress/anansi-calcpad/",
windows = ["AnansiCalc.py"],
)
If there is indentation problems, it was caused by a bad copy on StackOverflow's part, not in the code.
Here is the error:
Traceback (most recent call last):
File "AnansiCalc.py", line 3, in <module>
ImportError: No module named os
What is wrong?

Categories

Resources