Packaging winpexpect with pyinstaller - python

I've attempted to create a pretty basic executable with pyinstaller, but when I run it winpexpect (a windows version of pexpect) throws me a pretty undecipherable error. I've really only been able to deduce that the error occurs when using the winspawn class.
C:\Users\Dan\Dropbox\Programming\Python\MC\ServerSense>ServerSense.exe
Traceback (most recent call last):
File "<string>", line 170, in <module>
File "<string>", line 52, in __init__
File "C:\Users\Dan\Dropbox\Programming\Python\Packagers\PyInstaller\PyInstalle
r-2.1\ServerSense\build\ServerSense\out00-PYZ.pyz\winpexpect", line 346, in __in
it__
File "C:\Users\Dan\Dropbox\Programming\Python\Packagers\PyInstaller\PyInstalle
r-2.1\ServerSense\build\ServerSense\out00-PYZ.pyz\pexpect", line 429, in __init_
_
File "C:\Users\Dan\Dropbox\Programming\Python\Packagers\PyInstaller\PyInstalle
r-2.1\ServerSense\build\ServerSense\out00-PYZ.pyz\winpexpect", line 401, in _spa
wn
pywintypes.error: (2, 'CreateProcess', 'The system cannot find the file specifie
d.')
Can anyone provide some insight as to how I'd go about packaging winpexpect with pyinstaller? It doesn't even seem to be letting me know which file it can't find.

Figured it out, I used the fork of winpexpect over here: https://bitbucket.org/weyou/winpexpect/wiki/Home
Which has cx_freeze support, (py2exe works too, it's what I used.)

Related

Py2App>0.13 always outputs ValueError/ Py2App v0.13 App not opening on second machine

So I finally got my python program working on my Mac (Catalina 10.15.4), but I am greeted with the following error when it is opened on another Mac (High Sierra 10.13.6.)
Could not import the PyAudio C module '_portaudio'.
Traceback (most recent call last):
File "/Volumes/dist/Riff Gen.app/Contents/Resources/__boot__.py", line 355, in <module>
_run()
File "/Volumes/dist/Riff Gen.app/Contents/Resources/__boot__.py", line 340, in _run
exec(compile(source, path, 'exec'), globals(), globals())
File "/Volumes/dist/Riff Gen.app/Contents/Resources/riffgen_v1.01.py", line 9, in <module>
from pysine import sine
File "pysine/__init__.pyc", line 14, in <module>
File "pysine/pysine.pyc", line 1, in <module>
File "pyaudio.pyc", line 116, in <module>
ImportError: dlopen(/Volumes/dist/Riff Gen.app/Contents/Resources/lib/python3.6/lib-dynload/_portaudio.so, 2): Symbol not found: ____chkstk_darwin
Referenced from: /Volumes/dist/Riff Gen.app/Contents/MacOS/../Frameworks/libportaudio.2.dylib (which was built for Mac OS X 10.15)
Expected in: /usr/lib/libSystem.B.dylib
in /Volumes/dist/Riff Gen.app/Contents/MacOS/../Frameworks/libportaudio.2.dylib
A simple tkinter test with various sounds and images works fine on the second machine, but not this script. I've tried adding all the packages manually, tried --nostrip, manually including 'libportaudio.2.dylib', and dozens of other ideas from countless outdated forums to no avail.
When the play function of my application is stripped, the app opens and crashes shortly thereafter - giving me the following error:
Traceback (most recent call last):
File "/Volumes/RG no audio/Riff Gen.app/Contents/Resources/__boot__.py", line 81, in <module>
_run()
File "/Volumes/RG no audio/Riff Gen.app/Contents/Resources/__boot__.py", line 66, in _run
exec(compile(source, path, 'exec'), globals(), globals())
File "/Volumes/RG no audio/Riff Gen.app/Contents/Resources/riffgen_v1.01.py", line 2037, in <module>
root.mainloop()
File "tkinter/__init__.pyc", line 1277, in mainloop
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte
Fatal Python error: PyEval_RestoreThread: NULL tstate
Current thread 0x00007fffa118e380 (most recent call first):
Abort trap: 6
logout
Saving session...
...copying shared history...
...saving history...truncating history files...
...completed.
Deleting expired sessions...none found.
[Process completed]
I have been using Python 3.6 and Py2App v0.13 because it is, unfortunately, the only version that has successfully packaged my program in a standalone package. Any version later than 0.13 gives me the following error even when bundling in alias mode:
Traceback (most recent call last):
File "/Users/Alex/Desktop/python_scripts/rhythm_generator/riffgen/dist/Riff Gen.app/Contents/Resources/__boot__.py", line 420, in <module>
_run()
File "/Users/Alex/Desktop/python_scripts/rhythm_generator/riffgen/dist/Riff Gen.app/Contents/Resources/__boot__.py", line 414, in _run
exec(compile(source, script, 'exec'), globals(), globals())
File "/Users/Alex/Desktop/python_scripts/rhythm_generator/riffgen/riffgen_v1.01.py", line 7, in <module>
from tkinter import *
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/tkinter/__init__.py", line 36, in <module>
import _tkinter # If this fails your Python may not be configured for Tk
ValueError: character U+6573552f is not in range [U+0000; U+10ffff]
I've seen a handful of people with similar errors to the one above, but the few solutions I've seen had no success.
I'm assuming there is a simple solution to both of these errors, but after a long two weeks of tinkering, I'm out of ideas. I just began programming and really want to continue to deploy GUI programs, so I am desperate to get this functional. Any help is greatly appreciated!!
Probably not an answer you were hoping for, but this might give you some ideas where to look:
check if you don't have multiple pythons installed. Make sure you run it with 3.6. (but you probably already did)
Check the modules installed on both PC's help('modules') in a python shell.
Check if the correct version of the modules is installed. Install the exact same versions pip install SomePackage==1.0.4
Symbol not found: ____chkstk_darwin seems to be a very mac related issue. I'd start searching there in combination with the modules you use in your script. This is the only post I found on stackoverflow and it suggests looking at the PATH settings; plaidml-setup uses the wrong lib path and gets OSErrors

python exe file crashes while launching on windows xp

I have a python program that used Tkinter, matplotlib, numpy.
It was builded successfully on my windows 8 host system by py2exe and running as well.
I have one system based on windows 7 where this program (builded on windows 8) working too.
But when i trying to start this program on windows xp sp3, i get error in log file with a content of:
Traceback (most recent call last):
File "DrawPlots.py", line 6, in <module>
File "graph_ani2.pyc", line 4, in <module>
File "numpy\__init__.pyc", line 170, in <module>
File "numpy\add_newdocs.pyc", line 13, in <module>
File "numpy\lib\__init__.pyc", line 8, in <module>
File "numpy\lib\type_check.pyc", line 11, in <module>
File "numpy\core\__init__.pyc", line 46, in <module>
File "numpy\testing\__init__.pyc", line 13, in <module>
File "numpy\testing\utils.pyc", line 15, in <module>
File "tempfile.pyc", line 35, in <module>
File "random.pyc", line 885, in <module>
File "random.pyc", line 97, in __init__
File "random.pyc", line 113, in seed
WindowsError: [Error -2146893795]
As i can suggest - is it problem with numpy? If yes, then how can i resolve it?
I faced a similar problem, PyFactura issue #3, the solution seems to be removing crypt32.dll from the bundled DLLs (py2exe setup options, for more info see aws-cli):
# basic options for py2exe
opts = {
'py2exe': {
'dll_excludes': ['crypt32.dll'],
}
}
You may need to exclude other specific Windows 8.1 DLL too (API-MS-Win-Core-*.dll)
I also had this error, concretely this output:
WindowsError: [Error -2146893795] Provider DLL failed to initialize correctly
This happened at a call to os.urandom.
This was in a subprocess.
The bug for me was that I called _subprocess.CreateProcess with an env_mapper = {'foo': 'bar'}. The fix:
env_mapper = os.environ.copy()
env_mapper.update({'foo': 'bar'})
Note that there is a related question here.
And some discussion on this GitHub issue.
And this related Python bug.
All those seem to be related to crypt32.dll in a frozen Python app, or via py2app.

How to install subprocess module for python?

pip is not able to find this module, as well as me on pypi website.
Could you please tell me the secret, how to install it?
I need the module to spawn new shell process via subprocess.call. I have seen a lot of examples, where people use import subprocess, but no one shows how it was installed.
Error, that i got (just in case i've lost my mind and does not understand what is going on):
Microsoft Windows [Version 6.3.9600]
(c) 2013 Microsoft Corporation. All rights reserved.
C:\Users\Alexander\Desktop\tests-runner>python run.py
Traceback (most recent call last):
File "run.py", line 165, in <module>
main()
File "run.py", line 27, in main
subprocess.call('py.test')
File "C:\Python27\lib\subprocess.py", line 522, in call
return Popen(*popenargs, **kwargs).wait()
File "C:\Python27\lib\subprocess.py", line 710, in __init__
errread, errwrite)
File "C:\Python27\lib\subprocess.py", line 958, in _execute_child
startupinfo)
WindowsError: [Error 2] The system cannot find the file specified
There is no need to install this module in Python 2.7. It is a standard module that is built in.
The documentation shows that it was added to the library for Python version 2.4. It's been with us for a long time now.
The error that you show in your question update is nothing more prosaic than a file not found error. Likely the executable file that you are attempting to call Popen on cannot be found.
That traceback indicates that subprocess is installed and has been imported. The problem is simply that the call to subprocess.call('py.test') is failing.
For future reference, this is the type of traceback you encounter when attempting to import a module that has not been installed:
>>> import foo
Traceback (most recent call last):
File "", line 1, in
ImportError: No module named foo
The error-text is misleading. Most subprocess-commands expect the shellcmd to be submitted as a list of strings.
In these cases i strongly recommend the usage of the shlex module:
import shlex
shell_cmd = "test.py"
subprocess_cmd = shlex.split(shell_cmd)
subprocess.call(subprocess_cmd)
or in this simple case just:
subprocess.call(["test.py"])

Python pyinstaller and translit module

I'm using module transliterate.py from standard translit python libraries.
When I compile my GUI application, it raises the next error.
Traceback (most recent call last):
File "C:\Users\...\...\build\Rman\out00-PYZ.pyz\addobjectdialog", line 265, in OnTextName
File "C:\Users\...\...\build\Rman\out00-PYZ.pyz\core.utils", line 536, in translit
File "C:\Users\...\...\build\Rman\out00-PYZ.pyz\transliterate.utils", line 41, in translit
File "C:\Users\...\...\build\Rman\out00-PYZ.pyz\transliterate.utils", line 29, in ensure_autodiscover
File "C:\Users\...\...\build\Rman\out00-PYZ.pyz\transliterate.discover", line 27, in autodiscover
WindowsError: [Error 3] : 'C:\\...\\...\\AppData\\Local\\Temp\\_MEI11122\\transliterate\\contrib\\languages/*.*'
How I understand, I have to place
that lib somewhere within my application. But I just compile one .exe file, so wouldn't like to keep yet one file with my exe.
BTW, app is ran under Win 7 / 32bit.
Thanks.
That may be one of those libraries that you have to include explicitly. I know I had to do that from time to time with py2exe. See the following docs for more information:
http://pythonhosted.org/PyInstaller/#options-for-finding-imported-modules-and-libraries

py2exe + pywin32 MemoryLoadLibrary import fail when bundle_files=1

I have created a simple program which uses pywin32. I want to deploy it as an executable, so I py2exe'd it. I also didn't want a huge amount of files, so I set bundle_files to 1 (meaning bundle everything together). However, when I attempt running it, I get:
Traceback (most recent call last):
File "pshelper.py", line 4, in <module>
File "zipextimporter.pyc", line 82, in load_module
File "win32.pyc", line 8, in <module>
File "zipextimporter.pyc", line 98, in load_module
ImportError: MemoryLoadLibrary failed loading win32ui.pyd
In my setup script, I tried doing packages=["win32ui"] and includes=["win32ui"] as options, but that didn't help. How can I get py2exe to include win32ui.pyd?
I don't have this problem if I don't ask it to bundle the files, so I can do that, for now, but I'd like to know how to get it to work properly.
Are you sure that the problem is that win32ui.pyd is not included? The stack trace isn't exactly the same as noted in the wiki, but check this out: http://www.py2exe.org/index.cgi/Py2exeAndWin32ui.
The work-around that has worked best so far is to simply re-implement the pywin32 functions using ctypes. That doesn't require another .pyd or .dll file so the issue is obviated.
Do care to try out PyInstaller? I've used it both on Windows 7 and Ubuntu 10.04 and it worked like magic, even when I compiled to .pyd on Windows.
I've been able to bundle all sorts of applications that I've developed with it.
I have the same problem trying to bundle psutil with py2exe. Here is what I found so far.
Traceback (most recent call last):
File "wx_gui.py", line 43, in <module>
File "zipextimporter.pyc", line 82, in load_module
File "psutil\__init__.pyc", line 85, in <module>
File "zipextimporter.pyc", line 82, in load_module
File "psutil\_psmswindows.pyc", line 15, in <module>
File "zipextimporter.pyc", line 98, in load_module
ImportError: MemoryLoadLibrary failed loading _psutil_mswindows.pyd
I get this traceback when bundle_files = 3. zipfile may be specified or may be None, I still get the problem.
First, I thought this was a missing dll because of this page:
http://www.py2exe.org/index.cgi/ProblemsToBeFixed
I've copied all the dlls I found in Python27 into the same directory as the executable and added that directory path to os.environ['path']. That didn't worked.
Then I tried to import my package directly from site-packages.
I've replaced the whole sys.path of my compiled executable with my normal sys.path
sys.path = [r'C:\Python27\Lib\idlelib', ...]
I think the .pyd module got imported but Visual c++ threw me this really ugly error message:
Runtime Error!
Program: {path}.exe
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
I suggest you try to replace the whole sys.path to see if it is working. If it is, you could always make your single executable write the necessary module into a temp directory and add it to your path. If not, I feel like this problem is going to be hard to solve.

Categories