I am trying to convert a py file to an exe.
Here is the code for my setupfile
from distutils.core import setup
import py2exe
setup(console=["mycode.py"])
When I use cmd, it says:
Import Error: No module named easygui
How do I let py2exe know about the easygui? As well as the numpy and mathplotlib (all are used in mycode.py)
First, use pyinstaller. It is newer and better (though I have used py2exe until switching to pyinstaller) And it seems to have much better recipes for finding your included libs.
But for py2exe, you will need to expand that setup.py a bit more to tell it what to include (since they are probably hidden imports)
setup(
console=["mycode.py"],
options={
"py2exe": {
"includes": ["easygui"],
"bundle_files": 1
},
},
zipfile = None,
)
If this fails to build, then easygui is not in your PYTHONPATH properly. Make sure you are not doing something special in your script to add a pythonpath, which would not be visible to py2exe.
You may need to do a little more work with this file for numpy and matplotlib. See this wiki for help
Relative to the issue of the specific dll's mentioned, I had similar issues but fixed those problems by specifically excluding those in the setup lie so:
setup(
console=['DET14.py'],
options={
'py2exe': {
'packages' : ['matplotlib', 'pytz'],
'dll_excludes':['MSVCP90.DLL',
'libgdk-win32-2.0-0.dll',
'libgobject-2.0-0.dll',
'libgdk_pixbuf-2.0-0.dll'],
'includes':['scipy.sparse.csgraph._validation',
'scipy.special._ufuncs_cxx']
}
},
data_files=matplotlib.get_py2exe_datafiles()
)`
I would say try adding that exclude to your setup statement.
Related
To use pandas lib, I make a simple python program.
It works well when I run the *.py file. After I pack all the files into a exe with py2exe, I double click the exe to run it, then I get a message in the command line window:
Please install lxml if you want to use 'options' class.
Does it mean lxml lib is not packed into my exe correctly? Anyone know how to solve the problem?
My setup.py is:
from distutils.core import setup
import py2exe
setup(console=['app.py'],
options={
'py2exe': {
'includes': ['lxml.etree',
'lxml._elementpath',
'numexpr'],
}
}
)
Then the new problem comes:numexpr not found. cannot use engine = numexpr for query/eval if numexpr is not installed.
I've looked everywhere. Stackoverflow, various messageboards, the py2exe website, the pyinstaller website...nothing is helping. Including the selenium module, particularly making an exe that supports firefox, seems impossible. I am starting to pull out my hair because using either py2exe and pyinstaller is becoming a huge headache.
Both py2exe and pyinstaller have their share of problems.
My goal is to make one single exe file, without any extra directories, so that other people can use my program if they do not have python/modules.
With py2exe, if I create a setup.py file as such
from distutils.core import setup
import py2exe
setup(
name='Ask Alfred',
data_files = [('Drivers', ['Drivers/chromedriver.exe',
'Drivers/webdriver.xpi','Drivers/webdriver_prefs.json'])],
version='1.0',
description='Find emails fast!',
author='Me',
windows=[{'script': 'alphy.py'}],
options={
'py2exe':
{
'skip_archive': False,
'optimize': 2,
}
}
)
it will create an exe in the dist folder and a Drivers folder with the files I need, however, if I try to run the exe it will tell me that it could not find these files (because it is looking for them in the library.zip folder). On top of that, my GUI looks terrible (fonts are now grey instead of black and images with white backgrounds now have grey backgrounds).
With pyinstaller, if I use the "--onefile" flag when creating the exe it does not work at all/neither firefox nor chrome gets started.
With either, I only get workable results if I choose to not archive/not make one file. In that case, pyinstaller delivers a fully working solution.
Try this:
options={
'py2exe':
{
'skip_archive': True,
'unbuffered': True,
'bundle_files': 2, #assuming you dont want to include the python interpreter
'optimize': 2,
},
},
zipfile = None
I'm compiling a python script to .exe via py2exe. I originally started compiling it and the entire program ran fine aside from the Word document creation.
My logfile would give me: ERROR: Could not close or save Word Document 'docName.docx' :, so where I am supposed to be supplied an error message - I am not.
I started to think it could do with the missing modules in py2exe, reported as:
The following modules appear to be missing
['ICCProfile', '_imaging_gif', '_scproxy', '_sysconfigdata']
And then I noticed many people didn't care too much about these errors.
I looked in the docx package, located in C:\Python27\Lib\site-packages\docx-0.2.4-py2.7.egg\, as installed by easy_install, and saw this docx-templates folder, which I am certain was not imported, so I wrote my setup.py referencing the docx-template I put in my build folder manually:
from distutils.core import setup
from glob import glob
import os
import py2exe
#templatePath = 'C:/Python27/Lib/site-packages/docx-0.2.4-py2.7.egg/docx-template'
setup(
console=['xmlpolicydocx-0.4.py'],
options={
'py2exe':
{
'includes': ['docx', 'PIL', 'lxml.etree', 'lxml._elementpath', 'gzip']
}
},
packages=[
'docx-template'
],
package_data={
'docx-template': [
'_rels/*',
'docProps/*',
'word/theme/*.xml',
'word/*.xml'
],
},
)
Yet I still have no luck in getting docx to work when compiled via py2exe. Any suggestions or methods of debugging I can take to take another look at solving this problem?
I'm trying to use py2exe to convert my .pyw to executable file, and
encountered this error - "ImportError: No module named matplotlib.python-dateutil"
I've installed dateutil before trying to convert this .pyw to .exe,
and .pyw file itself worked fine and produced the expected output,
but I didn't manage to get the .exe file.
I also have tried put a copy of python-dateutil inside matplotlib folder but still did not solve the problem.
I'm using Python 2.7 and python-dateutil 2.2.
This is my setup.pyw. copied from (http://www.py2exe.org/index.cgi/MatPlotLib)
from distutils.core import setup
import py2exe
import matplotlib
matplotlibdatadir = matplotlib.get_data_path()
matplotlibdata = findall(matplotlibdatadir)
matplotlibdata_files = [] for f in matplotlibdata:
dirname = os.path.join('matplotlibdata', f[len(matplotlibdatadir)+1:])
matplotlibdata_files.append((os.path.split(dirname)[0], [f]))
setup(
windows = ['graph.pyw'],
options = {
'py2exe': {
'packages' : ['matplotlib', 'pytz'],
}
},
#data_files = matplotlibdata_files
data_files = matplotlib.get_py2exe_datafiles() )
Appreciate feedback and ideas..thank you very much in advance
I think you need to put matplotlib.python-dateutil in the packages list:
'packages' : ['matplotlib', 'matplotlib.python-dateutil', 'pytz'],
When this hasn't fixed similar hassles for me, I've sometimes found that you need to wildcard submodules:
'packages' : ['matplotlib', 'matplotlib.python-dateutil.*', 'pytz'],
YMMV on that one.
I have a Python 2.7.2 program with wxPython 2.8.12 and comtypes 0.6.2 dependencies on a win XP SP3 machine. I am using py2exe to produce windows distributables with the following setup:
setup(
options = {
"py2exe": {
"packages": ['wx.lib.pubsub']
}
},
windows = [
{
"script" : "entry.py",
}
],
data_files=[("bitmaps", ["../resources/icons/app_big.png",
"../resources/icons/app_medium.png",
"../resources/icons/app_small.png",
"../resources/icons/app_small_new.png",
"../resources/icons/app_small_bad.png",
"../resources/icons/cross_hover.png",
"../resources/icons/cross.png",
"../resources/icons/delete.png",
"../resources/icons/refresh.png",])]
)
I am also using the IEHtmlWindow control.
What is happening is that whenever I issue the command at the Python console, py2exe runs for a second with the following output:
running py2exe
* searching for required modules *
and then appears to hang indefinitely until I press Ctr+z.
I have tracked down the problem to the import :
from wx.lib.iewin import IEHtmlWindow
which seems to be causing the problem.
Any suggestions?
Solved, the problem was that comtypes generated a very large module file which was taking too much time to parse by py2exe:
comtypes.gen._3050F1C5_98B5_11CF_BB82_00AA00BDCE0B_0_4_0
The workaround is to patch py2exe source code (ver 0.6.9) as pointed out by Erez Bibi in his post:
http://groups.google.com/group/wxPython-users/browse_thread/thread/52deb8a0bc1cdc5e
and now with the setup file
options={
"py2exe": {
'packages': ['wx.lib.pubsub'],
'includes': ['comtypes.gen._3050F1C5_98B5_11CF_BB82_00AA00BDCE0B_0_4_0'],
'skip_scan': ['comtypes.gen._3050F1C5_98B5_11CF_BB82_00AA00BDCE0B_0_4_0']
}
},
everything seems to be working great once again.
There are actually two versions of IEHtmlWindow. You can try importing the other one:
from wx.lib.iewin_old import IEHtmlWindow
And see if that works. If it does, awesome. If not, then you should probably go cross-post to the py2exe mailing list and/or the wxPython mailing list.