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.
Related
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.
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'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.
So I have a Python script:
myscript.py
I am executing it like this:
python D:\myscript.py
However, I must have Python installed and included in the PATH environment variable for that to work.
Is it somehow possible to "bundle" Python executable with a Python script so other people will be able to run it on their PCs without Python?
It is ok if it will work only in Windows.
EDIT:
After trying the compile.py I get this error:
Traceback (most recent call last):
File "D:\stuff\compile.py", line 4, in <module>
import py2exe
ImportError: No module named py2exe
Here is one way to do it (for Windows, using py2exe).
First, install the py2exe on your Windows box.
Then create a python script named compile.py, like this:
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)
To compile your Python script into a Windows executable, run this script with your program as its argument:
$ python compile.py myscript.py
It will spit out a binary executable (EXE) with a Python interpreter compiled inside. You can then just distribute this executable file.
PyInstaller has worked well for me, generating reasonably small packages due to its use of upx. Its dependency detection was better than py2exe at the time as well. It seems not to have a lot of recent development and probably doesn't work with 3.x, however.
The source in the repository is a better starting point than the 1.4 package.
Also see the wiki page about working with Python 2.6+.
From the features list:
Packaging of Python programs into standard executables, that work on computers without Python installed.
Multiplatform: works under Windows (32-bit and 64-bit), Linux (32-bit and 64-bit) and Mac OS X (32-bit only for now, see MacOsCompatibility).
Multiversion: works under any version of Python from 1.5 up to 2.7. NOTE: If you're using Python 2.6+ on Windows, see Python26Win.
Flexible packaging mode:
Single directory: build a directory containing an executable plus all the external binary modules (.dll, .pyd, .so) used by the program.
Single file: build a single executable file, totally self-contained, which runs without any external dependency.
Custom: you can automate PyInstaller to do whatever packaging mode you want through a simple script file in Python.
Explicit intelligent support for many 3rd-packages (for hidden imports, external data files, etc.), to make them work with PyInstaller out-of-the-box (see SupportedPackages).
Full single-file EGG support: required .egg files are automatically inspected for dependencies and bundled, and all the egg-specific features are supported at runtime as well (entry points, etc.).
Partial directory EGG support: required .egg directories are automatically inspected for dependencies and bundled, but egg-specific features will not work at runtime.
Automatic support for binary libraries used through ctypes (see CtypesDependencySupport for details).
Support for automatic binary packing through the well-known UPX compressor.
Optional console mode (see standard output and standard error at runtime).
Windows-specific features:
Support for code-signing executables.
Full automatic support for CRTs: no need to manually distribute MSVCR*.DLL, redist installers, manifests, or anything else; true one-file applications that work everywhere!
Selectable executable icon.
Fully configurable version resource section and manifests in executable.
Support for building COM servers.
Mac-specific features:
Preliminar support for bundles (see MacOsCompatibility)
You want something like py2exe.
There are multiple solutions like py2exe, cx-freeze or (only for Mac OS X) py2app.
Here is a list of them.
I was writing a code which uses wxPython and comtypes. I have python 2.7 installed on my machine (Windows) along with wxPython, comtypes and py2exe. while trying to build it I got the following error:
error: MSVCP90.dll: No such file or directory
So, I did research I came to know about two solutions:
1. Copy Microsoft.VC90.CRT.manifest and msvcp90.dll to your machine and prepare your setup like as follows:
from distutils.core import setup
import py2exe
from glob import glob
data_files=[("Microsoft.VC90.CRT", glob(r'c:\shared_dlls*.*'))]
setup(data_files=data_files, console=['main.pyw'])
2. Use Python 2.5 along with wxPython, comtypes and py2exe
Now, I have following questions:
In first case:
a. Do I need to have Visual Studio license in order to use these files? or that can be used without any worries.
b. What if I compile it using aforementioned method? Does it still require MSVC90.dll on the user machine to execute? I think - No. Please correct me if I'm wrong. I want to remove any dependency and give user an exe which the user can directly execute without any dependency.
In Second case:
As I have Python_2.7 installed on my machine along with aforementioned modules. I would like to know can I install Python 2.5 on the same machine? Can they co-exist? If yes, do I need to install another copy of wxPython, comtypes and py2exe for this.
Please suggest me what is the best solution. How should I proceed? It's kind of blocking me.
Thanks in advance!
Python 2.5 and 2.7 (and all other versions of Python) co-exist very well. You may need to change your path to use the correct version of Python.
You will need to install the Python 2.5 builds of wxPython and py2exe. You will also need to install comtypes for Python 2.5. That installer will detect your Python installations by checking the registry.
I simply downloaded MSVCP90.dll file from here: http://www.dllme.com/dll/files/msvcp90_dll.html
and then pasted it into Python27\DLLs. It worked after that.
Did you try to install Visual C++ redistribuables?
I think you don't need a VS license for this.