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?
Related
I am using Python 3.6.
I have really been learning to program the last few days and I want to send this program to a few people. They are not computer literate so I figured I would turn the program in to a windows executable for them.
I have done this before ages ago, but with simpler programs. My current program uses praw, sqlite3, urllib, os, time, and hurry.filesize.
I have my setup.py configured with the following code:
from cx_Freeze import setup, Executable
base = None
executables = [Executable("Image Downloader v2.py", base=base)]
packages = ["idna","praw","queue","hurry.filesize"]
options = {
'build_exe': {
'packages':packages,
},
}
setup(
name = "Reddit Image Downloader",
options = options,
version = "2.0",
description = 'Downloads images from Reddit.',
executables = executables
)
When I run python setup.py build from my command line, I get the error "no module named 'hurry.filesize'". I tried changing hurry.filesize in setup.py to just hurry and I get the same error as before, telling me that there is no module named "hurry". I also had to include the "queue" module in setup.py even though it's not part of my program because when I tried to build the executable I kept getting the module error but for "queue". Putting it in that list seems to have fixed that error.
How can I fix this?
I'm a Python and coding newbie.I have tried to search for posts,but seems like I can't find other facing with the same problem.
I'm using Python 2.7 and opencv3.0 on Windows 10.
I tried to convert my .py file to an EXE file using py2exe.
However, the command window told me.
error: [Errno 2] No such file or directory: 'api-ms-win-core-registry-l1-1-0.dll'
This is my setup.py
from distutils.core import setup
import py2exe
import matplotlib
import FileDialog
setup(windows=['HW6.py'],
options={
'py2exe': {
"includes" : ["matplotlib.backends.backend_tkagg","cv2"],
'excludes': ['_gtkagg', '_tkagg', '_agg2', '_cairo','_cocoaagg',
"matplotlib.numerix.fft","sip", "PyQt4._qt",
"matplotlib.backends.backend_qt4agg",
"matplotlib.numerix.linear_algebra",
"matplotlib.numerix.random_array",
'_fltkagg', '_gtk','_gtkcairo' ],
'dll_excludes': ['libgdk-win32-2.0-0.dll',
'libgobject-2.0-0.dll' ,
'MSVCP90.dll']
}
},
data_files=matplotlib.get_py2exe_datafiles(),)
After I excluded 'api-ms-win-core-registry-l1-1-0.dll', another error popped up and said
error: [Errno 2] No such file or directory: 'api-ms-win-core-errorhandling-l1-1-1.dll'
After I excluded lots of DLLs, still some DLLs are missing.
Here are what I have excluded
'api-ms-win-core-string-l1-1-0.dll',
'api-ms-win-core-registry-l1-1-0.dll',
'api-ms-win-core-errorhandling-l1-1-1.dll',
'api-ms-win-core-string-l2-1-0.dll',
'api-ms-win-core-profile-l1-1-0.dll',
'api-ms-win-core-processthreads-l1-1-2.dll',
'api-ms-win-core-libraryloader-l1-2-1.dll',
'api-ms-win-core-file-l1-2-1.dll',
'api-ms-win-security-base-l1-2-0.dll',
'api-ms-win-eventing-provider-l1-1-0.dll',
'api-ms-win-core-heap-l2-1-0.dll',
'api-ms-win-core-libraryloader-l1-2-0.dll',
'api-ms-win-core-localization-l1-2-1.dll',
'api-ms-win-core-sysinfo-l1-2-1.dll',
'api-ms-win-core-synch-l1-2-0.dll',
'api-ms-win-core-heap-l1-2-0.dll'
Here are things imported in 'HW6.py'
import matplotlib.pyplot as plt
from Tkinter import *
from PIL import ImageTk,Image
import numpy as np
import copy
import FileDialog
import warnings
import cv2
Without
import cv2
Everything works fine.
I have no idea how to deal with those DLLs.
Thanks!
Hardly an insightful answer, but i had the same problem and can say that the full list of api-ms-core* dlls that need to be excluded is for me:
"dll_excludes": ["MSVCP90.dll","libzmq.pyd","geos_c.dll","api-ms-win-core-string-l1-1-0.dll","api-ms-win-core-registry-l1-1-0.dll","api-ms-win-core-errorhandling-l1-1-1.dll","api-ms-win-core-string-l2-1-0.dll","api-ms-win-core-profile-l1-1-0.dll","api-ms-win*.dll","api-ms-win-core-processthreads-l1-1-2.dll","api-ms-win-core-libraryloader-l1-2-1.dll","api-ms-win-core-file-l1-2-1.dll","api-ms-win-security-base-l1-2-0.dll","api-ms-win-eventing-provider-l1-1-0.dll","api-ms-win-core-heap-l2-1-0.dll","api-ms-win-core-libraryloader-l1-2-0.dll","api-ms-win-core-localization-l1-2-1.dll","api-ms-win-core-sysinfo-l1-2-1.dll","api-ms-win-core-synch-l1-2-0.dll","api-ms-win-core-heap-l1-2-0.dll","api-ms-win-core-handle-l1-1-0.dll","api-ms-win-core-io-l1-1-1.dll","api-ms-win-core-com-l1-1-1.dll","api-ms-win-core-memory-l1-1-2.dll","api-ms-win-core-version-l1-1-1.dll","api-ms-win-core-version-l1-1-0.dll"]
Everything worked as normal after that.
I think I have figured out what exactly what the issue is. This is because that the cv2.pyd is dependent on some system level dll (try "dumpbin /dependents cv2.pyd", if you have Visual Studio installed), and they are not ignored by py2exe, e.g.
MSVFW32.dll
AVIFIL32.dll
AVICAP32.dll
ADVAPI32.dll
CRYPT32.dll
WLDAP32.dll
And these dll replies on the "api-ms-win-core-*****". If you want to distribute your software to other machines, these dll should not be copied too.
So at last, a more sensible solution maybe to exclude the dlls above, rather than "api-ms-win-core-*****", and in this way, the problem shall also be solved,
"dll_excludes": ["MSVFW32.dll",
"AVIFIL32.dll",
"AVICAP32.dll",
"ADVAPI32.dll",
"CRYPT32.dll",
"WLDAP32.dll"]
I'm not using opencv, but was stuck on same issue. After altering py2exe to tell me which images were importing which DLLs, I found that extending the list to include the below worked for my imported libs (even though some are hardcoded to be excluded in py2exe itself already - the code comments state it's not comprehensive):
"dll_excludes": [
'MSVCP90.dll',
'IPHLPAPI.DLL',
'NSI.dll',
'WINNSI.DLL',
'WTSAPI32.dll',
'SHFOLDER.dll',
'PSAPI.dll',
'MSVCR120.dll',
'MSVCP120.dll',
'CRYPT32.dll',
'GDI32.dll',
'ADVAPI32.dll',
'CFGMGR32.dll',
'USER32.dll',
'POWRPROF.dll',
'MSIMG32.dll',
'WINSTA.dll',
'MSVCR90.dll',
'KERNEL32.dll',
'MPR.dll',
'Secur32.dll',
]
I have a flask project, everything appears to be working fine. When using py2exe to build the package, (target server is a windows server ugh), the executable can execute, but leaves me with a ImportError: No module named 'jinja2.ext'
I have the module, and the website works fine with no ImportError when not executing from the .exe
I am pretty new at packaging and delivering, and not sure whats wrong with the setup that is causing the break from .py -> .exe conversion.
Setup.py
from setuptools import setup, find_packages
import py2exe
NAME = "WorkgroupDashboard"
VERSION = "1.0"
setup(
name=NAME,
version=VERSION,
description="Provides real time ISIS connection data",
long_description="",
# Get strings from http://www.python.org/pypi?%3Aaction=list_classifiers
classifiers=[],
author="Test User",
author_email='',
url='',
license='Free',
packages=find_packages(exclude=['ez_setup', 'examples', 'tests']),
include_package_data=True,
zip_safe=False,
install_requires=[
'flask >= 0.10.1',
'SQLAlchemy>=0.6'
],
console=['DashboardBack.py']
)
The idea is in order to turn the server on, just execute the .exe. Server will not have python on it. I am using Python 3.4 64 bit.
Edit: build cmd = python setup.py py2exe
Figured it out it seems, Setup commands go inside the py2exe optuons=[]
Working Setup.py
__author__ = ''
import sys
from glob import glob # glob will help us search for files based on their extension or filename.
from distutils.core import setup # distutils sends the data py2exe uses to know which file compile
import py2exe
data_files = []
setup(
name='WorkgroupDashboard',
console=['DashboardBack.py'], # 'windows' means it's a GUI, 'console' It's a console program, 'service' a Windows' service, 'com_server' is for a COM server
# You can add more and py2exe will compile them separately.
options={ # This is the list of options each module has, for example py2exe, but for example, PyQt or django could also contain specific options
'py2exe': {
'packages':['jinja2'],
'dist_dir': 'dist/test', # The output folder
'compressed': True, # If you want the program to be compressed to be as small as possible
'includes':['os', 'logging', 'yaml', 'flask', 'sqlalchemy'], # All the modules you need to be included, because py2exe guesses which modules are being used by the file we want to compile, but not the imports
}
},
data_files=data_files # Finally, pass the
)
I'd convert mine to EXE and deploy is over a host. Just get "Auto Py To Exe" application. Download it locally. Open the app, insert your project location, do some setup if you want, and then click "Convert". There you go. Flask in EXE format. Plug-in anywhere that you like without the need to have Python Interpreter.
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 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.