Py2exe cannot be convert python script to Windows executables - python

I want to make the python script into Windows executable with py2exe. I did not miss MSVCP90.dll and the Feiwings.py(the file that I use for transforming) and setup.py are under the same path. Doing those things under command window, everything works fine, the last lines of the traceback here are:
**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
The setup.py has the content like this:
from distutils.core import setup
import py2exe
setup(console=['D:\python\Feiwings.py'])
When I cd the path to dist directory, it got an error.
Traceback (most recent call last):
File "Feiwings.py", line 2, in <module>
File "PySide\__init__.pyc", line 45, in <module>
File "PySide\__init__.pyc", line 43, in _setupQtDirectories
UnboundLocalError: local variable 'path' referenced before assignment
Thanks in advance!

It seems something is wrong in your PySide distribution. From the traceback, it shows a problem in the second line of your Feiwings program. In this line there is probably an import statement where you import something from PySide, right?
Apart from the py2exe problem, are you able to execute your code normally without raising the same error?
If so, I would guess that you should include other packages dependencies (eg.: PySide) in your setup, something similar to:
setup(packages=['PySide'],
console=['D:\python\Feiwings.py'])
Hope it helps!

Check the variable 'path' in the program. It seems not a error of Pyside(assuming that you have properly installed Pyside) but the way you have used the variable 'path'. Having a look at the error it seems you have used variable 'path' before assigning it any value.

Related

*.py script with tkinterdnd2 module doesn`t compile to an executable file

I made an app that uses tkinter and tkinterdnd moudles. It works completely fine when I launch it as a script, however when I try to make and executable file from it and laucnh it, foloowing error ocures:
Traceback (most recent call last):
File "TkinterDnD2\TkinterDnD.py", line 53, in _require
_tkinter.TclError: can't find package tkdnd
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "IxcomGUI.py", line 128, in <module>
File "IxcomGUI.py", line 11, in __init__
File "TkinterDnD2\TkinterDnD.py", line 285, in __init__
File "TkinterDnD2\TkinterDnD.py", line 55, in _require
RuntimeError: Unable to load tkdnd library.
[14512] Failed to execute script 'IxcomGUI' due to unhandled exception!
I tried following:
Installed tkinterdnd2 with pip install and built with pyinstaller myscript.py.
Manually installed tkinterdnd2 module as shown in this video https://www.youtube.com/watch?v=JIy0QjwQBl0&t=605s&ab_channel=RamonWilliams and built with pyinstaller myscript.py
Repeated previous step, but added this thing https://github.com/pmgagne/tkinterdnd2/blob/master/hook-tkinterdnd2.py
Tried to implicitly tell pyinstaller path to tkdnd module with specifying path to the module with --paths flag.
All this attempts led to error bellow. Does anyone know some kind of solution?
The issue here is that Drag n Drop requires two components: the TCL libraries and the Tkinter interface to them. I install both manually to config my environment. (See my answer to How to Install and Use TkDnD with Python Tkinter on OSX?). I know someone packaged something on PyPI for the TkinterDnD2, but I haven't looked into it.
I have a project which uses TkinterDnD2. I build it with PyInstaller and see the same error you see (more or less). Running PyInstaller with the --onedir option (rather than the --onefile option), I saw that tkdnd2.8 was missing from my dist directory.
To rectify this, on Windows, I added
--add-binary "C:/Python/Python38-32/tcl/tkdnd2.8;tkdnd2.8"
to the PyInstaller command line, and that did the trick. I can now build a --onefile executable, and it runs without error.
Apparently it was unnexpectedly easy to fix this issue. All you need to is to get to the <YourPath>\Python39\tcl directory and find tkdnd2.8 directory, and move it to the tcl8.6 directory. I have also renamed it to just tkdnd, however I don't know whether it's necessary.
Here is the original link that saved my day: http://pyinstaller.47505.x6.nabble.com/tkinter-TclError-can-t-find-package-tkdnd-td2330.html
I'm using tkinterdnd2 installed from pip, and not TkinterDnD.
What really worked for me was this flag:
--add-data "C:/Users/myName/AppData/Local/Packages/PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0/LocalCache/local-packages/Python39/site-packages/tkinterdnd2;tkinterdnd2"
It expects tkdnd to be a folder inside tkinterdnd2. Just using additional-hooks/hidden import on tkinterdnd2 and tkdnd did now preserve that subfolder structure.

Pyinstaller builds file but chokes on certain .dlls

When I run my py program it works the way I intended it to. If I am on a Linux box and build an executable using Pyinstaller, it builds without issue and executes without issue. I have scoured the Pyinstaller docs, git, etc. none of the posted fixes helped
I am still very new at python and feel like it might be a simple fix and might be over thinking the issue
Why can I no build a functional .exe on a windows based system using pyinstaller?
Windows 10 system
Pyinstaller version 3.2
Python version 3.5.2
This is a GUI program using appJar which is also up to date.
The file does build, but errors "Could not execute script"
EDIT
Not sure if this is best to edit in line like this but...
So studying the output and making adjustments, the issue seems to be appJar.py. For some reason it is missing assets, I am looking into it. The trouble is that I am still not used to looking at this kind of output and am not sure where to start.
C:\Users\_User_>C:\temp\fileCreatorGUI\fileCreatorGUI.exe
Traceback (most recent call last):
File "F:\Users\_User_\python_working\fileCreatorGUI.py", line 73, in <module>
app = gui()
File "C:\Users\_User_\AppData\Local\Programs\Python\Python35\lib\site-packages\appJar\appjar.py", line 509, in __init__
self.topLevel.wm_iconbitmap(self.appJarIcon)
File "C:\Users\_User_\AppData\Local\Programs\Python\Python35\lib\tkinter\__init__.py", line 1716, in wm_iconbitmap
return self.tk.call('wm', 'iconbitmap', self._w, bitmap)
_tkinter.TclError: bitmap "C:\temp\fileCreatorGUI\appJar\resources\icons\favicon.ico" not defined
Failed to execute script fileCreatorGUI
Edit 2
See answer below, but I was barking up the wrong tree on this one,
The Pyinstaller output chokes on the .dll's:
api-ms-win-core-console-l1-1-0.dll
api-ms-win-core-datetime-l1-1-0.dll
(There are like ~40 of these)
I added those .dll's to the python path, I declared them in the bianaries in the .spec file.
here is a truncated log:
2414 WARNING: Can not get binary dependencies for file: C:\Windows\system32\api-
ms-win-crt-stdio-l1-1-0.dll
Traceback (most recent call last):
File "C:\Users\_USER_NAME\AppData\Local\Programs\Python\Python35-32\lib\site-pa
ckages\PyInstaller\depend\bindepend.py", line 695, in getImports
return _getImports_pe(pth)
File "C:\Users\_USER_NAME\AppData\Local\Programs\Python\Python35-32\lib\site-pa
ckages\PyInstaller\depend\bindepend.py", line 122, in _getImports_pe
dll, _ = sym.forwarder.split('.')
TypeError: a bytes-like object is required, not 'str'
2423 WARNING: Can not get binary dependencies for file: C:\Windows\system32\api-
ms-win-crt-heap-l1-1-0.dll
I tried the fix listed here:
https://github.com/pyinstaller/pyinstaller/pull/1981
but it did not seem to make a difference.
Someone recommended adding the sys.path.insert() route but it did not make a difference either way
I also tried this in a VM with windows 7, clean install, no change. My next step is to try to use Wine in Debian, but I don't really want to go that route. Any help would be appreciated. Thank you
Turns out this was an appJar/packaging issue, the pyinstaller was not looking in the correct directory for the assets. per the dev of appJar, I commented out two lines of code in the appJar.py, lines 508-509:
if self.platform == self.WINDOWS:
self.topLevel.wm_iconbitmap(self.appJarIcon)
More on the specifics here: https://github.com/jarvisteach/appJar/issues/84
I probably can fix this by using the --path argument with pyinstaller but for the moment, the issue is fully resolved

Error Importing SHTOOLS Python Package

I am trying to import the spherical harmonic toolbox (SHTOOLS) in python. I have the files downloaded and unzipped and am using RedHat.
I added the package's path to my python system path and when I go to import the package, I get this error:
>>import pyshtools
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "pyshtools/__init__.py", line 49, in <module>
load_documentation()
File "pyshtools/__init__.py", line 27, in load_documentation
from . import _SHTOOLS
ImportError: cannot import name _SHTOOLS
I can not seem to figure out what the issue is. I checked that the path to this folder was actually added to the system path and it was.
Is this an issue on my end? Or is it possible that I have something downloaded incorrectly? If so, how would I go about fixing this issue?
The SHTOOLS package needs to be built with make first to compile the Fortran libraries. The wiki on Github gives directions on which libraries are required - libblas-dev, liblapack-dev, g++, gfortran, and libfftw3-dev (these are the Ubuntu packages, they may have slightly different names on Redhat). Once these are installed, you need to run make, then sudo make all to install the Fortran and Python components. The Makefile has a lot of good comments in it, I'd recommend reading through it before running make.

Python import error on Windows: no __path__

OK, trying to track down this issue of running a Python package.
Running on Windows.
Only one version of Python is installed on the computer: 3.4.3
Package has been installed (package name: Willie) (details of installation are more convoluted than usual; can provide steps if necessary)
Package installed at: C:\Python34\Lib\site-packages\willie
Startup script is: C:\Python34\Scripts\willie.py
Error is one of the first lines of the script:
from willie.tools import stderr
If I run willie.py from the command line, I get this error:
Traceback (most recent call last):
File "<frozen importlib._bootstrap>", line 2218, in _find_and_load_unlocked
AttributeError: 'module' object has no attribute '__path__'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Python34\Scripts\willie.py", line 15, in <module>
from willie.tools import stderr
File "C:\Python34\Scripts\willie.py", line 15, in <module>
from willie.tools import stderr
ImportError: No module named 'willie.tools'; 'willie' is not a package
The __path__ attribute is supposed to be set automatically when the import function is used, but it doesn't exist, which leads to the program being unable to execute.
C:\Python34\Scripts; is in my Path environment variable.
PYTHONPATH has been set for everything from C:\Python34; to C:\Python34;C:\Python34\Lib;C:\Python34\Lib\site-packages;C:\Python34\Lib\site-packages;C:\Python34\Lib\site-packages\willie;C:\Python34\Lib\site-packages\willie\tools;.
In all cases with these directories, if I try to execute the above import command from the interactive Python prompt, it runs correctly. I can use the stderr function, and examine its __file__ and __path__ fields.
If I add C:\Python34\Scripts; to PYTHONPATH, however, I get the same error as using it from the command line: __path__ doesn't exist, 'willie' is not a package.
I do know that willie.py is being called recursively, somehow, because I can add a print() at the top of the file that runs twice.
Looking for help in figuring out how to make this run. Is almost certainly a configuration issue on my end, but I have no idea what to do to fix it.
First, you absolutely do not want c:\Python34\Scripts in your PYTHONPATH. Files under \Scripts are NOT meant to be importable.
Second, willie does some screwing around to make sure willie.py gets installed to c:\Python34\Scripts\willie (note there is no .py suffix). This is decidedly nonstandard. The only reason this even works is because on Unix machines, the first line of that file is a special "shebang" that tells the Unix program launcher to execute the file using Python. There is no equivalent feature on Windows - naming the file willie with no .py means you simply can't execute it.
So it looks like the module willie is simply not prepared to be installed on Windows systems. (#811 and #822 both refer to weirdness on Windows caused by the nonstandard package setup.)
A standard package setup would have willie.py inside the willie package as willie/main.py and, in the package's setup.py, register willie.main as an "Entry Point" named willie. This incantation would create c:\Python34\Scripts\willie.exe on Windows systems when the package is installed using pip.
I believe the reason for the recursive import is because the second entry in sys.path is the name of the script that is run from the command line. So, it's always finding C:\Python34\Scripts\willie.py when it looks for the module willie which is not the one it needs.
As a workaround, you could try renaming C:\Python34\Scripts\willie.py to C:\Python34\Scripts\run-willie.py

Jython 2.5.1: "ImportError: No Module named os"

I looked through the other posts and bug reports and couldn't figure out what's causing this. I'm using Jython 2.5.1, in a Java project in Eclipse (Ubuntu 8.10). It has been added to the project as a standalone .jar file (I just replaced the old Jython 2.1 jar with this one).
I'm running a script that uses the threading.py class. At some point the statement "import os" is evaluated from linecache.py and I get this error, which I can't seem to figure out how to fix:
'Execution failed. Traceback (most recent call last):
File "<string>", line 1, in <module>
File "../lib/python/threading.py", line 6, in <module>
import traceback
File "../lib/python/traceback.py", line 3, in <module>
import linecache
File "../lib/python/linecache.py", line 9, in <module>
import os
ImportError: No module named os'
What do you mean with "the jar that comes with the 2.5 download"? Did you extract the contents and use jython.jar or did you run the installer? If you just extracted and didn't run the installer your jython.jar will miss the whole LIB folder.
Can you check if jython.jar contains a LIB folder? (e.g. open jython.jar with 7z or WinZip).
Or try copying the LIB folder in the same folder where jython.jar resides.
Did you try setting these properties. Jython Registry. e.g. via -Dpython.home in the eclipse run configuration.
python.cachedir
python.path
python.home
How is the jar named? If similar to jython-complete.jar try renaming it to jython.jar
Something is wrong at a very deep level, but it's probably easy to fix. You are seeing an error that happens while trying to report some other error.
Probably you have your PYTHONPATH misconfigured. I don't know the details of Jython or Eclipse running Jython, but it looks like you have no standard library available to you.
If you are getting maven, using the dependency jython-standalone instead of jython may help (at least it did for me in a maven project with jython-standalone-2.5.3)

Categories