cx-freeze doesn't find all dependencies - python
I have a python script (2.7) with some "interesting" imports at the top. I initially wanted to use py2exe to compile this into an exe that I can more easily distribute (py2exe doesn't find all dependencies).
I have given up and am trying to use cx-freeze instead. But, I am having problem there as well. The problems seem to be libraries I have added to Python (jinja2 and restkit). I see them in my python directory ./Lib/site-packages/Jinja2-2.6-py2.7.egg/jinja2 and here ./Lib/site-packages/restkit-4.2.1-py2.7.egg/restkit.
Here are the imports in my script:
import datetime
from jinja2 import Environment, PackageLoader
from optparse import OptionParser
from datetime import date, timedelta
from restkit import Resource, BasicAuth, request
I am using a setup.py with cx-freeze. Here is the setup.py:
from cx_Freeze import setup, Executable
packages = ["restkit", "jinja2" , "restkit.client" ]
includes = []
includefiles = []
eggsacutibull = Executable(
script = "myScript.py",
initScript = None,
targetName = "myScript.exe",
compress = True,
copyDependentFiles = True,
appendScriptToExe = False,
appendScriptToLibrary = False,
icon = None
)
setup(
name = "myScript",
version = "0.1",
author = 'vickery',
description = "MyScript description",
options = {"build_exe": {"includes":includes, "include_files": includefiles, "packages": packages}},
executables = [eggsacutibull]
)
I run cxfreeze like this:
cxfreeze myScript.py --target-dir exe
I get this in my build:
Missing modules:
? __pypy__ imported from jinja2.debug
? http_parser.http imported from restkit.client
? jinja2._debugsupport imported from jinja2.debug
? jinja2._markupsafe._speedups imported from jinja2._markupsafe
? jinja2.debugrenderer imported from jinja2.debug
? markupsafe imported from jinja2.utils
? pretty imported from jinja2.utils
? socketpool imported from restkit.conn
And, when I try to run the exe, I get this:
Traceback (most recent call last):
File "c:\Python27\lib\site-packages\restkit-4.2.1-py2.7.egg\restkit\__init__.py", line 9, in <module>
from restkit.conn import Connection
File "c:\Python27\lib\site-packages\restkit-4.2.1-py2.7.egg\restkit\conn.py", line 14, in <module>
from socketpool import Connector
ImportError: No module named socketpool
Traceback (most recent call last):
File "c:\Python27\lib\site-packages\cx_Freeze\initscripts\Console.py", line 27, in <module>
exec code in m.__dict__
File "myScript.py", line 12, in <module>
ImportError: cannot import name Resource
Edit:
I am now running cxfreeze correctly like this:
python setup.py build
I also added socketpool to my setup.py:
packages = [ "restkit", "jinja2" , "restkit.client", "restkit.conn", "socketpool" ]
But, when I try to build now, I get a build error:
$ python setup.py build
running build
running build_exe
Traceback (most recent call last):
File "setup.py", line 32, in <module>
executables = [eggsacutibull]
File "c:\python27\lib\site-packages\cx_Freeze\dist.py", line 365, in setup
distutils.core.setup(**attrs)
File "c:\python27\lib\distutils\core.py", line 152, in setup
dist.run_commands()
File "c:\python27\lib\distutils\dist.py", line 953, in run_commands
self.run_command(cmd)
File "c:\python27\lib\distutils\dist.py", line 972, in run_command
cmd_obj.run()
File "c:\python27\lib\distutils\command\build.py", line 127, in run
self.run_command(cmd_name)
File "c:\python27\lib\distutils\cmd.py", line 326, in run_command
self.distribution.run_command(command)
File "c:\python27\lib\distutils\dist.py", line 972, in run_command
cmd_obj.run()
File "c:\python27\lib\site-packages\cx_Freeze\dist.py", line 235, in run
freezer.Freeze()
File "c:\python27\lib\site-packages\cx_Freeze\freezer.py", line 570, in Freeze
self.finder = self._GetModuleFinder()
File "c:\python27\lib\site-packages\cx_Freeze\freezer.py", line 325, in _GetModuleFinder
finder.IncludePackage(name)
File "c:\python27\lib\site-packages\cx_Freeze\finder.py", line 534, in IncludePackage
module = self._ImportModule(name, deferredImports)
File "c:\python27\lib\site-packages\cx_Freeze\finder.py", line 274, in _ImportModule
raise ImportError("No module named %r" % name)
ImportError: No module named 'socketpool'
What has me confused here, is, my script compiles just fine. In addition, I can import these modules from a python shell. For example:
$ python
Python 2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import socketpool
>>> from restkit import Resource, BasicAuth, request
>>>
How is python resolving modules that is differnt than cxfreeze?
Edit2:
From python I can do this:
>>> import socketpool
>>> print socketpool.__file__
c:\python27\lib\site-packages\socketpool-0.5.2-py2.7.egg\socketpool\__init__.pyc
Is that a non-standard place to look for a package? Can I used PYTHONPATH to coerce cxfreez into looking there for socketpool?
Thanks
I know this thread is old but I just spent 4 days figuring this out and it might be helpful for someone else so here goes:
The description for include_files option in cx_freeze is misleading. If you want to use the include_files option for build_exe here is an example of how you do that
include_files=[
(r"C:\Python27\Scripts\mk2ifcoremd.dll", "mk2ifcoremd.dll"),
(r"C:\Python27\Scripts\mk2ifportmd.dll", "mk2ifportmd.dll"),
(r"C:\Python27\Scripts\mk2imalloc.dll", "mk2imalloc.dll"),
(r"C:\Python27\Scripts\mk2iomp5md.dll", "mk2iomp5md.dll"),
(r"C:\Python27\Scripts\mk2mmd.dll", "mk2mmd.dll"),]
You must have a list of tuples with an absolute path for the source and ONLY THE FILENAME for the destination.
I ran into trouble with cx_freeze because it did/ does not copy all the required DLLs into the dist directory. So my exe tested fine on my machine but did not work on another machine that did not have Python installed. In order to debug this I had to repeatedly move my Python installation out of the way (renamed C:\Python27 to C:_Python27) and see if there were missing libraries.
Here is an example setup.py file that works for me:
# invoke using:
# python setup.py build
from cx_Freeze import setup, Executable
import sys
import glob
import os
import zlib
import shutil
# Remove the existing folders folder
shutil.rmtree("build", ignore_errors=True)
shutil.rmtree("dist", ignore_errors=True)
########################################
# Here is a list of the Executable options
########################################
#"script": #the name of the file containing the script which is to be frozen
#"initScript": #the name of the initialization script that will be executed before the actual script is executed; this script is used to set up the environment for the executable; if a name is given without an absolute path the names of files in the initscripts subdirectory of the cx_Freeze package is searched
#"base": #the name of the base executable; if a name is given without an absolute path the names of files in the bases subdirectory of the cx_Freeze package is searched
#"path": #list of paths to search for modules
#"targetDir": #the directory in which to place the target executable and any dependent files
#"targetName": #the name of the target executable; the default value is the name of the script with the extension exchanged with the extension for the base executable
#"includes": #list of names of modules to include
#"excludes": #list of names of modules to exclude
#"packages": #list of names of packages to include, including all of the package's submodules
#"replacePaths": #Modify filenames attached to code objects, which appear in tracebacks. Pass a list of 2-tuples containing paths to search for and corresponding replacement values. A search for '*' will match the directory containing the entire package, leaving just the relative path to the module.
#"compress": #boolean value indicating if the module bytecode should be compressed or not
#"copyDependentFiles": #boolean value indicating if dependent files should be copied to the target directory or not
#"appendScriptToExe": #boolean value indicating if the script module should be appended to the executable itself
#"appendScriptToLibrary":#boolean value indicating if the script module should be appended to the shared library zipfile
#"icon": #name of icon which should be included in the executable itself on Windows or placed in the target directory for other platforms
#"namespacePackages": #list of packages to be treated as namespace packages (path is extended using pkgutil)
#"shortcutName": #the name to give a shortcut for the executable when included in an MSI package
#"shortcutDir": #the directory in which to place the shortcut when being installed by an MSI package; see the MSI Shortcut table documentation for more information on what values can be placed here.
MY_TARGET_EXE = Executable(
# what to build
script = "main.py",
initScript = None,
base = 'Win32GUI',
targetDir = r"dist",
targetName = "MyProgram.exe",
compress = True,
copyDependentFiles = True,
appendScriptToExe = False,
appendScriptToLibrary = False,
icon = None
)
########################################
#Here is a list of the build_exe options
########################################
#1) append the script module to the executable
append_script_to_exe=False
#2) the name of the base executable to use which, if given as a relative path, will be joined with the bases subdirectory of the cx_Freeze installation; the default value is "Console"
base="Console"
#3) list of names of files to exclude when determining dependencies of binary files that would normally be included; note that version numbers that normally follow the shared object extension are stripped prior to performing the comparison
bin_excludes=[]
#4) list of names of files to include when determining dependencies of binary files that would normally be excluded; note that version numbers that normally follow the shared object extension are stripped prior to performing the comparison
bin_includes=[]
#5) list of paths from which to exclude files when determining dependencies of binary files
bin_path_excludes=[]
#6) list of paths from which to include files when determining dependencies of binary files
bin_path_includes=[]
#7) directory for built executables and dependent files, defaults to build/
build_exe="dist/"
#8) create a compressed zip file
compressed=False
#9) comma separated list of constant values to include in the constants module called BUILD_CONSTANTS in form <name>=<value>
constants=[]
#10) copy all dependent files
copy_dependent_files=True
#11) create a shared zip file called library.zip which will contain all modules shared by all executables which are built
create_shared_zip=True
#12) comma separated list of names of modules to exclude
excludes = ['_gtkagg', '_tkagg', 'bsddb', 'curses', 'email', 'pywin.debugger',
'pywin.debugger.dbgcon', 'pywin.dialogs', 'tcl',
'Tkconstants', 'Tkinter']
#13) include the icon in the frozen executables on the Windows platform and alongside the frozen executable on other platforms
icon=False
#13) comma separated list of names of modules to include
includes = ['sip', 'matplotlib.backends.backend_wxagg']
#15) list containing files to be copied to the target directory;
# it is expected that this list will contain strings or 2-tuples for the source and destination;
# the source can be a file or a directory (in which case the tree is copied except for .svn and CVS directories);
# the target must not be an absolute path
#
# NOTE: INCLUDE FILES MUST BE OF THIS FORM OTHERWISE freezer.py line 128 WILL TRY AND DELETE dist/. AND FAIL!!!
# Here is a list of ALL the DLLs that are included in Python27\Scripts
include_files=[
(r"C:\Python27\Scripts\mk2ifcoremd.dll", "mk2ifcoremd.dll"),
(r"C:\Python27\Scripts\mk2ifportmd.dll", "mk2ifportmd.dll"),
(r"C:\Python27\Scripts\mk2imalloc.dll", "mk2imalloc.dll"),
(r"C:\Python27\Scripts\mk2iomp5md.dll", "mk2iomp5md.dll"),
(r"C:\Python27\Scripts\mk2mmd.dll", "mk2mmd.dll"),
(r"C:\Python27\Scripts\mk2_avx.dll", "mk2_avx.dll"),
(r"C:\Python27\Scripts\mk2_blacs_ilp64.dll", "mk2_blacs_ilp64.dll"),
(r"C:\Python27\Scripts\mk2_blacs_intelmpi_ilp64.dll", "mk2_blacs_intelmpi_ilp64.dll"),
(r"C:\Python27\Scripts\mk2_blacs_intelmpi_lp64.dll", "mk2_blacs_intelmpi_lp64.dll"),
(r"C:\Python27\Scripts\mk2_blacs_lp64.dll", "mk2_blacs_lp64.dll"),
(r"C:\Python27\Scripts\mk2_blacs_mpich2_ilp64.dll", "mk2_blacs_mpich2_ilp64.dll"),
(r"C:\Python27\Scripts\mk2_blacs_mpich2_lp64.dll", "mk2_blacs_mpich2_lp64.dll"),
(r"C:\Python27\Scripts\mk2_blacs_msmpi_ilp64.dll", "mk2_blacs_msmpi_ilp64.dll"),
(r"C:\Python27\Scripts\mk2_blacs_msmpi_lp64.dll", "mk2_blacs_msmpi_lp64.dll"),
(r"C:\Python27\Scripts\mk2_cdft_core.dll", "mk2_cdft_core.dll"),
(r"C:\Python27\Scripts\mk2_core.dll", "mk2_core.dll"),
(r"C:\Python27\Scripts\mk2_def.dll", "mk2_def.dll"),
(r"C:\Python27\Scripts\mk2_intel_thread.dll", "mk2_intel_thread.dll"),
(r"C:\Python27\Scripts\mk2_mc.dll", "mk2_mc.dll"),
(r"C:\Python27\Scripts\mk2_mc3.dll", "mk2_mc3.dll"),
(r"C:\Python27\Scripts\mk2_p4n.dll", "mk2_p4n.dll"),
(r"C:\Python27\Scripts\mk2_pgi_thread.dll", "mk2_pgi_thread.dll"),
(r"C:\Python27\Scripts\mk2_rt.dll", "mk2_rt.dll"),
(r"C:\Python27\Scripts\mk2_scalapack_ilp64.dll", "mk2_scalapack_ilp64.dll"),
(r"C:\Python27\Scripts\mk2_scalapack_lp64.dll", "mk2_scalapack_lp64.dll"),
(r"C:\Python27\Scripts\mk2_sequential.dll", "mk2_sequential.dll"),
(r"C:\Python27\Scripts\mk2_vml_avx.dll", "mk2_vml_avx.dll"),
(r"C:\Python27\Scripts\mk2_vml_def.dll", "mk2_vml_def.dll"),
(r"C:\Python27\Scripts\mk2_vml_mc.dll", "mk2_vml_mc.dll"),
(r"C:\Python27\Scripts\mk2_vml_mc2.dll", "mk2_vml_mc2.dll"),
(r"C:\Python27\Scripts\mk2_vml_mc3.dll", "mk2_vml_mc3.dll"),
(r"C:\Python27\Scripts\mk2_vml_p4n.dll", "mk2_vml_p4n.dll"),
# These next DLLs appear to be copied correctly or as needed by cxfreeze...
# (r"C:\Python27\Scripts\libgcc_s_sjlj-1.dll", "libgcc_s_sjlj-1.dll"),
# (r"C:\Python27\Scripts\libgfortran-3.dll", "libgfortran-3.dll"),
# (r"C:\Python27\Scripts\libssp-0.dll", "libssp-0.dll"),
# (r"C:\Python27\Scripts\libstdc++-6.dll", "libstdc++-6.dll"),
# (r"C:\Python27\Scripts\pythoncom27.dll", "pythoncom27.dll"),
# (r"C:\Python27\Scripts\pywintypes27.dll", "pywintypes27.dll"),
]
#,("Microsoft.VC90.MFC", mfcfiles), ]
#16) include the script module in the shared zip file
include_in_shared_zip=True
#17) include the Microsoft Visual C runtime DLLs and (if necessary) the manifest file required to run the executable without needing the redistributable package installed
include_msvcr =False
#18) the name of the script to use during initialization which, if given as a relative path, will be joined with the initscripts subdirectory of the cx_Freeze installation; the default value is "Console"
init_script=""
#19) comma separated list of packages to be treated as namespace packages (path is extended using pkgutil)
namespace_packages=[]
#20) optimization level, one of 0 (disabled), 1 or 2
optimize=0
#21) comma separated list of packages to include, which includes all submodules in the package
packages = ['numpy.linalg']
#22) comma separated list of paths to search; the default value is sys.path
path = []
#23) Modify filenames attached to code objects, which appear in tracebacks. Pass a comma separated list of paths in the form <search>=<replace>. The value * in the search portion will match the directory containing the entire package, leaving just the relative path to the module.
replace_paths=[]
#24) suppress all output except warnings
silent=False
#25) list containing files to be included in the zip file directory; it is expected that this list will contain strings or 2-tuples for the source and destination
zip_includes=[]
setup(
version = "0.0",
description = "This is a program that works",
author = "Your Name Here",
name = "A text description",
options = {"build_exe": {
# "append_script_to_exe": append_script_to_exe,
# "base": base,
# "bin_excludes": bin_excludes,
# "bin_includes": bin_includes,
# "bin_path_excludes": bin_path_excludes,
# "bin_path_includes": bin_path_includes,
"build_exe": build_exe,
"compressed": compressed,
# "constants": constants,
"copy_dependent_files": copy_dependent_files,
# "create_shared_zip": create_shared_zip,
"excludes": excludes,
# "icon": icon,
"includes": includes,
"include_files": include_files,
# "include_in_shared_zip":include_in_shared_zip,
# "include_msvcr": include_msvcr,
# "init_script": init_script,
# "namespace_packages": namespace_packages,
# "optimize": optimize,
"packages": packages,
"path": path,
# "replace_paths": replace_paths,
# "silent": silent,
# "zip_includes": zip_includes,
}
},
executables = [MY_TARGET_EXE]
)
In case anyone ever runs across this, the problem seemed to be that cxfreeze does not play nicely with eggs. Once I extracted the code out of the egg (renamed it to a zip and unzipped), and, created for example: Python27\Lib\site-packages\socketpool for the code, then ran the build, things seemed to work fine.
Seems like a hack. Time for a shower.
Related
Compile a Python project Windows
I have the following directory structure to my python project: eplusplus/ | | ----__main__.py ----model/ ----exception/ ----controller/ ----view/ The directories: model, exception, controller and view each one has its __init__.py. When I run the program at my machine I always use this following command: py -m eplusplus. But when I tried to use py2exe or pytinstaller the the points to: permission denied. For what I found, this is because its a directory I trying to compile, but when I compiled the __main__.py it compiled normally, but when I try to execute it says: Error! No eplusplus module founded! I have no setup.py file and I don't know how they worked.
After some very intensive research and error and try I succeeded by doing this: I added an empty __init__.py at the eplusplus folder Out of the eplusplus folder, I had to write a compilation.py file (the file doesn't necessary must have this) to include all libraries I was using (I will post the file at the end of this answer) Finally, at the PowerShell, all I have to type was py compilation.py py2exe Thanks for all that tried to help me! compilation.py file: #To compile we need to run: python compilation.py py2exe from distutils.core import setup from glob import glob import os import py2exe import pyDOE VERSION=1.0 includes = [ "sip", "PyQt5", "PyQt5.QtCore", "PyQt5.QtGui", "PyQt5.QtWidgets", "scipy.linalg.cython_blas", "scipy.linalg.cython_lapack", "pyDOE" ] platforms = ["C:\\Python34\\Lib\\site-packages\\PyQt5\\plugins" + "\\platforms\\qwindows.dll"] dll = ["C:\\windows\\syswow64\\MSVCP100.dll", "C:\\windows\\syswow64\\MSVCR100.dll"] media = ["C:\\Users\\GUSTAVO\\EPlusPlus\\media\\title.png", "C:\\Users\\GUSTAVO\\EPlusPlus\\media\\icon.png"] documents = ["C:\\Users\\GUSTAVO\\EPlusPlus\\docs\\"+ "documentacaoEPlusPlus.pdf"] examples = ["C:\\Users\\GUSTAVO\\EPlusPlus\\files\\"+ "\\examples\\baseline2A.idf", "C:\\Users\\GUSTAVO\\EPlusPlus\\files\\"+ "\\examples\\vectors.csv", "C:\\Users\\GUSTAVO\\EPlusPlus\\files\\"+ "\\examples\\BRA_SC_Florianopolis.838970_INMET.epw"] datafiles = [("platforms", platforms), ("", dll), ("media", media), ("docs", documents), ("Examples", examples)] imageformats = glob("C:\\Python34\\Lib\\site-packages\\PyQt5\\"+ "plugins\\imageformats\\*") datafiles.append(("imageformats", imageformats)) setup( name="eplusplus", version=VERSION, packages=["eplusplus"], url="", license="", windows=[{"script": "eplusplus/__main__.py"}], scripts=[], data_files = datafiles, options={ "py2exe": { "includes": includes, } } )
keyring module is not included while packaging with py2exe
I am making an app using python 2.7 on windows and keyring-3.2.1 . In my python code on eclipse, I used import keyring keyring.set_password("service","jsonkey",json_res) json_res= keyring.get_password("service","jsonkey") is working fine as I am storing json response in keyring. But, when I converted python code into exe by using py2exe, it shows import error keyring while making dist. Please suggest how to include keyring in py2exe. Traceback (most recent call last): File "APP.py", line 8, in <module> File "keyring\__init__.pyc", line 12, in <module> File "keyring\core.pyc", line 15, in <module> File "keyring\util\platform_.pyc", line 4, in <module> File "keyring\util\platform.pyc", line 29, in <module> AttributeError: 'module' object has no attribute 'system' platform_.py code is : from __future__ import absolute_import import os import platform def _data_root_Windows(): try: root = os.environ['LOCALAPPDATA'] except KeyError: # Windows XP root = os.path.join(os.environ['USERPROFILE'], 'Local Settings') return os.path.join(root, 'Python Keyring') def _data_root_Linux(): """ Use freedesktop.org Base Dir Specfication to determine storage location. """ fallback = os.path.expanduser('~/.local/share') root = os.environ.get('XDG_DATA_HOME', None) or fallback return os.path.join(root, 'python_keyring') # by default, use Unix convention data_root = globals().get('_data_root_' + platform.system(), _data_root_Linux) platform.py code is: import os import sys # While we support Python 2.4, use a convoluted technique to import # platform from the stdlib. # With Python 2.5 or later, just do "from __future__ import absolute_import" # and "import platform" exec('__import__("platform", globals=dict())') platform = sys.modules['platform'] def _data_root_Windows(): try: root = os.environ['LOCALAPPDATA'] except KeyError: # Windows XP root = os.path.join(os.environ['USERPROFILE'], 'Local Settings') return os.path.join(root, 'Python Keyring') def _data_root_Linux(): """ Use freedesktop.org Base Dir Specfication to determine storage location. """ fallback = os.path.expanduser('~/.local/share') root = os.environ.get('XDG_DATA_HOME', None) or fallback return os.path.join(root, 'python_keyring') # by default, use Unix convention data_root = globals().get('_data_root_' + platform.system(), _data_root_Linux)
The issue you're reporting is due to an environment that contains invalid modules, perhaps from an improper installation of one version of keyring over another. You will want to ensure that you've removed remnants of the older version of keyring. In particular, make sure there's no file called keyring\util\platform.* in your site-packages. After doing that, however, you'll encounter another problem. Keyring loads its backend modules programmatically, so py2exe won't detect them. To work around that, you'll want to add a 'packages' declaration to your py2exe options to specifically include the keyring.backends package. I invoked the following setup.py script with Python 2.7 to convert 'app.py' (which imports keyring) to an exe: from distutils.core import setup import py2exe setup( console=['app.py'], options=dict(py2exe=dict( packages='keyring.backends', )), ) The resulting app.exe will import and invoke keyring.
Using psyco with py2exe?
In my main script, lets call this MyScript.py, I have it like this: import psyco psyco.full() And then my setup.py looks like this: from distutils.core import setup import py2exe, sys, os, glob sys.argv.append('py2exe') import psyco #speed up compilation psyco.full() def find_data_files(source,target,patterns): """Locates the specified data-files and returns the matches in a data_files compatible format. source is the root of the source data tree. Use '' or '.' for current directory. target is the root of the target data tree. Use '' or '.' for the distribution directory. patterns is a sequence of glob-patterns for the files you want to copy. """ if glob.has_magic(source) or glob.has_magic(target): raise ValueError("Magic not allowed in src, target") ret = {} for pattern in patterns: pattern = os.path.join(source,pattern) for filename in glob.glob(pattern): if os.path.isfile(filename): targetpath = os.path.join(target,os.path.relpath(filename,source)) path = os.path.dirname(targetpath) ret.setdefault(path,[]).append(filename) return sorted(ret.items()) setup( name="MyScript", version="1.0", description="a script that does something", author="Keelx", data_files=find_data_files('.','',[ 'gfx/*', 'data/*', ]), options={'py2exe': {'bundle_files': 1,'optimize': 2}}, windows=[{'script': "MyScript.py"}], zipfile=None, ) It creates a 'dist' folder, with the executable, a win9x executable, and the gfx and data folders next to the executable. However, when I run it it points me to a log which reads: Traceback (most recent call last): File "MyScript.py", line 16, in File "zipextimporter.pyo", line 82, in load_module File "psyco__init__.pyo", line 64, in WindowsError: [Error 3] The system cannot find the path specified: 'C:\Documents and Settings\Keelx\Desktop\MyScriptFolder\dist\MyScript.exe\psyco\_psyco.pyd' It would seem that the psyco module is not being put into the executable. I've been searching, and I haven't found a working solution to get py2exe to copy psyco over. And please refrain from posting solutions along the lines of 'don't use py2exe'. Thank you in advance whomever can help me out here.
Hunting down py2exe errors appears to be an art to me. That said, I will at least offer something to try. I py2exe'ed a psyco enabled python script and tossed it in the includes part of the setup. Thats the only part that looks different between your setup and my old one. options = {'py2exe': {'packages': [ 'IPython'], 'includes': ["psyco"], } } Also I was never able to enable optimize. It always caused random errors. Best to leave that one off in my experience. I think it was matplotlib that caused those errors. Hope this helps, Cheers,
py2exe bundle_files=1 or 2 fails
My application uses QGraphicsPixmapItem, and to make it able to load jpeg files I've placed qjpeg4.dll under 'imageformats' subdirectory in the 'dist' directory. It works, but only as long as 'bundle_files' option is set to 3. If I set it to 1 or 2, qt4 (pyqt4) is no longer able to find needed dlls, and so QGraphicsPixmapItems is not visible. setup.py: from distutils.core import setup import py2exe setup( options = {'py2exe': {'bundle_files': 1}}, description = "", name = "name", windows = ["mainwindow.py"], zipfile=None, )
You should be able to convince py2exe to include the dll by using: setup( # other options, data_files=[('imageformats', 'qjpeg4.dll'), #other options ) For future reference, data_files should look like this (afaik): data_files = [ (dir1, [file1, file2, ...]), (dir2, [file3, file4, ...]), ...] EDIT 1: You could try using a directory structure like this (source): yourapp.exe [qt.conf] (optional? see lower down) plugins/ imageformats/ qjpeg4.dll And if that doesn't work, here suggests using a qt.conf file that looks like this: [Paths] Plugins = <directory containing the imageformats directory> Which apparently should work fine so long as the core dll QtCore4.dll has been included correctly (as it needs this .dll to interpret your qt.conf file).
How to compile python code that uses boto to access S3?
I'm trying to compile a simple Python program, that uploads files to an S3 bucket using the boto package, in to a single, redistributable .exe file. I'm open to any compilation method. So far I've tried both bbfreeze and py2exe and both yield the same results. The code in question that causes trouble looks like this: import boto #...snip... fname_base = os.path.basename(fname) s3 = boto.connect_s3(aws_access_key_id=_aws_key, aws_secret_access_key=_aws_secret_key, is_secure=False); bucket = s3.get_bucket(_bucket) key = bucket.new_key(fname_base) key.set_contents_from_filename(fname) Compiled with either executable bundling utility and run I get: Traceback (most recent call last): File "s3stash.py", line 238, in <module> sys.exit(main()) File "s3stash.py", line 225, in main push_file_to_s3(f, options) File "s3stash.py", line 160, in push_file_to_s3 _push_with_boto(fname) File "s3stash.py", line 148, in _push_with_boto s3 = boto.connect_s3(aws_access_key_id=_aws_key, aws_secret_access_key=_aws_secret_key, is_secure=False); File "boto\__init__.pyo", line 104, in connect_s3 File "zipextimporter.pyo", line 82, in load_module File "boto\s3\connection.pyo", line 27, in <module> File "zipextimporter.pyo", line 82, in load_module File "boto\utils.pyo", line 55, in <module> File "email\__init__.pyo", line 79, in __getattr__ ImportError: No module named multipart I'm using ActiveState Python 2.6 on Windows XP SP3. The boto package was installed with: easy_installer --always-unzip boto I used the --always-unzip option based on the information found here about py2exe having issues with the egg files that were unpacked. Unfortunately the error I get is the same when I use bb-freeze to build the executable. The output from py2exe includes, near the end, the following bit of information: The following modules appear to be missing ['_scproxy', 'email.Encoders', 'email.MIMEBase', 'email.MIMEMultipart', 'email.MIMEText', 'email.Utils', 'simplejson'] Which lends some hints. I tried methods suggested in other posts to SO where the -i option was recommended when compiling with py2exe and unfortunately nothing helped. In those other questions the users were doing their own explicit inclusion of of the email sub-modules. I could not figure how to adapt those solutions to my case unfortunately and just adding them with -i didn't stop py2exe from warning me of the missing modules, or the resulting bundled exe from failing with the missing module error. Can someone help me get this code bundled for redistribution?
I actually got this to work. The answer was to ditch boto and use the poster library instead. I still use boto to generate a signed policy and the necessary form fields for POST I do via poster, but the actual executable that does the POST only includes poster now. With just poster in the mix, py2exe doesn't have any issues creating a standalone executable for me for redistribution.
I know this is an old question, but I had the same problem and fixed it while still using py2exe and py2app. Just use the 'packages' option instead of the 'includes' option in your setup.py: extra = {} mainscript = "foo/__main__.py" if is_os_x(): extra["setup_requires"] =['py2app'] extra["app"] = [mainscript] extra["options"] = { "py2app": { "packages": ['email'], } } elif is_windows(): extra["setup_requires"] =['py2exe'] extra['console'] = [mainscript] extra['options'] = {'py2exe': { # Includes that py2exe doesn't include automatically 'packages': ['email'], } } setup( # snip ** extra ) Hope that helps.
I've managed to create working exe with boto & py2exe Add to your script.py from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText Next error is with HTTPS connection, it seems that py2exe is "hiding" cert file somehow.. The way to fix this is 1) use HTTP OR 2) dont check certs 1) HTTP conn = boto.connect_dynamodb( aws_access_key_id = ' ', aws_secret_access_key = ' ', is_secure = False) "is_secure = False" is crutial 2) DONT CHECK CERTS conn = boto.connect_dynamodb( aws_access_key_id = ' ', aws_secret_access_key = ' ', is_secure = True, validate_certs = False) "validate_certs = False" is crutial If someone figures out how to fix error in cert validation, please reply !