py2exe & win32 OLEObject error - python

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)!

Related

py2exe executes file but doesn't attempt to build

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 *

py2exe "No module named 'site'" from Anaconda

I'm trying to use py2exe to build an executable on 64-bit Windows 7 with Anaconda (Python 3.4) for a project of mine that depends on a lot of libraries. Some of the more complex ones include vispy (pyopengl), PyQt4, numba, and scipy. I've been stepping through various errors to try to get a working executable, but have hit a road block with no clear way forward. Currently, the py2exe command completes, but I get the following error when running the exe:
...
from numba import jit
File "C:\Anaconda3\envs\sift_py2exe\lib\site-packages\numba\__init__.py", line
13, in <module>
from .pycc.decorators import export, exportmany
File "C:\Anaconda3\envs\sift_py2exe\lib\site-packages\numba\pycc\__init__.py",
line 12, in <module>
from .cc import CC
File "C:\Anaconda3\envs\sift_py2exe\lib\site-packages\numba\pycc\cc.py", line
4, in <module>
from distutils.command import build_ext
File "C:\Anaconda3\envs\sift_py2exe\lib\distutils\command\build_ext.py", line
17, in <module>
from site import USER_BASE
ImportError: No module named 'site'
I was able to do a small workaround by adding the C:\Anaconda3\envs\sift_py2exe\Lib directory to sys.path in my main script, but I doubt that's going to help me much later. Not to mention I had more scipy DLL issues after that.
Here are the relevant parts of my setup.py:
try:
import py2exe
from llvmlite.binding.ffi import _lib_dir, _lib_name
kwargs["data_files"] = [('.', [os.path.join(_lib_dir, _lib_name), os.path.join(_lib_dir, "MSVCP120.dll"), os.path.join(_lib_dir, "MSVCR120.dll")])]
kwargs["console"] = [{
'script': 'cspov/__main__.py',
'dest_base': "SIFT",
}]
kwargs["options"] = {'py2exe': {"includes": ["vispy.app.backends._pyqt4", "PyQt4.QtNetwork"]}}
except ImportError:
print("'py2exe' and/or 'llvmlite' not available")
I've tried adding the "Lib" directory in setup.py and then including "site", but it doesn't find the module. Any ideas? Thanks.
Side note: I'm using the Microsoft DLLs from llvmlite as a quick workaround because I couldn't get it to work in any of the normal ways.
This isn't the answer I was hoping for, but I was able to get a working executable when I switched to pyinstaller. All of the other SO questions I saw relevant to my problem had similar "solutions".

Best of both worlds: python packaging for a game

I am currently trying to package a game made with python and pygame and I am running into some issues.
I am using py2exe to package and have looked up some question on here about it but I couldn't find a great solution. I want to end up with a folder, containing an exe, that I can compress and put online. Running the setup.py works fine except it puts all the dependencies into library.zip. This means that the program, when run, does not work.
I found that someone else was running into this issue and they ended using the "skip archive = true" option to solve it. And while, yes, that does work for me too I was hoping there was a method that would still let the program be run without trouble but wouldn't clutter the folder with countless files.
To be very precise the issue I'm running into with the library.zip is:
ImportError: MemoryLoadLibrary failed loading pygame\mixer.pyd
Which, if I understand it properly, means that the program can not reach/find the mixer module of Pygame.
Here is the setup script I am currently using (and that isn't working):
from distutils.core import setup
import py2exe, sys, os
sys.argv.append('py2exe')
data_files = [('resources', ['resources/step.wav',
'resources/wind2.wav',
'resources/The Steppes.ogg',
'resources/warrior3-nosword-notassle.png',
'resources/warrior3-sword.png',
'resources/warrior2-blood1.png',
'resources/warrior2-blood2.png',
'resources/warrior2-blood3.png',
'resources/warrior2-blood4.png',
'resources/warrior3-up.png',
'resources/warrior3-kneel.png',
'resources/warrior3-kneel-nosword.png',
'resources/warrior2-blood2-kneel.png',
'resources/warrior2-blood3-kneel.png',
'resources/warrior2-blood4-kneel.png',
'resources/warrior3-death.png',
'resources/warrior3-offarm.png',
'resources/menu1.png',
'resources/plains3-top-nomount.png',
'resources/mountains.png',
'resources/plains5-bottom.png',
'resources/plains3-bottom.png',
'resources/cloud1.png',
'resources/warrior2-sword.png',
'resources/warrior2-hand.png',
'resources/blue-tassle1.png',
'resources/blue-tassle2.png',
'resources/blue-tassle3.png',
'resources/blue-tassle4.png'])]
setup(options = {'py2exe': {"bundle_files": 1}},
data_files = data_files,
console = [{'script': "steppes2.0.py"}],
zipfile = None
)
This code in your setup.py should do the trick of producing a single executable (you will still have to distribute msvc dlls separately)
from distutils.core import setup
import py2exe, sys, os
sys.argv.append('py2exe')
setup(
options = {'py2exe': {'bundle_files': 1}},
console = [{'script': "myscript.py"}],
zipfile = None,
)

LoadLibrary(pythondll) failed error using py2exe tutorials

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.

Making exe using py2exe + sqlalchemy + mssql

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.

Categories