Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Creating an executable
#1
Hi.

I'm trying to create an executable file from a Python script.
I'm running Python v. 3.7 & Pycharm.

I tried "pyinstaller", but that didn't work.
I found out later that pyinstaller is no longer in use
for my version of python.

I then tried "cx_Freeze". That also didn't work.
When I run the executable file it creates, the window closes
almost immediately. So, I can't see the text in the window.

My Python script opens images & audio files in 2 different folders.

I tried going to Python.org docs & help, but it was useless.
It just sent me to this link:
https://docs.python.org/3/faq/windows.ht...hon-script

What do you recommend?
Reply
#2
(Apr-02-2020, 04:26 AM)vman44 Wrote: I tried "pyinstaller", but that didn't work.
I found out later that pyinstaller is no longer in use
for my version of python.
that is simply not true.
What went wrong using pyinstaller?

(Apr-02-2020, 04:26 AM)vman44 Wrote: What do you recommend?
Debug the problem using pyinstaller
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
Here is the video that stated that
pyinstaller cannot be used in Python anymore.
The video is in Hindi. Sorry, I don't have
the English translation for it.

https://www.youtube.com/watch?v=yp1FmtIXG_w


How would you recommend I approach debugging
the pyinstaller issue?
Reply
#4
(Apr-02-2020, 05:36 PM)vman44 Wrote: How would you recommend I approach debugging the pyinstaller issue?
for start read When things go wrong

most common causes of problems are shown there. One is hidden imports - sometimes pyinstaller cannot find an import. in this case you need to "help" by explicitly specifying them with --hidden-import option or by editing the spec file.
Another common problem is whit some paths. There is example script that helps to understand which path is what exactly

How to debug - is there problem while running pyinstaller? is there a problem with generated exe? any debug information that is printed?
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#5
Sorry for the delay in posting this.

Pyinstaller runs w/o giving any errors.

The problem is when I run the actual executable file.
It says "failed to execute script.py"

I tried putting all the images & audio files into the same folder
as my script file. I then ran pyinstaller as:
pyinstaller -w -add-data*img file 1* -add-data*img-file 2*, etc. script.py

That didn't help. The only thing that changed was that when I ran
the executable, it opened a black window on my screen & then it gave
me the annoying window about "failed to execute script.py"

I'm thinking I need to make a spec file.
I couldn't find any tutorial on this topic.
If there are any available, please let me know.
Reply
#6
the documentation is very good, look at it.
Also,as I explained in my prevous post, you need to make sure your script is able to find the images it use (i.e. no hardcoded paths, etc). Look at this example script that show which folder is what. What you describe as error looks very much like problem with paths to images or missing imports
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#7
buran,

Thanks. I've been going through those links & webpages.

In the script I wrote, there are 2 folders my script is accessing:
** 'alpha\english\*.png' --> contains image files, in .png format
** 'alpha\english\audio\*.wav --> contains audio files, in .wav format

I modified my "aaaaa.spec" file, by using:
....
datas=[ ('alpha\english\*.png', 'alpha\english'), ('alpha\english\audio\*.wav', 'audio') ],
....

When I run pyinstaller, it gives me this error:
33955 INFO: Appending 'datas' from .spec
Unable to find "alpha\englishudio\*.wav" when adding binary and data files.

I'm not sure what's going on.
Also, I should note, there is one '.mp3' file in my 'alpha\english\audio\' folder.
My script calls the mp3 file.

How do I account for these issues?
Reply
#8
it looks like your datas are relative and it cannot find them. you can specify optional pathex to list paths it should search in.
Also, you call mp3 file, but never add it to executable?
Also make sure your paths are not hard coded in the code, i.e. they should not rely on the fixed location where they reside before making the exe. You need to make sure you use the one included in the exe.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#9
My script file has the following:
=================================
img_folder = 'alpha\\english\\'
eng_audio_folder = 'alpha\\english\\audio\\'
.....
Later, in my script, as part of a list definition:
pygame.image.load(resource_path(img_folder + "q.png")), pygame.image.load(resource_path(img_folder + "r.png")),
.....
I also define the following function:
def pronounce(a):
soundfile = resource_path(eng_audio_folder + a + '.wav')
pygame.mixer.music.load(soundfile)
pygame.mixer.music.play(-1)
time.sleep(1.6)
return
.....
Inside another function:
pygame.mixer.music.load(resource_path(eng_audio_folder + "Birdcall.mp3"))
pygame.mixer.music.play(-1)
=================================
Everything works fine when I run the script from Pycharm.
I can successfully create an executable file w/ simpler Python scripts,
where it doesn't use image files and/or audio files.

Isn't that relative coding? I don't use "C:\ ...." for my directories.
Also, how do I add the mp3 file to the spec file?
Should I convert it to a .wav file?

I'll try to modify the PATHEX parameter in the spec file later today.

Thanks.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Creating an executable from a script wolf8963 6 5,787 May-11-2020, 05:23 PM
Last Post: wolf8963

Forum Jump:

User Panel Messages

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