Introduction
I have a script which uses SSL and is build with py2exe (bundle_files=1, pack everything together into the *.exe)
Now I faced this problem
Running py2exe on Win7 creates an *.exe which will run in Win7 and Win10
Running py2exe on Win10 creates an *.exe which will run in Win10 but produces this error in Win7:
ImportError: MemoryLoadLibrary failed loading _ssl.pyd
Workaround
Setting bundle_files to 3 (don't pack) will result in an *.exe which is working fine in Win7 even when it is built on Win10.
I tried out some py2exe options and suddenly it worked, when changing bundle_files. But I don't understand why.
My setup
python 32bit 2.7.11
ssl.OPENSSL_VERSION => 'OpenSSL 1.0.2d 9 Jul 2015'
py2exe 0.6.9
Same on both machines (win7 and win10).
This is a minimal demo to reproduce it:
demo.py
import ssl
print "import done"
It can be built using this
exebuilder.py
from distutils.core import setup
import py2exe
import sys
sys.argv.append("py2exe") # run py2exe (instead of supplying the command line argument)
# exclude some DLLs
dll_excludes = [
# win9x leftovers
"w9xpopen.exe",
# don't import these - otherwise win7 created *.exe won't work in winXP
# http://stackoverflow.com/questions/1979486/py2exe-win32api-pyc-importerror-dll-load-failed
"mswsock.dll",
"powrprof.dll"
]
sys.argv.append("--dll-excludes=%s" % ",".join(dll_excludes))
app_name = "win10ssl"
params = {
'zipfile': None, # pack everything into the *.exe
'options': {
"py2exe": {
"compressed": 1,
"optimize": 2,
# bundle_files
# 1 = EVERYTHING packed into the *.exe
# 2 = everything except for the pythonXX.dll
# 3 = don't pack
"bundle_files": 3
}
},
'version': "0.0.1.0",
'description': "demo to show MemoryLoadLibrary error",
'name': app_name,
'console': [{
"script": "demo.py",
"dest_base": app_name
}
]
}
setup(**params)
Add "crypt32.dll" and "mpr.dll" to your dll_excludes. These are loaded by _ssl.pyd in newer versions of Python such as 2.7.11. But these libraries are Windows system libraries and OS version dependent, so they should not be packaged and distributed with your project. The Win7 "crypt32.dll" probably works on Win10, but the Win10 "crypt32.dll" most likely won't work on Win7.
Related
I wrote a basic script in python 3.7 that does what I need. However it needs to run on another person's computer. I want to run this as an exe then just change the icon logo.
I have installed py2exe (I believe). Below is the python script:
pip install py2exe
import os
os.startfile(r"\\ComputerName\c$\users\UserName\desktop\Lullaby wav.wav")
I have another file, that looks like this (basing this off this thread Can I somehow "compile" a python script to work on PC without Python installed? ):
import sys
from distutils.core import setup
import py2exe
entry_point = sys.argv[1]
sys.argv.pop()
sys.argv.append('py2exe')
sys.argv.append('-q')
opts = {
'py2exe': {
'compressed': 1,
'optimize': 2,
'bundle_files': 1
}
}
setup(console=[entry_point], options=opts, zipfile=None)
I then open up cmd and try to use the compile.py file on myscript per the instructions but get an erro:
File "", line 1
python compile.py covid.pyw
^
You can use PyInstaller. Which is inbuilt, if not you can install it. Just very simple lines in cmd to create an exe file and also you can add icon using -i(I think so).
Visit this to learn about it from realpython which I love to read about python tutorials : https://realpython.com/pyinstaller-python/
By the way you can use python 3.8.6 or 3.9 which is the updated version of python 3.7.
Make sure your device is up to date, that could be the problem, also pyinstaller is a better, more modern alternative
I'm on Windows 7, as are all potential users of my program. I packaged a Python program I wrote into an executable file using cx_Freeze, with the following command:
python setup.py build
This generates a build directory that contains my_program.exe. The executable works flawlessly on my computer, but on a coworker's machine, it throws an exception:
ImportError: No module named 'zipfile'
Here's my setup.py, where zipfile is explicitly included (and it's definitely in library.zip):
import sys
from cx_Freeze import setup, Executable
base = None
if sys.platform == "win32":
base = "Win32GUI"
setup(
name='Z-Wizard',
version='0.1',
description='Z1/Z2 data extraction tool',
author='Liz Rosa',
author_email='me#url',
options = {
'build_exe': {
'packages': ['zipfile']
}
},
executables = [Executable('my_program.py', base=base)]
)
The traceback is quite long; there's a screenshot at the URL below. It apparently involves a series of functions in _bootstrap.py. I'm not quite sure what's going on here. Also, "C:\Users\lizr..." is my home directory, not hers. Why does it appear in the traceback on her computer? In case it's not obvious, I don't know much about the freezing process.
http://i.imgur.com/cAQKWxq.png
I have a project in Python 3.4 and GTK+ 3. I'm on Windows XP SP3 32-bit (VirtualBox).
I need to compile down to an executable using py2exe. (Do NOT suggest cx_freeze. It has ten times the problems on this project than py2exe).
My setup.py is as follows.
#!/usr/bin/python
from setuptools import setup
import py2exe
setup(name="Redstring",
version="2.0",
description="REDundant STRING generator",
author="MousePaw Labs",
url="http://www.mousepawgames.com/",
maintainer_email="info#mousepawgames.com",
data_files=[("", ["redstring.png", "redstring_interface.glade"])],
py_modules=["redstring"],
windows=[{'script':'redstring.py'}],
options={"py2exe":{
"unbuffered": True,
"compressed":True,
"bundle_files": 1,
'packages':['gi.repository'],
}},
zipfile=None
)
When I run it via C:\Documents and Settings\Jason\Desktop\redstring2>python setup.py py2exe, I get the following output (in full).
running py2exe
running build_py
1 missing Modules
------------------
? gi.repository.Gtk imported from __SCRIPT__
Building 'dist\redstring.exe'.
C:\Documents and Settings\Jason\Desktop\redstring2>
The actual script, redstring.py, runs without a hitch in my Windows environment. In that, I have the following (working) line of code: from gi.repository import Gtk That is ALL I import from gi.repository in the entire project.
If I swap the line in setup.py to 'packages':['gi'],, the error output switches to about 24-some-odd missing modules, all of them belonging to gi.repository. If I try and import "Gtk" or "gi.repository.Gtk" in either 'packages': or 'includes':, I get an error that the file in question being imported cannot be found.
I spent eight hours on #python (IRC channel) today, and no one could solve this. I need this packaged down to a Windows binary this week.
NOTE: This question is not a duplicate; while it is a similar issue, it is a) not the same error message, and b) neither answer solves the question in any way.
I solved this by, first of all, downgrading to Python 2.7. (GTK+ 3.8 is still fine.) py2exe apparently has known issues with Python 3.
Second, I switched...
options={"py2exe": {
"bundle_files": 1,
}
to
options={"py2exe": {
"bundle_files": 3,
}
For some reason, py2exe cannot include certain files needed to run the gi library when 'bundle_files' is set to 1 or 2.
The full setup.py that works with py2exe for my project can be found on GitHub. I run it on cmd with python setup.py py2exe.
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'm currently looking into pyInstaller. I've been using py2exe for now but it would be nice if I'm only using one compiler for all platforms we target. My py2exe setup.py looks like this:
from distutils.core import setup
import py2exe
setup(
name='agent',
description='Service Test',
version='1.00.00',
service=['agent'],
console=['agent.py'],
zipfile=None,
options={ "py2exe":{
"includes":"win32service,win32serviceutil,win32event,servicemanager,autobahn",
"packages": 'twisted, autobahn',
'bundle_files': 1
},
},
)
I've managed to compile the windows service but as soon as i start using twisted it fails.
Commanlines I've used to compile with pyInstaller:
python PyInstaller.py --onefile c:\path\here\agent.py
python PyInstaller.py --hidden-import=twisted --onefile c:\path\here\agent.py
The error I get when I try to install my service
agent.exe?175104\twisted\python\modules.py:758:
UserWarning: C:\dist\path\agent.exe?175104 (for module twisted.web.util) not in path importer cache (PEP 302 violation - check your local configuration).