CX_Freeze application closes directly after startup - python

I'm relatively new to Python, but I made my first program and want to easily distribute it. I succesfully pip installed cx_freeze version 5.1.1 and I have successfully built the application. But as soon as I start the .exe, it closes, without giving me any information on the error. My setup.py:
from cx_Freeze import setup, Executable
import os.path
os.environ['TCL_LIBRARY'] = r'C:\Python36\tcl\tcl8.6'
os.environ['TK_LIBRARY'] = r'C:\Python36\tcl\tk8.6'
setup(name='PythonAutoTyper',
version='0.1',
description='PATv0.1',
executables = [Executable("distme.py")])
I have already searched for it on Google, and came across this page:
cx_Freeze Exe Application closes as soon as opens , but that doesn't solve my problem since my program is named distme.py.
The only PyPi library that I'm using in my application is PyAutoGUI.
Thanks in advance.
Edit: I've tried to run it via the command prompt, and it gave an error (luckily):
Traceback (most recent call last):
File "C:\Python36\lib\site-packages\cx_Freeze\initscripts\__startup__.py",
line 14, in run
module.run()
File "C:\Python36\lib\site-packages\cx_Freeze\initscripts\Console.py", line
26, in run
exec(code, m.__dict__)
File "distme.py", line 3, in <module>
File "C:\Python36\lib\tkinter\__init__.py", line 36, in <module>
import _tkinter # If this fails your Python may not be configured for Tk
ImportError: DLL load failed: The specified module could not be found.
So I guess I have a problem with tkinter.

Related

Packaging Enaml Application with PyInstaller

I have a single window/view enaml application (backend is PySide). I have packaged it to .exe using PyInstaller and it finishes successfully but when I run the executable it complains about the module which is in the .enaml file (I have already included the file and the parser in the .spec file, see below). Any thoughts on what goes wrong?
Here is the error from running the .exe file:
Traceback (most recent call last):
File "colEq.py", line 70, in <module>
from colEq import CaseView
ImportError: cannot import name CaseView
CaseView is defined in colEq.enaml file and the line referred to is:
with enaml.imports():
from colEq import CaseView`
My spec file has the following added beyond the default generated by PyInstaller:
a.datas+= [('colEq.enaml', 'colEq.enaml', 'DATA'),
('enaml\\core\\parser.py', parser_filepath, 'DATA')]
hiddenimports=[
"enaml",
"enaml.core.parse_tab.lextab",
"enaml.core.compiler_helpers",
"enaml.core.compiler_nodes",
"enaml.core.enamldef_meta",
"enaml.core.template",
"enaml.widgets.api",
"enaml.widgets.form",
"enaml.layout.api",
"enaml.stdlib.fields"
]
The platform is Python 2.7, x86, Win 10.

Issues using py2exe, psutil library errors

I'm trying to use py2exe for making a python program exe.
Until now it was working perfectly, but in the new version of the program I'm using psutil library and it makes some problems to some people.
In my computer, it works perfectly, I can start the exe file without any issues.
But on other computers, the exe program makes a problems and it creates a error log, here is it:
Traceback (most recent call last):
File "guard.pyw", line 10, in <module>
File "psutil\__init__.pyc", line 126, in <module>
File "psutil\_pswindows.pyc", line 16, in <module>
File "psutil\_psutil_windows.pyc", line 12, in <module>
File "psutil\_psutil_windows.pyc", line 10, in __load
ImportError: DLL load failed: The operating system cannot run %1.
I have no idea why it happens, especially when it works fine in my computer.
Here is the setup.py file of the py2exe program, maybe the problem is there:
from distutils.core import setup
import py2exe, sys, os
sys.argv.append('py2exe')
setup (windows = ['guard.pyw'],
options = { 'py2exe' : {'packages':['Tkinter'], 'compressed': True}},
dll_excludes=['msvcr71.dll', "IPHLPAPI.DLL", "NSI.dll", "WINNSI.DLL", "WTSAPI32.dll"])
Does anyone have an idea about how to fix that issue? Thanks in advance :)

py2exe not finding modules already installed?

I'm trying to use p2exe to build an exe from a python script that uses pymodbus and twisted (with lots of underlying dependencies apparently). I can build the exe but it does not run properly. I'm trying to figure out what I am doing wrong setting up the environment. I'm confident it is not my script because I can run it just fine from the python command line interpreter.
My python script uses these modules...
from pymodbus.server.async import StartTcpServer
from pymodbus.datastore import ModbusSequentialDataBlock
from pymodbus.datastore import ModbusSlaveContext, ModbusServerContext
import sys
import logging
from twisted.internet.task import LoopingCall
I get this error on python setup1.py py2exe...
The following modules appear to be missing
['Crypto.PublicKey._fastmath', 'FCNTL', 'OpenSSL', 'OpenSSL.SSL', 'OpenSSL._util', 'PAM', 'System', 'System.IO.Ports', 'TERMIOS', '_scproxy',
'gmpy', 'idna', 'pkg_resources', 'pyasn1.codec.ber', 'pyasn1.error', 'pyasn1.type', 'queue', 'resource', 'service_identity', 'service_identity
.pyopenssl', 'twisted.python._initgroups', 'twisted.python.sendmsg']
It builds the exe. When I run the exe this happens...
C:\Users\jlaird\Desktop\slush\dbclienttest\dist>modbus_slave2.exe
Traceback (most recent call last):
File "modbus_slave2.py", line 1, in <module>
File "pymodbus\server\async.pyc", line 18, in <module>
File "pymodbus\internal\ptwisted.pyc", line 5, in <module>
File "twisted\conch\manhole_ssh.pyc", line 14, in <module>
File "twisted\conch\ssh\factory.pyc", line 15, in <module>
File "twisted\conch\ssh\transport.pyc", line 32, in <module>
File "twisted\conch\ssh\keys.pyc", line 20, in <module>
ImportError: No module named pyasn1.error
If I start python and do 'import pyasn1' it imports without error. I can also import twisted and pymodbus just fine. Python can reach it but not py2exe. Why?
Figured it out...for some reason the contents of the build\lib folder for pyasn1 was not copied into C:\Python27\Lib\site-packages. Only an egg was copied. So I moved the folder over into site-packages and py2exe built an executable that worked.

Py2Exe Error: Win32com.client causes errors when trying to run created executable

My script that I'm trying to create into an executable contains the following imports:
import csv, time, BeautifulSoup, sys, mechanize, os, traceback, win32com.client as win32
My setup.py looks like this:
from distutils.core import setup
import py2exe, sys, os
sys.argv.append('py2exe')
setup(
options = {'py2exe': {'bundle_files': 1}},
console = [{'script': "tool.py"}],
zipfile = None,
)
The .exe of my program is created successfully, however when I try to run it I receive the following errors:
Traceback (most recent call last):
File "tool.py", line 1, in <module>
File "zipextimporter.pyc", line 82, in load_module
File "win32com\__init__.pyc", line 5, in <module>
File "zipextimporter.pyc", line 98, in load_module
ImportError: MemoryLoadLibrary failed loading win32api.pyd
Surprisingly, it compiles into an .exe fine if I use bundle_files: = 3 however I need this program to be in one executable, not multiple files. I've read this from the py2exe website but I'm not sure if that's what I need to do/use. If that is the answer I'm looking for, I don't know how to use that or what to do with it. Please explain.
Any help is greatly appreciated!
This was solved by upgrading to Python 2.7. I originally had Python 2.6 installed but the update solved this issue.

python 3.2: cx_freeze does not import all of pyserial

I am having issues building an exe verision of my python 3.2 script. The script requires pyserial and builds using cx_freeze. However, when I run the exe I get:
Traceback (most recent call last):
File "C:\Python32\lib\site-packages\cx_Freeze\initscripts\Console3.py", line 27,
in <module>
exec(code, m.__dict__)
File "my_serial_program.py", line 1, in <module>
import serial
File "C:\Python32\lib\site-packages\serial\__init__.py", line 19, in <module>
from .serialwin32 import *
File "C:\Python32\lib\site-packages\serial\serialwin32.py", line 12, in <module>
from . import win32
ImportError: cannot import name win32
Doing a little snooping, Pyserial site-package has a "win32.py" module (in addition to serialwin32.py); however, in the compressed lib that cx_freeze produces, win32.py is missing. Simply placing a pyc version does not fix the issue. Also using cx_freeze "includes = [ ]" does not work.
Any ideas? Is my question even cogent (I am fairly new to python)?
I had the same issue. There is an option to include extra modules as mentioned in cx_Freeze ImportError: cannot import name and documentation for cx_Freeze
Just append --include-modules serial.win32

Resources