Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
py2exe failed to compiled
#1
I am using Python 3.7.2 and py2exe 0.9.2.2
I have followed the tutorial from Py2exe Tutorial
But I am still failed to convert the script into executable file as I can't find any right solution through google search.

Log:
C:\Users\Jack Wong\Desktop\PythonTutorial>python setup.py py2exe
running py2exe
Traceback (most recent call last):
  File "setup.py", line 4, in <module>
    setup(console=['google.py'])
  File "C:\Users\Jack Wong\AppData\Local\Programs\Python\Python37\lib\distutils\core.py", line 148, in setup
    dist.run_commands()
  File "C:\Users\Jack Wong\AppData\Local\Programs\Python\Python37\lib\distutils\dist.py", line 966, in run_commands
    self.run_command(cmd)
  File "C:\Users\Jack Wong\AppData\Local\Programs\Python\Python37\lib\distutils\dist.py", line 985, in run_command
    cmd_obj.run()
  File "C:\Users\Jack Wong\AppData\Local\Programs\Python\Python37\lib\site-packages\py2exe\distutils_buildexe.py", line 188, in run
    self._run()
  File "C:\Users\Jack Wong\AppData\Local\Programs\Python\Python37\lib\site-packages\py2exe\distutils_buildexe.py", line 267, in _run
    builder.analyze()
  File "C:\Users\Jack Wong\AppData\Local\Programs\Python\Python37\lib\site-packages\py2exe\runtime.py", line 160, in analyze
    self.mf.import_hook(modname)
  File "C:\Users\Jack Wong\AppData\Local\Programs\Python\Python37\lib\site-packages\py2exe\mf3.py", line 120, in import_hook
    module = self._gcd_import(name)
  File "C:\Users\Jack Wong\AppData\Local\Programs\Python\Python37\lib\site-packages\py2exe\mf3.py", line 274, in _gcd_import
    return self._find_and_load(name)
  File "C:\Users\Jack Wong\AppData\Local\Programs\Python\Python37\lib\site-packages\py2exe\mf3.py", line 357, in _find_and_load
    self._scan_code(module.__code__, module)
  File "C:\Users\Jack Wong\AppData\Local\Programs\Python\Python37\lib\site-packages\py2exe\mf3.py", line 388, in _scan_code
    for what, args in self._scan_opcodes(code):
  File "C:\Users\Jack Wong\AppData\Local\Programs\Python\Python37\lib\site-packages\py2exe\mf3.py", line 417, in _scan_opcodes
    yield "store", (names[oparg],)
IndexError: tuple index out of range
setup.py
from distutils.core import setup
import py2exe

setup(console=['google.py'])
Previously I am used the pyinstaller to convert and it successful to execute the .exe file in my machine.
But failed to execute the .exe file to other machine that don't have Python installed.
After I searched, I found out that py2exe approach is able to execute the .exe file in Non-Python machine.

Please kindly advise.Thanks
Reply
#2
Py2exe stopped develop at Python 3.4 and do not work for newer versions.
Use pyinstaller work Python 3.7.
Look at posts in this Thread and my run in this post.
Reply
#3
(Feb-27-2019, 01:28 PM)snippsat Wrote: Py2exe stopped develop at Python 3.4 and do not work for newer versions.
Use pyinstaller work Python 3.7.
Look at posts in this Thread and my run in this post.

But if convert to .exe by using pyinstaller, the client computers are not able to execute the .exe files due to their computers have no Python installed.
That's why I am consider to using the py2exe.
But do you have any advises what should I do with pyinstaller, so that my client computers can execute the .exe files without needed to install Python in their computer?
Thanks for advance.
Reply
#4
(Feb-27-2019, 03:44 PM)gahhon Wrote: But if convert to .exe by using pyinstaller, the client computers are not able to execute the .exe files due to their computers have no Python installed.
That's why I am consider to using the py2exe.
Then you doing something wrong,like not aware that stuff can be outside(Python) link to OS that's need to be included.

Follow all in this post.
So if move power.exe to Pc without Python then it will work.
power.py is simple file with no external dependencies.

Look at Sound-player standalone,
see that i take step to include external OS dependencies AVbin avbin.dll(windows) and libavbin.so.10(Linux).
If i do not do this,it's not a standalone solution.
See also that i start with virtual environment,to have isolation from OS in first place before start troubleshoot.

Have to understand that there never will be one easy solution for doing building stuff like this.
py2exe had of course the same problem,if there where external dependencies.
Reply
#5
(Feb-27-2019, 04:47 PM)snippsat Wrote:
(Feb-27-2019, 03:44 PM)gahhon Wrote: But if convert to .exe by using pyinstaller, the client computers are not able to execute the .exe files due to their computers have no Python installed.
That's why I am consider to using the py2exe.
Then you doing something wrong,like not aware that stuff can be outside(Python) link to OS that's need to be included.

Follow all in this post.
So if move power.exe to Pc without Python then it will work.
power.py is simple file with no external dependencies.

Look at Sound-player standalone,
see that i take step to include external OS dependencies AVbin avbin.dll(windows) and libavbin.so.10(Linux).
If i do not do this,it's not a standalone solution.
See also that i start with virtual environment,to have isolation from OS in first place before start troubleshoot.

Have to understand that there never will be one easy solution for doing building stuff like this.
py2exe had of course the same problem,if there where external dependencies.

I think I know the clue already.
I have to install the pipenv.
Then using the pipenv to install pyinstaller, selenium, and any other libraries that I had import in my script.
Then in my script, I must add the pyglet.lib.load_library('avbin.dll') pyglet.have_avbin=True
But in your post, you were mentioned that pyglet & avbin is for the playing. But what if for Selenium?
Reply
#6
(Feb-27-2019, 05:45 PM)gahhon Wrote: Then in my script, I must add the pyglet.lib.load_library('avbin.dll') pyglet.have_avbin=True
But in your post, you were mentioned that pyglet & avbin is for the playing. But what if for Selenium?
Do you not understand that this a example of including external dependencies and has nothing to with your build.
You should of course not add pyglet & avbin in your build,why do i even need to explain this Dodgy

Selenium has at least one external dependencies which is the web-driver,
so a simple solution could eg to have chromedriver.exe together with the build .exe.
I have build Selenium with pyinstaller before(working),but it's long time ago so don't remember all the build steps.
Reply
#7
(Feb-27-2019, 06:05 PM)snippsat Wrote:
(Feb-27-2019, 05:45 PM)gahhon Wrote: Then in my script, I must add the pyglet.lib.load_library('avbin.dll') pyglet.have_avbin=True
But in your post, you were mentioned that pyglet & avbin is for the playing. But what if for Selenium?
Do you not understand that this a example of including external dependencies and has nothing to with your build.
You should of course not add pyglet & avbin in your build,why do i even need to explain this Dodgy

Selenium has at least one external dependencies which is the web-driver,
so a simple solution could eg to have chromedriver.exe together with the build .exe.
I have build Selenium with pyinstaller before(working),but it's long time ago so don't remember all the build steps.

Yes. I did put the chromedriver.exe together with my build.exe and test it on NON-Python machine, but the error is saying
Error loading Python DLL
'.....\python37.dll'
LoadLibrary: Pyinstaller: FormatMessagW Failed.

And I also found this Create a Python executable with chromedriver & Selenium
Will give it a shot by tomorrow.
Reply
#8
A quick test,an you have to read the doc.
So can use spec file that get create every time run pyinstaller or add stuff with commands.
Adding binary from commands.
pyinstaller --onefile --console --add-binary chromedriver.exe;. duck_go.py 
In spec file it look like this '.' or command line ;. means find file in folder you run from an add it to build.
binaries=[('chromedriver.exe', '.')],
So when i build i have chromedriver.exe is same folder as .py file,and no path giver to chromedriver.exe in .py file.
browser = webdriver.Chrome(executable_path=r'chromedriver.exe')
If move .exe to other Pc it work when in this test.
Reply
#9
(Feb-27-2019, 08:49 PM)snippsat Wrote: A quick test,an you have to read the doc.
So can use spec file that get create every time run pyinstaller or add stuff with commands.
Adding binary from commands.
pyinstaller --onefile --console --add-binary chromedriver.exe;. duck_go.py 
In spec file it look like this '.' or command line ;. means find file in folder you run from an add it to build.
binaries=[('chromedriver.exe', '.')],
So when i build i have chromedriver.exe is same folder as .py file,and no path giver to chromedriver.exe in .py file.
browser = webdriver.Chrome(executable_path=r'chromedriver.exe')
If move .exe to other Pc it work when in this test.

I am trying. Will let you know soonly.
Reply
#10
(Feb-27-2019, 08:49 PM)snippsat Wrote: A quick test,an you have to read the doc.
So can use spec file that get create every time run pyinstaller or add stuff with commands.
Adding binary from commands.
pyinstaller --onefile --console --add-binary chromedriver.exe;. duck_go.py 
In spec file it look like this '.' or command line ;. means find file in folder you run from an add it to build.
binaries=[('chromedriver.exe', '.')],
So when i build i have chromedriver.exe is same folder as .py file,and no path giver to chromedriver.exe in .py file.
browser = webdriver.Chrome(executable_path=r'chromedriver.exe')
If move .exe to other Pc it work when in this test.

Okay. It appear that the chrome browser is launched, but I got the log error saying that IndexError: ('list index out of range',)
This error doesn't appear in my local, but in my client computer.
Any idea tho?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [split] Py2exe Writing UNKNOWN-0.0.0-py3.7.egg-info sarahroxon7 1 908 Apr-20-2022, 08:02 AM
Last Post: VadimCr
  Py2exe and pycryptodome reks2004 5 4,095 Dec-16-2020, 06:42 PM
Last Post: reks2004
  I need my compiled Python Mac app to accept a file as a parameter Oethen 2 2,357 May-10-2020, 05:57 PM
Last Post: Oethen
  compiled cpython output wrong version bigrockcrasher 0 1,480 Feb-25-2020, 06:31 PM
Last Post: bigrockcrasher
  Py2exe Writing UNKNOWN-0.0.0-py3.7.egg-info Rickus 2 3,609 Feb-18-2020, 03:09 PM
Last Post: Rickus
  Hello Im looking for a compiled window version of 3.4.x ... SlowMotion 2 2,173 Feb-12-2019, 08:13 PM
Last Post: SlowMotion
  What are ways of pointing cross-compiled origin source line for python? wyvogew 2 2,773 Feb-02-2019, 03:16 PM
Last Post: wyvogew
  py2exe keegan_010 4 4,436 Aug-22-2018, 07:58 AM
Last Post: buran
  How would I combine multiple .py files into one .exe with Py2Exe shlomi27 0 3,066 Aug-20-2018, 10:27 AM
Last Post: shlomi27
  jira-2.0.0.dist causing error with py2exe johnlawlor 1 2,483 Aug-09-2018, 08:27 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020