I am using Python-2.7 with py2exe-0.6.9 win 32 version. I have developed a tkinter GUI having OCR recognition program using openCV-3.1.0 and OpenTesseract (Pytesser) engine. I tried a lot to convert my program into an .exe but failed every time.
I have already installed Microsoft Visual C++ 2008 runtime, copied msvcp90.dll as well as Microsoft.vc90.crt.manifest into Python DLL folder but nothing worked at all. You can see the error below.
Error: C:\Python27>python setup.py py2exe
running py2exe
*** searching for required modules ***
*** parsing results ***
creating python loader for extension '_ctypes' (C:\Python27\DLLs\_ctypes.pyd -> _ctypes.pyd)
creating python loader for extension '_testcapi' (C:\Python27\DLLs\_testcapi.pyd -> _testcapi.pyd)
creating python loader for extension 'win32pipe' (C:\Python27\lib\site-packages\win32\win32pipe.pyd -> win32pipe.pyd)
creating python loader for extension 'select' (C:\Python27\DLLs\select.pyd -> select.pyd)
creating python loader for extension 'unicodedata' (C:\Python27\DLLs\unicodedata.pyd -> unicodedata.pyd)
creating python loader for extension 'PIL._imaging' (C:\Python27\lib\site-packages\PIL\_imaging.pyd -> PIL._imaging.pyd)
creating python loader for extension '_tkinter' (C:\Python27\DLLs\_tkinter.pyd -> _tkinter.pyd)
creating python loader for extension '_hashlib' (C:\Python27\DLLs\_hashlib.pyd -> _hashlib.pyd)
creating python loader for extension 'bz2' (C:\Python27\DLLs\bz2.pyd -> bz2.pyd)
creating python loader for extension '_ssl' (C:\Python27\DLLs\_ssl.pyd -> _ssl.pyd)
creating python loader for extension 'cv2' (C:\Python27\cv2.pyd -> cv2.pyd)
creating python loader for extension 'pyexpat' (C:\Python27\DLLs\pyexpat.pyd -> pyexpat.pyd)
creating python loader for extension '_socket' (C:\Python27\DLLs\_socket.pyd -> _socket.pyd)
*** finding dlls needed ***
error: [Errno 2] No such file or directory: 'api-ms-win-core-handle-l1-1-0.dll'
My setup.py script is:
# creating executable here
from distutils.core import setup
import py2exe, sys, os
sys.argv.append("py2exe")
setup(
options = {"py2exe": {"bundle_files": 3,"compressed":"True"}},
console=["gui_test3.py"],
zipfile = None,
)
Related
Running a Python program which uses a PySimpleGUI interface on top of TkInter. Program runs well on Windows 10 and CentOS Linux workstations. Unfortunately have a job requirement to also run the program on a Windows XP Service Pack 3 PC in an isolated secret lab area, no internet, so any installations are brought in on a DVD.
Python 3.4.4 was the latest version I could find which supports Windows XP and it installs and runs fine with Tkinter up and running as well.
PC Setup:
Windows XP Service Pack 3
Python 3.4.4
PySimpleGUI 3.39.0
Execution Error:
Traceback (most recent call last):
File "PysharkLiveCapGUI.py", line 9, in <module>
sg.theme('Topanga')
AttributeError: 'module' object has no attribute 'theme'
Path to PySimpleGUI EGG:
Type "help", "copyright", "credits" or "license" for more information.
\>>> import PySimpleGUI as sg
\>>> print(sg)
<module 'PySimpleGUI' from 'C:\\Python34\\lib\\site-packages\\pysimplegui-3.39.0-py3.4.egg\\PySimpleGUI\\_init_.py'>
PySimpleGUI Installation Results:
C:\Python34\Downloads\dist\PySimpleGUI-3.39.0>python setup.py install
C:\Python34\lib\distutils\dist.py:260: UserWarning: Unknown distribution option:
'long_description_content_type'
warnings.warn(msg)
running install
running bdist_egg
running egg_info
writing top-level names to PySimpleGUI.egg-info\top_level.txt
writing PySimpleGUI.egg-info\PKG-INFO
writing dependency_links to PySimpleGUI.egg-info\dependency_links.txt
reading manifest file 'PySimpleGUI.egg-info\SOURCES.txt'
writing manifest file 'PySimpleGUI.egg-info\SOURCES.txt'
installing library code to build\bdist.win32\egg
running install_lib
running build_py
creating build\bdist.win32\egg
creating build\bdist.win32\egg\PySimpleGUI
copying build\lib\PySimpleGUI\PySimpleGUI.py -> build\bdist.win32\egg\PySimpleGU
I
copying build\lib\PySimpleGUI\__init__.py -> build\bdist.win32\egg\PySimpleGUI
byte-compiling build\bdist.win32\egg\PySimpleGUI\PySimpleGUI.py to PySimpleGUI.c
python-34.pyc
byte-compiling build\bdist.win32\egg\PySimpleGUI\__init__.py to __init__.cpython
-34.pyc
creating build\bdist.win32\egg\EGG-INFO
copying PySimpleGUI.egg-info\PKG-INFO -> build\bdist.win32\egg\EGG-INFO
copying PySimpleGUI.egg-info\SOURCES.txt -> build\bdist.win32\egg\EGG-INFO
copying PySimpleGUI.egg-info\dependency_links.txt -> build\bdist.win32\egg\EGG-I
NFO
copying PySimpleGUI.egg-info\top_level.txt -> build\bdist.win32\egg\EGG-INFO
zip_safe flag not set; analyzing archive contents...
creating 'dist\PySimpleGUI-3.39.0-py3.4.egg' and adding 'build\bdist.win32\egg'
to it
removing 'build\bdist.win32\egg' (and everything under it)
Processing PySimpleGUI-3.39.0-py3.4.egg
Removing c:\python34\lib\site-packages\PySimpleGUI-3.39.0-py3.4.egg
Copying PySimpleGUI-3.39.0-py3.4.egg to c:\python34\lib\site-packages
PySimpleGUI 3.39.0 is already the active version in easy-install.pth
Installed c:\python34\lib\site-packages\pysimplegui-3.39.0-py3.4.egg
Processing dependencies for PySimpleGUI==3.39.0
Finished processing dependencies for PySimpleGUI==3.39.0
Problem?:
PySimpleGUI installation appeared to run error free. The EGG file looks fine when I inspect it using 7 Zip. Best guess is that Windows XP doesn't know how to read the EGG file although it's within a Python execution where theoretically Python has no problem importing EGG files. Any help with this issue greatly appreciated.
Thanks,
Jeff Stearns
Program runs well on Windows 10 and CentOS Linux workstations.
It should be wrong if you have code like sg.theme and you will get exception, no matter on Windows 10, CentOS Linux workstations.
PySimpleGUI 3.39.0
If nothing wrong, function sg.theme released from 4.14.0 PySimpleGUI 23-Dec-2019.
Python 3.4.4
"Upgrade your PySimpleGUI to the most update version" may not work for this version of python. try to use old method sg.change_look_and_feel.
Say, I have the following cython module renamed_module.pyx. This module contains all my cython code which include C and Python functions. Normally in development below is how I compile and run renamed_module.pyx.
A python file called setup.py that calls cython to convert my pyx modules into C code.
Setup.py code:
from distutils.core import setup
from Cython.Build import cythonize
setup(
name="appname",
ext_modules=cythonize(['renamed_module.pyx', 'other1.pyx', 'other2.pyx', 'other3.pyx']),
language_level=3)
I have another python file called run_renamed_module.py with the following code:
run_renamed_module.py:
import renamed_module
import os
import sys
sys.path.insert(0, os.path.abspath("."))
renamed_module.startingfunction()
Finally I compile it as following which works perfectly: python Setup.py build_ext --inplace && python run_renamed_module.py
Question
Now, I would like to convert my renamed_module.pyx into a standalone executable or a *.exe file that would open my cython GUI App.
After doing some research, I was able to first convert my renamed_module.pyx code into C code using cython renamed_module.pyx --embed -o renamed_module_comp.c
and then compile it to a binary file using gcc -c -DMS_WIN64 -shared -pthread -Wall -IC:/Users/[username]/AppData/Local/Programs/Python/Python39/Include -LC:/Users/[username]/AppData/Local/Programs/Python\Python39\libs -o app.exe renamed_module_comp.c.
With these two steps, I fall into no errors and they compile just fine. But now when I attempt to execute app.exe, I get the following error:
This app can't run on your PC. To find a version for your PC, check with the software publisher.
As reported/commented by other developers on the web, app.exe seem to be a DLL file. So, I tried to copy app.exe into an external folder, open python terminal from that directory, and call import app. With that I get:
ImportError: DLL load failed while importing app: %1 is not a valid Win32 application.
Unfortunately I don't know where to go from here. Any direction is really appreciated.
OS: Windows 10 x64
Python Version: Python 3.9.1
Cython Version: Cython version 0.29.23
GCC Version: gcc.exe (GCC) 9.2.0
GUI Libs: PyQT5 - Tkinter and pysimplegui
Summary of the question: I basically, want to compile my cython GUI app into a standalone executable program.
I'm having some trouble with cython. I recently found out about it and decided to use it in a project, but for some reason I'm unable to import the module/function that I've just compiled.
Here is what my sum.pyx file looks like:
def add(x, y):
return x+y
And this is my setup.py file:
from distutils.core import setup
from Cython.Build import cythonize
setup(ext_modules = cythonize('image_converter.pyx'))
When I run python setup.py build_ext --inplace, the output shows this error:
Compiling sum.pyx because it changed.
[1/1] Cythonizing sum.pyx
C:\Users\User-name\AppData\Local\Programs\Python\Python39\lib\site-packages\Cython\Compiler\Main.py:369: FutureWarning: Cython directive 'language_level' not set, using 2 for now (Py2). This will change in a later release! File: C:\Users\User-name\Documents\Cython\sum.pyx
tree = Parsing.p_module(s, pxd, full_module_name)
running build_ext
building 'sum' extension
error: Unable to find vcvarsall.bat
Only one file was created called sum.c, but I'm aware that there should be some .so file created in a new directory but I couldn't find any, so I just continued and created the test.py file to see if the cython file worked:
import sum
print(sum.add(5,6))
But if I run this I get the error:
ModuleNotFoundError: No module named 'sum'
I am using Python 3.9.7 and Visual Studio Code, and I'm using the g++ compiler (MSYS2).
Thanks in advance.
A few days ago I was able to create a Windows executable of my package using py2exe with no trouble. Today I tried again after completing deleting the build/ and dist/ folders and I don't see any errors, but I also don't get an executable in my dist/ folder. I do get these files in dist/:
_hashlib.pyd
bz2.pyd
library.zip
python27.dll
select.pyd
unicodedata.pyd
Here's my setup.py file:
from setuptools import setup
import py2exe
setup (
name = "RabbitToRaven",
version = "0.1",
description="RabbitToRaven is a utility for copying RabbitMQ messages into a RavenDB database.",
author="Greg Major",
author_email="", # Removed to limit spam harvesting.
url="http://www.gregmajor.com/",
packages=['RabbitToRaven'],
entry_points = {
'console_scripts': ['RabbitToRaven = RabbitToRaven.__main__:main']
},
download_url = "http://www.gregmajor.com/",
zip_safe = True
)
If I run $ python setup.py build with export DISTUTILS_DEBUG=1 then I get this:
options (after parsing config files):
options (after parsing command line):
option dict for 'aliases' command:
{}
option dict for 'build' command:
{'verbose': ('command line', 1)}
running build
Distribution.get_command_obj(): creating 'build' command object
setting options for 'build' command:
verbose = 1 (from command line)
running build_py
Distribution.get_command_obj(): creating 'build_py' command object
creating build
creating build\lib
creating build\lib\RabbitToRaven
copying RabbitToRaven\__init__.py -> build\lib\RabbitToRaven
copying RabbitToRaven\__main__.py -> build\lib\RabbitToRaven
Here's my python setup.py py2exe output:
options (after parsing config files):
options (after parsing command line):
option dict for 'aliases' command:
{}
option dict for 'py2exe' command:
{}
running py2exe
Distribution.get_command_obj(): creating 'py2exe' command object
Distribution.get_command_obj(): creating 'bdist' command object
Distribution.get_command_obj(): creating 'build' command object
setting options for 'build' command:
running build_py
Distribution.get_command_obj(): creating 'build_py' command object
creating build
creating build\lib
creating build\lib\RabbitToRaven
copying RabbitToRaven\__init__.py -> build\lib\RabbitToRaven
copying RabbitToRaven\__main__.py -> build\lib\RabbitToRaven
creating c:\Users\Greg\Code\LeadPipe.RabbitToRaven\build\bdist.win-amd64
creating c:\Users\Greg\Code\LeadPipe.RabbitToRaven\build\bdist.win-amd64\winexe
creating c:\Users\Greg\Code\LeadPipe.RabbitToRaven\build\bdist.win-amd64\winexe\collect-2.7
creating c:\Users\Greg\Code\LeadPipe.RabbitToRaven\build\bdist.win-amd64\winexe\bundle-2.7
creating c:\Users\Greg\Code\LeadPipe.RabbitToRaven\build\bdist.win-amd64\winexe\temp
creating c:\Users\Greg\Code\LeadPipe.RabbitToRaven\dist
*** searching for required modules ***
*** parsing results ***
creating python loader for extension 'unicodedata' (C:\tools\python2\DLLs\unicodedata.pyd -> unicodedata.pyd)
creating python loader for extension 'select' (C:\tools\python2\DLLs\select.pyd -> select.pyd)
creating python loader for extension '_hashlib' (C:\tools\python2\DLLs\_hashlib.pyd -> _hashlib.pyd)
creating python loader for extension 'bz2' (C:\tools\python2\DLLs\bz2.pyd -> bz2.pyd)
*** finding dlls needed ***
*** create binaries ***
*** byte compile python files ***
byte-compiling C:\tools\python2\Lib\StringIO.py to StringIO.pyc
snip!!!
byte-compiling c:\Users\Greg\Code\LeadPipe.RabbitToRaven\lib\warnings.py to warnings.pyc
*** copy extensions ***
copying C:\tools\python2\DLLs\_hashlib.pyd -> c:\Users\Greg\Code\LeadPipe.RabbitToRaven\dist
copying C:\tools\python2\DLLs\bz2.pyd -> c:\Users\Greg\Code\LeadPipe.RabbitToRaven\dist
copying C:\tools\python2\DLLs\select.pyd -> c:\Users\Greg\Code\LeadPipe.RabbitToRaven\dist
copying C:\tools\python2\DLLs\unicodedata.pyd -> c:\Users\Greg\Code\LeadPipe.RabbitToRaven\dist
*** copy dlls ***
copying C:\Windows\system32\python27.dll -> c:\Users\Greg\Code\LeadPipe.RabbitToRaven\dist
setting sys.winver for 'c:\Users\Greg\Code\LeadPipe.RabbitToRaven\dist\python27.dll' to 'RabbitToRaven'
*** binary dependencies ***
Your executable(s) also depend on these dlls which are not included,
you may or may not need to distribute them.
Make sure you have the license if you distribute any of them, and
make sure you don't distribute files belonging to the operating system.
USER32.dll - C:\Windows\system32\USER32.dll
SHELL32.dll - C:\Windows\system32\SHELL32.dll
ADVAPI32.dll - C:\Windows\system32\ADVAPI32.dll
WS2_32.dll - C:\Windows\system32\WS2_32.dll
GDI32.dll - C:\Windows\system32\GDI32.dll
KERNEL32.dll - C:\Windows\system32\KERNEL32.dll
Anybody have an idea? I'm pretty new to py2exe so I'm sure it's probably just a silly oversight. For what it's worth, my virtualenv environment is activated and I'm building from a Bash for Git terminal (although cmd.exe doesn't work either).
You aren't specifying which file should be made into an executable. Or at least not in a way that py2exe understands. entry_points and console_scripts seem to be options unique to setuptools.
Add either
console=['name_of_script.py']
or
windows=['name_of_script.py']
as a parameter to your setup() function inside the setup.py file. Depending on if you're creating a console or GUI application. These need to be lists, even if you're specifying only a single python script, although you can add more if you'd like.
Assuming you're creating a console application, your setup function should look something like this.
setup (
name = "RabbitToRaven",
version = "0.1",
console = ['name_of_script.py'],
...)
See http://www.py2exe.org/index.cgi/ListOfOptions for all the py2exe options.
I am trying to create an exe on Windows from a Python 3 package with a C extension module. In distutils, you can create an extension like this:
from distutils.core import setup, Extension
module1 = Extension('demo',
sources = ['demo.c'])
setup (name = 'PackageName',
version = '1.0',
description = 'This is a demo package',
ext_modules = [module1])
Than, the extension will be compiled with the appropriate compiler and placed alongside your other modules with the command:
python setup.py build_ext --inplace
cx_Freeze is a module that can package your code into an exe file along with a Python interpreter and the relevant packages. Then, an end user can use your program without having a Python installation. Unfortunately, cx_Freeze doesn't have an Extension class, and I cannot find a way to handle compilation with cx_Freeze.
One solution I am unsure about is to first build the extensions in place with distutils/setuptools, and then use cx_Freeze to create the executable. I don't want to reinvent the wheel though, so I wonder if someone else with more experience in this area has a solution.
I found a working solution. I can import Extension from distutils, and pass it into the setup from cx_Freeze:
from cx_Freeze import setup
from distutils.core import Extension
...
setup=(...
ext_modules=Extension(...))
This makes sense, since cx_Freeze is built on top of distutils. Originally, I was trying to use setuptools.setup, but that doesn't work.