My question is rather simple: if I try to build my .exe using:
python setup.py py2exe
Python just executes my main file, starting my application, however py2exe doesn't try to build it. Meaning: it does the same as if I'd do:
python setup.py
I guess something is wrong with the distutil?
Anybody already encountered this problem?
py2exe is installed (I reinstalled it, hoping it'd fix it).
My Code:
from testmain import *
from Initfile import *
import math
import py2exe
import matplotlib
import PyQt4
import numpy
from distutils.core import setup
setup(
windows=['Initfile.py'],
data_files=[("GUI", ["testmain.ui"]),*matplotlib.get_py2exe_datafiles()],
options = {
'py2exe': {
'includes' : ['math','py2exe','numpy','matplotlib','PyQt4']
}
}
)
Well the error isn't within distutil, it seems when one imports the entry point itself (in my case Initfile.py) pyexe isnt executing.
So the solution is: remove the line from Initfile import *
Related
I have tried to compile my program into an exe with py2exe. Unfortunately, as I am using win32com to copy charts from Excel and embed them into PowerPoint using (Shapes.PasteSpecial(ppPasteOLEObject), I constantly get this error:
File "win32com\client\__init__.pyc", line 170, in __getattr__
AttributeError: ppPasteOLEObject`.
Googling hasn't really helped. The script works perfectly when I run it in python, so I know the problem is with win32com. Using makepy.py to include typelibs also didn't help, but maybe my setup.pyis just wrong. So here it is:
import sys
from distutils.core import setup
import py2exe
from glob import glob
from os.path import normpath
import matplotlib
sys.setrecursionlimit(5000)
data_files=[("Microsoft.VC90.CRT",glob(normpath(
r'C:/Program Files/Microsoft Visual Studio 9.0/VC/redist/x86/Microsoft.VC90.CRT/*.*'))),
("images",glob(normpath("images/*.PNG"))),
("ppttemplate",glob(normpath("ppttemplate/*.pptx")),
(".",normpath("C:/windows/system32/ole32.dll")),
(".",normpath("C:/Anaconda2/envs/py27/Library/bin/MSVCP90.dll")))
]
data_files.extend(matplotlib.get_py2exe_datafiles())
setup(
data_files=data_files,
console=['Main.py'],
options={"py2exe":{"includes":["lxml.etree","lxml._elementpath","gzip",
"sip","PyQt4.QtGui","PyQt4.QtCore","matplotlib"],
"excludes":["Tkinter"],
"typelibs":[('{2DF8D04C-5BFA-101B-BDE5-00AA0044DE52}', 0, 2, 8),
('{00020430-0000-0000-C000-000000000046}', 0, 2, 0)]
}
}
)
Thanks in advance for your help!
Got it! One just needs to inlude the relevant dlls and set skip_archive=True... (I included everything that py2exe was complaining about).
By adding:
sys.path.append("C:\\Program Files\\Microsoft VisualStudio9.0\\VC\\redist\\x86\\Microsoft.VC90.CRT")
sys.path.append("C:\\windows\\system32")
before the data_files line and adding all the system32 to data_files and adding skip_archive=True inside py2exe: it worked!
Hopefully it functions on different computers as well...
The guide I used was on the website of [py2exe] (http://www.py2exe.org/index.cgi/IncludingTypelibs)!
I've created a program that pulls information from routers using SNMP (via PySNMP module). The application works great and I now what to compile it into a standalone application so that I can distribute it to my co-workers. However, after trying both Py2exe and PyInstaller, I've been unsuccessful in compiling a working application. I have searched the internet (a lot!) trying to find an example of someone who has successfully been able to compile their PySNMP application, but haven't been able to find anyway. Is there a better way to compile this or am I just doing it wrong?
These are the modules I've imported:
from Tkinter import *
import tkMessageBox
from pysnmp.entity.rfc3413.oneliner import cmdgen
This is the setup.py I've created for Py2exe:
from distutils.core import setup
import py2exe
setup( console = [
{ "script": "RSSIChecker.py",
}],
options = {
"py2exe":{
'includes': [
'pysnmp.smi.mibs.*',
'pysnmp.smi.mibs.instances.*'
]
}
}
)
Any suggestions?
With the following setup.py, a pysnmp-based app can be packaged with py2exe right out of the box (see line 101 and below). There are also some additional modules added implicitly into py2exe packaging as they are used by the app, not pysnmp itself.
I am trying to make a windows executable from a python script that uses matplotlib and it seems that I am getting a common error.
File "run.py", line 29, in
import matplotlib.pyplot as plt File "matplotlib\pyplot.pyc", line 95, in File "matplotlib\backends__init__.pyc", line
25, in pylab_setup ImportError: No module named backend_tkagg
The problem is that I didn't found a solution while googling all over the internet.
Here is my setup.py
from distutils.core import setup
import matplotlib
import py2exe
matplotlib.use('TkAgg')
setup(data_files=matplotlib.get_py2exe_datafiles(),console=['run.py'])
First, the easy question, is that backend installed? On my Fedora system I had to install it separately from the base matplotlib.
At a Python console can you:
>>> import matplotlib.backends.backend_tkagg
If that works, then force py2exe to include it. In your config:
opts = {
'py2exe': { "includes" : ["matplotlib.backends.backend_tkagg"] }
}
If you are using py2exe it doesn't handle .egg formatted Python modules. If you used easy_install to install the trouble module then you might only have the .egg version. See the py2exe site for more info on how to fix it.
http://www.py2exe.org/index.cgi/ExeWithEggs
This works well
from distutils.core import setup
import py2exe, sys, os
import matplotlib
sys.setrecursionlimit(12000)
sys.argv.append('py2exe')
setup(
options = {
"py2exe" : {
"bundle_files":3,
"compressed":True,
"includes" : ["matplotlib.backends.backend_tkagg"]
}
},
windows = [{"script": "script.py"}],
zipfile = None,
data_files=matplotlib data_files = matplotlib.get_py2exe_datafiles(),
)
Run the following command to install the backend_tkagg
For centos -- sudo yum install python-matplotlib-tk
This should work.
I'm trying to use py2exe and right now I'm just having trouble building the samples and tutorials that come with py2exe. I run setup.py and that goes fine but when I try to run the exe that is created I get the "LoadLibrary(pythondll) failed" error. I haven't moved the exe from the dist directory and I see that python27.dll is in that dist directory. Does anyone know what might be happening?
In case it matters I'm running 32 bit python 2.7 with the corresponding 32 bit python 2.7 py2exe on windows 7.
Thanks
The test.py file just contains
print "test"
Here's my setup.py based off what Kirk wrote:
from distutils.core import setup
import py2exe
import sys
from glob import glob
project_folder = r'C:\\Python27\\Lib\site-packages\\py2exe\\samples\\test\\'
data_files = [
("dlls", glob(project_folder + r'dlls\\*.dll'))
,("pyds", glob(project_folder + r'pyds\\*.pyd'))
]
options = { }
setup(
name='test'
,options = options
,zipfile = None
,data_files=data_files
,console=['test.py']
)
You'll want to specifically include the python27.dll file. If you're including multiple things, use glob and a data files array like below to get the best results with py2exe. For this example, create a Dll folder and put python27.dll in there.
from distutils.core import setup
import py2exe
import sys
from glob import glob
data_files = [
("Stuff", glob(r'C:\projectfolder\Stuff\*.*'))
,("dlls", glob(r'C:\projectfolder\dlls\*.dll'))
,("pyds", glob(r'C:\projectfolder\pyds\*.pyd'))
]
options = { }
setup(
name='ProjectName'
,options = options
,zipfile = None
,data_files=data_files
,console=['projectname.py']
)
I know this is a pretty old question, but I had a similar problem.
I had uninstalled python and py2exe 64 bit to replace it with the 32 bit version.
After I did this, I always got this error.
Later, I deleted my dist and build directories from my project, and the subsequent build worked.
I have a problem with making exe using py2exe. In my project i'm using sqlalchemy with mssql module.
My setup.py script looks like:
from distutils.core import setup
import py2exe
setup(
windows=[{"script" : "pyrmsutil.py"}],
options={"pyrmsutil" : {
"includes": ["sqlalchemy.dialects.mssql", "sqlalchemy"],
"packages": ["sqlalchemy.databases.mssql", "sqlalchemy.cresultproxy"]
}})
But when i'm starting procedure like:
python.exe setup.py py2exe
I'm receiving build log with following errors:
The following modules appear to be missing
['_scproxy', 'pkg_resources', 'sqlalchemy.cprocessors', 'sqlalchemy.cresultproxy']
And in "dist" folder i see my pyrmsutil.exe file, but when i'm running it nothing happens. I mean that executable file starts, but do nothing and ends immediately without any pyrmsutil.exe.log. It's very strange.
Can anybody help me with this error?
I know it's no an answer per se but have you tries pyInstaller? I used to use py2exe and found it tricky to get something truly distributable. pyInstaller requires a little more setup but the docs are good and the result seems better.
For solving this issue you could try searching for the mentioned dlls and placing them in the folder with the exe, or where you build it.
Looks like py2exe can't find sqlalchemy c extensions.
Why not just include the egg in the distribution, put sqlachemy in py2exe's excludes and load the egg on start?
I use this in the start script:
import sys
import path
import pkg_resources
APP_HOME = path.path(sys.executable).parent
SUPPORT = APP_HOME / 'support'
eggs = [egg for egg in SUPPORT.files('*.egg')]
reqs, errs = pkg_resources.working_set.find_plugins(
pkg_resources.Environment(eggs)
)
map(pkg_resources.working_set.add, reqs)
sys.path.extend(SUPPORT.files('*.egg'))
i use Jason Orendorff's path module (http://pypi.python.org/pypi/path.py) but you can easily wipe it out if you want.