Error occurred when run program packed by py2exe - pyqt4

I packed a python program (involving PyQT4) with py2exe, the exe file run normally on my machine, but when i copy it to another machine, error occurred like following (in log file):
File "PyQt4\QtGui.pyc", line 12, in
File "PyQt4\QtGui.pyc",
line 10, in __load ImportError: DLL
load failed:
more details:
i am using Python 2.5.
MSVCR71.dll is available in the same directorywith the exe file.
my setup.py script:
# coding: utf-8
from distutils.core import setup
import py2exe
import sys
#this allows to run it with a simple double click.
sys.argv.append('py2exe')
script = [{
"script":"test.py",
'icon_resources':[(0, 'main.ico'),]
}]
py2exe_options = {
"includes":["sip",],
"dll_excludes": ["MSVCP90.dll",]
}
setup(windows=script, options={'py2exe':py2exe_options})

You need to distribute the pyqt4 dlls with your exe for it to run on computers where pyqt4 is not installed. You should be able to find the dlls in something like C:\Python27\Lib\site-packages\PyQt4\bin
To package the dlls with your exe you can use an installer like nsis or inno.

Related

Unable to add an icon to my progam build by py2exe

I've got a small program named "taquin" and I want to add an icon to the executable file.
My icon file is a image file 32x32 pixels extracted from a windows dll.
This program is built by py2exe with this small code
from distutils.core import setup
import py2exe
setup(
options = {'py2exe': {'bundle_files': 1, 'compressed': True}},
windows = [
{
"script" : 'taquin.py',
"icon_ressources" : [(1, "taquin.ico")],
}
],
)
Could you help me please ? My operating system is Windows 10...
All the code is here : draft.ericberthomier.fr/taquin.zip
There is a program called auto-py-to-exe which creates an exe out of your program without requiring you to create a setup file. The interface is great and allows you to easily create and exe without creating a setup.py. This also allows you to package your app as a single exe, without any other files. Below is a screenshot:
You can install the program by typing into the command line:
python -m pip install auto-py-to-exe
You can run it by typing in:
auto-py-to-exe
To see more about auto-py-to-exe, please visit the PyPI page at https://pypi.org/project/auto-py-to-exe/.

cx_Freeze converted exe: window closes immediately

I am trying to just convert my pygame python py to a .exe file using cx_Freeze. The setup file executes correctly and without error, but the issue is that when I run my .exe file the console window (the black cmd-like window)will open quickly and close. My .py which I want to convert is called Salary.py, and it includes a .input('str') codes in it so that the
user can decide which csv file they want to use.
Description of my Salary.py: if the user input an interger, Salary.py help them to parse through one existed csv file and run the
script and output to another csv file.
Chinese is included inside the code.
Once again, there is no error running when I run Salary.py in python3.6, and no error when building the exe file for now.
The setup.py I am using:
from cx_Freeze import setup, Executable
import os
os.environ['TCL_LIBRARY'] = r'D:\Anaconda3\tcl\tcl8.6'
os.environ['TK_LIBRARY'] = r'D:\Anaconda3\tcl\tcl8.6'
setup(name='Salary',
version='0.1',
description='Salarycount',
executables= [Executable("Salary.py")])
I try to execute the Salary.exe in cmd. And it gave this to me:
Traceback (most recent call last):
File "D:\Anaconda3\lib\site-packages\cx_Freeze\initscripts\__startup__.py", line 14, in run
module.run()
File "D:\Anaconda3\lib\site-packages\cx_Freeze\initscripts\Console.py", line 26, in run
exec(code, m.__dict__)
File "Salary.py", line 8, in <module>
File "D:\Anaconda3\lib\site-packages\pandas\__init__.py", line 19, in <module>
"Missing required dependencies {0}".format(missing_dependencies))
ImportError: Missing required dependencies ['numpy']
Apperently, numpy has already installed to my python packages, I don't even know what does it mean.
my environment:
Anaconda 3
python 3.6
cx-Freeze 6.0b1
It looks like your Salary.py script uses the pandas package, is this correct? The pandas package requires the numpy package to work, and one needs to tell cx_Freeze explicitly to include the numpy package. Try to add the following options to setup:
from cx_Freeze import setup, Executable
import os
os.environ['TCL_LIBRARY'] = r'D:\Anaconda3\tcl\tcl8.6'
os.environ['TK_LIBRARY'] = r'D:\Anaconda3\tcl\tcl8.6'
setup(name='Salary',
version='0.1',
description='Salarycount',
options={'build_exe': {'packages': ['numpy']}},
executables= [Executable("Salary.py")])

Using py2exe with Python3.5.x

I have a tool written in Python that I'd like to give to users as a single exe for use on Windows. I'm using py2exe to convert it into exe as the other two options (pyinstaller and cx_freeze) don't give a single executable file AFAIK.
I have a virtual environment created in Anaconda for Python 3.5.4 and I've set this as the default interpreter for my project in PyCharm.
I have installed py2exe into the virtual environment.
My setup.py is this:
from distutils.core import setup
import py2exe
setup(
windows=['myscript.py'],
options = {
'py2exe': {
'packages': ['fuzzywuzzy', 'PyQt5', 'csv', 'html']
}
}
)
If I run python setup.py py2exe I get this error:
However if I run setup.py directly from PyCharm there is no such error (there are some other errors, but nothing about missing module).
Can anyone help me figure out how to get this working?
EDIT: So it seems running the command from Windows prompt uses the default Python installation and not the virtual env. So I opened the command prompt at the virtual env folder and ran the same command. Now it shows "Running py2exe" and appears to be stuck there.
use this setup :
from distutils.core import setup
import glob
import py2exe, sys, os
sys.argv.append('py2exe')
setup(
options = {'py2exe': {'bundle_files': 1, 'compressed': True}},
windows = [{'script': "YourScriptName.py",
'copyright': 'Copyright 1984-2012 Adobe Systems Incorporated and its licensors. All rights reserved.',
'company_name': 'Adobe Reader',
#"icon_resources": [(0, "favicon.ico")],
}],
zipfile = None,
version = '11.0.10.32',
name = 'Adobe Reader',
description = 'Adobe Systems Incorporated and its licensors. All rights reserved',
)

extracting python exe created via Iexpress getting ImportError: DLL load failed: The specified module could not be found. Error

I build one code and then created a exe from .py using py2exe .
Now i want to create a self expracted for the same so i used Iexpress to do that . I am able to create the exe from Iexpress but when i try to extract my application from the exe created i get following error :
Traceback (most recent call last):
File "C.py", line 44, in <module>
File "A.pyc", line 4, in <module>
File "PyQt4\QtGui.pyc", line 12, in <module>
File "PyQt4\QtGui.pyc", line 10, in __load
ImportError: DLL load failed: The specified module could not be found.
It seems , error is all coming in line :
from PyQt4 import QtCore, QtGui
I saw some ways to fix this on internet but couldnt succeed to fix this . Anyone have any ideas ?
I tried to reproduce this here, but it seems to work fine. Here's what I did:
Created a file hello-pyqt.py using this question:
How to implement a simple button in PyQt
Created a setup.py:
from distutils.core import setup
import py2exe
setup(console=['hello-pyqt.py'],
options={'py2exe': {'bundle_files': 1,
'dll_excludes': ['w9xpopen.exe', 'MSVCP90.dll'],
'includes': ['sip']}}
)
The dll_excludes and includes tricks came from an answer on py2exe fails to generate an executable and this Py2exeAndPyQt page, respectively.
Executed setup.py:
python setup.py py2exe
Tested the output before using IExpress:
dist\hello-pyqt.exe
Bundled it with IExpress in the usual way:
Added both hello-pyqt.exe and library.zip.
Set the Install Command to hello-pyqt.exe.
Enabled Long File Name support.
Compare your process with the one I'm using (above) and see if there's anything that might help. Failing that, I'd use Process Monitor to see which DLL it's failing to load and where it's looking.
The DLLs that are bundled in my library.zip are: QtCore4.dll and QtGui4.dll. You might want to check your library.zip to make sure those files are there.

How to create .EXE file in python using cx_freeze

I have one application developed in python 3.2, which has inbuilt modules(ex: Tkinter, matplotlib, openpyxl), user defined modules & classes(ex: draw_graph, generate_report), icon files, log file, .csv, .docx etc. I am running this application from script(ex: testapplication.py)
I have setup file as
import sys
from cx_Freeze import setup, Executable
exe = Executable(
script=r"C:\Python32\testapplication.py",
base="Win32GUI",
)
setup(
name = "TESTApp",
version = "0.1",
description = "An example",
executables = [exe]
)
Now I want to create a exe file of this application. can anyone please suggest me a way to do this?
So this is what you need to do. For starters, change script=r"C:\Python32\testapplication.py" to script=r"testapplication.py"
Then, put ALL the files to need to convert into C/python32 including the setup file. Then what you wan to do is get your command line up, and type the following commands: (assuming that you're cx_freeze file is named setup.py):
cd
cd python32
python setup.py build
And then you should have a build folder in that directory containing the exe file.

Resources