I have a data acquisition program written in Python that I distribute to my collaboration as an executable (using cx_freeze), as I don't want to bother them with installing Python and installing all the software dependencies. The program has been working well for a year now. Recently, the program started to crash (crash, not give a scripting error, i.e., the Python virtual machine itself is crashing). So I would like to know what library is causing this problem. This problem is happening randomly, so it's difficult to systematically pinpoint the cause.
I learned about faulthandler, and I would like to use it with my cx_freeze, because I can't be sure the problem is happening due to cx_freeze itself or due to some other library.
The question: How can I produce a cx_freeze executable that will use faulthandler?
What I tried:
My current cx_freeze setup script is the following:
import sys
from cx_Freeze import setup, Executable
from GUI.Meta import *
target = Executable("Main.py",
#base = "Win32GUI",
icon = "GUI\\icon.ico",
compress=True,
targetName="Prog.exe")
setup(
name = "My Software",
version = SOFTWARE_VERSION,
description = "",
executables = [target])
I tried replacing my Executable part Main.py by Main.py -q -X faulthandler, but that didn't work. Importing faulthandler in my cx_freeze setup file with import faulthandler or from faulthandler import * didn't help.
Please advise.
Additional info: Dependencies that I'm using (in case you may know a possible cause of the problem): PySide, Sympy, Numpy, H5py, PySerial, Matplotlib
I learned that I could use procdump. It can be downloaded from here. It's a very simple program that can log stack trace. You can use it with:
C:\>procdump -ma -i c:\Dumps
and this will dump the stack trace of any program that crashes to that folder.
Related
I think this is one of the many questions about missing modules and py2exe... anyway...
PylibUty is a local package located in C:\Dati\workspaces\PythonEclipse\APyLibUty\PyLibUty and referred in every .py file with:
import sys, os
sys.path.append(os.path.join(os.path.dirname("file"), '..'))
sys.path.append("C:/Dati/workspaces/PythonEclipse/APyLibUty")
from PyLibUty.pystr import randomString, insertStr
uuid is a Python package so I normally import it
_posixshmem I am not able to find what package I should install using pip/pipenv
resource: I installed both resource and pyresource using pip/pipenv bat nothing changed
What should I install or import to solve these problems?
This is the output produced running py2exe:
I did not find a solution to understand what modules I should add or install to clear the problems of py2exe, so I searched the web to find a different tool able to make exe files from Python sources. I found cx_freeze, actually it does not produce the errors I reported so at the moment I switched to cx_freeze. I will test it better but at the moment my problem is solved.
I am trying to create a python software distribution depending on wxpython library. The thing is that I have two different versions in my PC: 2.8 and 3.0. The tool I use for exe creation is py2exe and the following content in setup.py :
from distutils.core import setup
import py2exe
setup(
name='Grabador tarjetas',
version='0.0',
description='Grabador Mifare',
author='siteco.desarrollo',
author_email='siteco.desarrollo#gmail.com',
url='http://www.sitecosl.net',
scripts=["GrabadorTarjetaMifareSiteco.py"],
windows=["GrabadorTarjetaMifareSiteco.py"],
data_files=[('', ['config.cfg'])],
install_requires=["wxpython=wx-2.8-msw-unicode"]
)
Each time I generate exe file, instead of including wxpython 2.8 library, it gets 3.0 library, regarding wxpython. Then, when I launch exe application, I get an error due to the difference between included library and needed library.
In my python distribution folder, inside lib/site-packages, I have two folders for wxpython distributions: wx-2.8-msw-unicode and wx-3.0-msw. Besides, wx.pth is pointing to wx-2.8-msw-unicode. Running from pydev in eclipse works fine, but I get errors when executing generated exe from "dist" folder.
Obviously something is wrong....
¿Could you give me any tips?
Thanks a lot.
this is the solution: in my main script, I have included the following code
import sys
if not hasattr(sys, 'frozen'):
import wxversion
wxversion.select('2.8')
setup.py remains the same.
Thanks.
I'm trying to convert my python project into an exe using Py2Exe. It is worth noting that cx_freeze complains about the same three "missing modules", along with several dozen others. The problem is, no one anywhere tells how to resolve this.
I'm building on MS Windows XP 32-bit (VirtualBox).
C:\Documents and Settings\Jason\Desktop\redstring2>python setup.py py2exe
running py2exe
running build_py
creating build
creating build\lib
copying redstring.py -> build\lib
3 missing Modules
------------------
? readline imported from cmd, code, pdb
? win32api imported from platform
? win32con imported from platform
Building shared code archive 'dist\library.zip'.
Copy c:\windows\system32\python34.dll to dist
Copy C:\Python34\DLLs\select.pyd to dist\select.pyd
Copy C:\Python34\DLLs\_ssl.pyd to dist\_ssl.pyd
Copy C:\Python34\DLLs\_ctypes.pyd to dist\_ctypes.pyd
Copy C:\Python34\DLLs\_lzma.pyd to dist\_lzma.pyd
Copy C:\Python34\DLLs\_hashlib.pyd to dist\_hashlib.pyd
Copy C:\Python34\DLLs\pyexpat.pyd to dist\pyexpat.pyd
Copy C:\Python34\DLLs\_socket.pyd to dist\_socket.pyd
Copy C:\Python34\DLLs\_bz2.pyd to dist\_bz2.pyd
Copy C:\Python34\DLLs\unicodedata.pyd to dist\unicodedata.pyd
My setup.py is as follows.
#!/usr/bin/python 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/",
author_email="info#mousepawgames.com",
data_files=[("", ["redstring.png", "redstring_interface.glade"])],
py_modules=["redstring"],
)
This is a Python 3.4 project using GTK+ 3 (built in Glade). It runs just peachy on Ubuntu, and from python redstring.py, but I can't get the thing to compile down to an .exe.
So far I tried import platform, from platform import win32api, and all the like in both redstring.py and setup.py, along with importing platform via py2exe options in the setup file.
win32api and win32con are part of Mark Hammond's Python Windows extensions (aka pywin32). readline is a module that is used (if present) by some code interacting with the console.
Both readline and pywin32 are optional modules/packages that are not abolutely required but will be used when present.
All in all - py2exe notices that these modules/packages are referenced by some code which will be included into your exe (it even mentions the modules that reference these mod/packages: cmd, code, pdb, platform).
I hope you have tested your script - in the 'non-compiled' form, if it works correctly than you can safely ignore these messages: they are only warnings.
The reason that no executable is built is that the line 'console=["redstring"]' or 'windows=["redstring"]' is missing in the setup() call.
So, it would happen that these libraries were never installed to begin with. Python may be "batteries included", but not to this extent. However, I'm answering this because fixing it isn't the most obvious thing in the world to some (myself included).
You need to install win32api (or pywin32, as it is officially called) from Sourceforge (at the moment, browse the files for the latest version, as the Download button links to README.txt) That will resolve win32con as well. (You cannot install pywin32 from pip at the moment, unfortunately.)
readline is not compatible with Windows, yet it asks for it. You actually have to install pyreadline, which is easiest from pip install pyreadline.
That should resolve all of those issues for py2exe. I'm still having trouble, but it's different trouble, so it's a different question.
I am trying to freeze a Python script that contains an import from osgeo but the executable fails with an ImportError: No module named '_gdal'.
I've stripped down my script to just one line:
import osgeo
When running in Python (version 3.3.3) all is well. I've tried freezing with cx_Freeze and py2exe. Both report that there is a missing module: ? _gdal imported from osgeo (among others) but successfully freeze the script. Then the exe fails with the above ImportError.
I've tried importing _gdal in python and it works. I tried manually including the osgeo module in the freezing options but still get the same error.
There is a similar question here:
Importing GDAL with cx_Freeze, Python3.4
but maybe this isn't a cx_freeze issue because it also happens with py2exe (it has experimental support for python 3 now).
Does anybody know how to fix this?
I found a fix. I edited the osgeo\__init__.py file and modified line 13 like this: import osgeo._gdal. This works but only if the module osgeo._gdal is manually included when freezing. #Thomas K Your solution does the same thing I guess.
Note that the same modification must be applied both at osgeo.ogr (line 18) and osgeo.osr (line 18) modules if they are needed (import osgeo._ogr and import osgeo._osr respectively). This means that these must be manually included when freezing as well. My freezing command now looks like this: python cxfreeze.py module1.py --include-modules=osgeo._gdal,osgeo._ogr,osgeo._osr.
Thanks #Thomas K for your help.
I'm making a real simple RPG game at college and I would like to use pygame. However, my college has a group policy disabling any Windows executables from running so I can't install pygame. Is there any way I can just import pygame by just having it in the same folder?
One thing I do with external python libraries is to download the source, build it and copy the built library into ${PROJECT_HOME}/lib/${EXTERNAL_LIB_NAME}. This way, I can run my python scripts with just standard python installation on a machine. To be able to use the external lib, you'll have to include the lib directory to sys path like this:
import os
from sys import path as syspath
syspath.append(os.path.join(os.path.dirname(__file__), 'lib'))
P.S.: Since pygame has C/C++ files to be compiled, you'd have to use mingw instead. Refer to this answer for that: error: Unable to find vcvarsall.bat
EDIT: In case you're wondering how to build pygame from source, you'll need to run setup.py build. This will build the python library into 'build' folder of the package directory and there you'd see how it should be placed in Python's directory. You will face the compilation problem in Windows as I've mentioned before, but you can easily fix that.
EDIT 2: Download link to contents of 'lib' for PyGame:
Python 2.7: http://dl.dropbox.com/u/71422266/pygame27.7z
Python 3.2: http://dl.dropbox.com/u/71422266/pygame32.7z
If you're allowed to run stuff from a USB drive, one option would be to use Portable Python 2.7.3.2, which includes PyGame 1.9.1.