Speeding up an .exe created with PyinstallerHow can I safely create a nested directory in Python?How can you speed up Eclipse?Why is the Android emulator so slow? How can we speed up the Android emulator?Create a dictionary with list comprehension in PythonSpeed comparison with Project Euler: C vs Python vs Erlang vs HaskellWay to create multiline comments in Python?PyInstaller .exe file does nothingPyInstaller - Program returns -1 in another computerPattern module issue when using Pyinstaller to build an executableWhat are the necessary modules to run Python? (For PyInstaller)
All ASCII characters with a given bit count
What is the best way to deal with NPC-NPC combat?
How to pronounce 'c++' in Spanish
Is there really no use for MD5 anymore?
std::unique_ptr of base class holding reference of derived class does not show warning in gcc compiler while naked pointer shows it. Why?
A strange hotel
Restricting the options of a lookup field, based on the value of another lookup field?
How to not starve gigantic beasts
Is there any pythonic way to find average of specific tuple elements in array?
Does the damage from the Absorb Elements spell apply to your next attack, or to your first attack on your next turn?
Complex numbers z=-3-4i polar form
Magical attacks and overcoming damage resistance
Why do games have consumables?
Older movie/show about humans on derelict alien warship which refuels by passing through a star
"The cow" OR "a cow" OR "cows" in this context
Double-nominative constructions and “von”
Do I need to watch Ant-Man and the Wasp and Captain Marvel before watching Avengers: Endgame?
How do I produce this symbol: Ϟ in pdfLaTeX?
How can I practically buy stocks?
Is it acceptable to use working hours to read general interest books?
Find the identical rows in a matrix
How exactly does Hawking radiation decrease the mass of black holes?
Why must Chinese maps be obfuscated?
I preordered a game on my Xbox while on the home screen of my friend's account. Which of us owns the game?
Speeding up an .exe created with Pyinstaller
How can I safely create a nested directory in Python?How can you speed up Eclipse?Why is the Android emulator so slow? How can we speed up the Android emulator?Create a dictionary with list comprehension in PythonSpeed comparison with Project Euler: C vs Python vs Erlang vs HaskellWay to create multiline comments in Python?PyInstaller .exe file does nothingPyInstaller - Program returns -1 in another computerPattern module issue when using Pyinstaller to build an executableWhat are the necessary modules to run Python? (For PyInstaller)
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I've converted my program (written in Python 3.6.1, converted using Python 3.5.3) from a .py to an .exe using Pyinstaller. However, it is incredibly slow at loading (it takes roughly 16 seconds, compared to the <1 second when running in IDLE), even after I optimised what I though the problem was (importing tons of modules, so I changed the code to only import the parts of the modules that are necessary). That sped it up a lot when running it in IDLE, but when I created an .exe out of it it was exactly the same (and I did check that I was using the right .py file). I seems like Pyinstaller just packages all modules that you have installed on your system into the .exe, instead of only the small parts of the modules that are actually being used (when using --onefile
). How can I make sure that Pyinstaller only installs the necessary parts of the modules or otherwise speed it up, while still using --onefile
and packaging it into a single .exe?
Full code:
from os import path, remove
from time import sleep
from sys import exit
from getpass import getuser
from mmap import mmap, ACCESS_READ
my_file = "Text To Speech.mp3"
username = getuser()
no_choices = ["no", "nah", "nay", "course not", "don't", "dont", "not"]
yes_choices = ["yes", "yeah", "course", "ye", "yea", "yh", "do"]
def check_and_remove_file():
active = mixer.get_init()
if active != None:
mixer.music.stop()
mixer.quit()
quit()
if path.isfile(my_file):
remove(my_file)
def get_pause_duration(audio_length, maximum_duration=15):
default_pause, correction = divmod(audio_length, 12)
return min(default_pause + bool(correction), maximum_duration)
def exiting():
check_and_remove_file()
print("nGoodbye!")
exit()
def input_for_tts(message):
try:
tts = gTTS(text = input(message))
tts.save('Text To Speech.mp3')
with open(my_file) as f:
m = mmap(f.fileno(), 0, access=ACCESS_READ)
audio = MP3(my_file)
audio_length = audio.info.length
try:
mixer.init()
except error:
print("nSorry, no audio device was detected. The code cannot complete.")
m.close()
exiting()
mixer.music.load(m)
mixer.music.play()
sleep(audio_length + get_pause_duration(audio_length))
m.close()
check_and_remove_file()
except KeyboardInterrupt:
exiting()
from pygame import mixer, quit, error
from gtts import gTTS
from mutagen.mp3 import MP3
check_and_remove_file()
input_for_tts("Hello there " + username + ". This program isnused to output the user's input as speech.nPlease input something for the program to say: ")
while True:
try:
answer = input("nDo you want to repeat? ").strip().lower()
if answer in ["n", no_choices] or any(x in answer for x in no_choices):
exiting()
elif answer in ["y", yes_choices] or any(x in answer for x in yes_choices):
input_for_tts("nPlease input something for the program to say: ")
else:
print("nSorry, I didn't understand that. Please try again with yes or no.")
except KeyboardInterrupt:
exiting()
python performance python-3.x exe pyinstaller
add a comment |
I've converted my program (written in Python 3.6.1, converted using Python 3.5.3) from a .py to an .exe using Pyinstaller. However, it is incredibly slow at loading (it takes roughly 16 seconds, compared to the <1 second when running in IDLE), even after I optimised what I though the problem was (importing tons of modules, so I changed the code to only import the parts of the modules that are necessary). That sped it up a lot when running it in IDLE, but when I created an .exe out of it it was exactly the same (and I did check that I was using the right .py file). I seems like Pyinstaller just packages all modules that you have installed on your system into the .exe, instead of only the small parts of the modules that are actually being used (when using --onefile
). How can I make sure that Pyinstaller only installs the necessary parts of the modules or otherwise speed it up, while still using --onefile
and packaging it into a single .exe?
Full code:
from os import path, remove
from time import sleep
from sys import exit
from getpass import getuser
from mmap import mmap, ACCESS_READ
my_file = "Text To Speech.mp3"
username = getuser()
no_choices = ["no", "nah", "nay", "course not", "don't", "dont", "not"]
yes_choices = ["yes", "yeah", "course", "ye", "yea", "yh", "do"]
def check_and_remove_file():
active = mixer.get_init()
if active != None:
mixer.music.stop()
mixer.quit()
quit()
if path.isfile(my_file):
remove(my_file)
def get_pause_duration(audio_length, maximum_duration=15):
default_pause, correction = divmod(audio_length, 12)
return min(default_pause + bool(correction), maximum_duration)
def exiting():
check_and_remove_file()
print("nGoodbye!")
exit()
def input_for_tts(message):
try:
tts = gTTS(text = input(message))
tts.save('Text To Speech.mp3')
with open(my_file) as f:
m = mmap(f.fileno(), 0, access=ACCESS_READ)
audio = MP3(my_file)
audio_length = audio.info.length
try:
mixer.init()
except error:
print("nSorry, no audio device was detected. The code cannot complete.")
m.close()
exiting()
mixer.music.load(m)
mixer.music.play()
sleep(audio_length + get_pause_duration(audio_length))
m.close()
check_and_remove_file()
except KeyboardInterrupt:
exiting()
from pygame import mixer, quit, error
from gtts import gTTS
from mutagen.mp3 import MP3
check_and_remove_file()
input_for_tts("Hello there " + username + ". This program isnused to output the user's input as speech.nPlease input something for the program to say: ")
while True:
try:
answer = input("nDo you want to repeat? ").strip().lower()
if answer in ["n", no_choices] or any(x in answer for x in no_choices):
exiting()
elif answer in ["y", yes_choices] or any(x in answer for x in yes_choices):
input_for_tts("nPlease input something for the program to say: ")
else:
print("nSorry, I didn't understand that. Please try again with yes or no.")
except KeyboardInterrupt:
exiting()
python performance python-3.x exe pyinstaller
add a comment |
I've converted my program (written in Python 3.6.1, converted using Python 3.5.3) from a .py to an .exe using Pyinstaller. However, it is incredibly slow at loading (it takes roughly 16 seconds, compared to the <1 second when running in IDLE), even after I optimised what I though the problem was (importing tons of modules, so I changed the code to only import the parts of the modules that are necessary). That sped it up a lot when running it in IDLE, but when I created an .exe out of it it was exactly the same (and I did check that I was using the right .py file). I seems like Pyinstaller just packages all modules that you have installed on your system into the .exe, instead of only the small parts of the modules that are actually being used (when using --onefile
). How can I make sure that Pyinstaller only installs the necessary parts of the modules or otherwise speed it up, while still using --onefile
and packaging it into a single .exe?
Full code:
from os import path, remove
from time import sleep
from sys import exit
from getpass import getuser
from mmap import mmap, ACCESS_READ
my_file = "Text To Speech.mp3"
username = getuser()
no_choices = ["no", "nah", "nay", "course not", "don't", "dont", "not"]
yes_choices = ["yes", "yeah", "course", "ye", "yea", "yh", "do"]
def check_and_remove_file():
active = mixer.get_init()
if active != None:
mixer.music.stop()
mixer.quit()
quit()
if path.isfile(my_file):
remove(my_file)
def get_pause_duration(audio_length, maximum_duration=15):
default_pause, correction = divmod(audio_length, 12)
return min(default_pause + bool(correction), maximum_duration)
def exiting():
check_and_remove_file()
print("nGoodbye!")
exit()
def input_for_tts(message):
try:
tts = gTTS(text = input(message))
tts.save('Text To Speech.mp3')
with open(my_file) as f:
m = mmap(f.fileno(), 0, access=ACCESS_READ)
audio = MP3(my_file)
audio_length = audio.info.length
try:
mixer.init()
except error:
print("nSorry, no audio device was detected. The code cannot complete.")
m.close()
exiting()
mixer.music.load(m)
mixer.music.play()
sleep(audio_length + get_pause_duration(audio_length))
m.close()
check_and_remove_file()
except KeyboardInterrupt:
exiting()
from pygame import mixer, quit, error
from gtts import gTTS
from mutagen.mp3 import MP3
check_and_remove_file()
input_for_tts("Hello there " + username + ". This program isnused to output the user's input as speech.nPlease input something for the program to say: ")
while True:
try:
answer = input("nDo you want to repeat? ").strip().lower()
if answer in ["n", no_choices] or any(x in answer for x in no_choices):
exiting()
elif answer in ["y", yes_choices] or any(x in answer for x in yes_choices):
input_for_tts("nPlease input something for the program to say: ")
else:
print("nSorry, I didn't understand that. Please try again with yes or no.")
except KeyboardInterrupt:
exiting()
python performance python-3.x exe pyinstaller
I've converted my program (written in Python 3.6.1, converted using Python 3.5.3) from a .py to an .exe using Pyinstaller. However, it is incredibly slow at loading (it takes roughly 16 seconds, compared to the <1 second when running in IDLE), even after I optimised what I though the problem was (importing tons of modules, so I changed the code to only import the parts of the modules that are necessary). That sped it up a lot when running it in IDLE, but when I created an .exe out of it it was exactly the same (and I did check that I was using the right .py file). I seems like Pyinstaller just packages all modules that you have installed on your system into the .exe, instead of only the small parts of the modules that are actually being used (when using --onefile
). How can I make sure that Pyinstaller only installs the necessary parts of the modules or otherwise speed it up, while still using --onefile
and packaging it into a single .exe?
Full code:
from os import path, remove
from time import sleep
from sys import exit
from getpass import getuser
from mmap import mmap, ACCESS_READ
my_file = "Text To Speech.mp3"
username = getuser()
no_choices = ["no", "nah", "nay", "course not", "don't", "dont", "not"]
yes_choices = ["yes", "yeah", "course", "ye", "yea", "yh", "do"]
def check_and_remove_file():
active = mixer.get_init()
if active != None:
mixer.music.stop()
mixer.quit()
quit()
if path.isfile(my_file):
remove(my_file)
def get_pause_duration(audio_length, maximum_duration=15):
default_pause, correction = divmod(audio_length, 12)
return min(default_pause + bool(correction), maximum_duration)
def exiting():
check_and_remove_file()
print("nGoodbye!")
exit()
def input_for_tts(message):
try:
tts = gTTS(text = input(message))
tts.save('Text To Speech.mp3')
with open(my_file) as f:
m = mmap(f.fileno(), 0, access=ACCESS_READ)
audio = MP3(my_file)
audio_length = audio.info.length
try:
mixer.init()
except error:
print("nSorry, no audio device was detected. The code cannot complete.")
m.close()
exiting()
mixer.music.load(m)
mixer.music.play()
sleep(audio_length + get_pause_duration(audio_length))
m.close()
check_and_remove_file()
except KeyboardInterrupt:
exiting()
from pygame import mixer, quit, error
from gtts import gTTS
from mutagen.mp3 import MP3
check_and_remove_file()
input_for_tts("Hello there " + username + ". This program isnused to output the user's input as speech.nPlease input something for the program to say: ")
while True:
try:
answer = input("nDo you want to repeat? ").strip().lower()
if answer in ["n", no_choices] or any(x in answer for x in no_choices):
exiting()
elif answer in ["y", yes_choices] or any(x in answer for x in yes_choices):
input_for_tts("nPlease input something for the program to say: ")
else:
print("nSorry, I didn't understand that. Please try again with yes or no.")
except KeyboardInterrupt:
exiting()
python performance python-3.x exe pyinstaller
python performance python-3.x exe pyinstaller
edited May 29 '17 at 21:29
Gameskiller01
asked May 29 '17 at 21:05
Gameskiller01Gameskiller01
1341110
1341110
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
have a look at the documentation, i guess that explains, why it is slow: https://pyinstaller.readthedocs.io/en/stable/operating-mode.html#how-the-one-file-program-works
Short answer, a complete environment for your program needs to be extracted and written to a temporary folder.
Furthermore the one-file option is in contrast to what you expected: https://pyinstaller.readthedocs.io/en/stable/operating-mode.html#bundling-to-one-file
2
So there's no way to speed it up? It's much easier to distribute one file rather than a whole folder, especially to people who probably won't understand what they're looking at if they see all of the Python files in a folder. The .exe file is somewhat hard to find in the folder.
– Gameskiller01
May 29 '17 at 21:27
add a comment |
Try making a virtual environment and run your project from there. Then run pyinstaller from inside the virtual environment so you only package what you need. This will do most for you
Secondly onedir option is faster than onefile since it does not have to unpack all the files from your exe into a temp folder. Pyinstaller makes it easy to use qny other installer to move it to program files and make a shortcut in start or something.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f44250280%2fspeeding-up-an-exe-created-with-pyinstaller%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
have a look at the documentation, i guess that explains, why it is slow: https://pyinstaller.readthedocs.io/en/stable/operating-mode.html#how-the-one-file-program-works
Short answer, a complete environment for your program needs to be extracted and written to a temporary folder.
Furthermore the one-file option is in contrast to what you expected: https://pyinstaller.readthedocs.io/en/stable/operating-mode.html#bundling-to-one-file
2
So there's no way to speed it up? It's much easier to distribute one file rather than a whole folder, especially to people who probably won't understand what they're looking at if they see all of the Python files in a folder. The .exe file is somewhat hard to find in the folder.
– Gameskiller01
May 29 '17 at 21:27
add a comment |
have a look at the documentation, i guess that explains, why it is slow: https://pyinstaller.readthedocs.io/en/stable/operating-mode.html#how-the-one-file-program-works
Short answer, a complete environment for your program needs to be extracted and written to a temporary folder.
Furthermore the one-file option is in contrast to what you expected: https://pyinstaller.readthedocs.io/en/stable/operating-mode.html#bundling-to-one-file
2
So there's no way to speed it up? It's much easier to distribute one file rather than a whole folder, especially to people who probably won't understand what they're looking at if they see all of the Python files in a folder. The .exe file is somewhat hard to find in the folder.
– Gameskiller01
May 29 '17 at 21:27
add a comment |
have a look at the documentation, i guess that explains, why it is slow: https://pyinstaller.readthedocs.io/en/stable/operating-mode.html#how-the-one-file-program-works
Short answer, a complete environment for your program needs to be extracted and written to a temporary folder.
Furthermore the one-file option is in contrast to what you expected: https://pyinstaller.readthedocs.io/en/stable/operating-mode.html#bundling-to-one-file
have a look at the documentation, i guess that explains, why it is slow: https://pyinstaller.readthedocs.io/en/stable/operating-mode.html#how-the-one-file-program-works
Short answer, a complete environment for your program needs to be extracted and written to a temporary folder.
Furthermore the one-file option is in contrast to what you expected: https://pyinstaller.readthedocs.io/en/stable/operating-mode.html#bundling-to-one-file
answered May 29 '17 at 21:12
olischolisch
690210
690210
2
So there's no way to speed it up? It's much easier to distribute one file rather than a whole folder, especially to people who probably won't understand what they're looking at if they see all of the Python files in a folder. The .exe file is somewhat hard to find in the folder.
– Gameskiller01
May 29 '17 at 21:27
add a comment |
2
So there's no way to speed it up? It's much easier to distribute one file rather than a whole folder, especially to people who probably won't understand what they're looking at if they see all of the Python files in a folder. The .exe file is somewhat hard to find in the folder.
– Gameskiller01
May 29 '17 at 21:27
2
2
So there's no way to speed it up? It's much easier to distribute one file rather than a whole folder, especially to people who probably won't understand what they're looking at if they see all of the Python files in a folder. The .exe file is somewhat hard to find in the folder.
– Gameskiller01
May 29 '17 at 21:27
So there's no way to speed it up? It's much easier to distribute one file rather than a whole folder, especially to people who probably won't understand what they're looking at if they see all of the Python files in a folder. The .exe file is somewhat hard to find in the folder.
– Gameskiller01
May 29 '17 at 21:27
add a comment |
Try making a virtual environment and run your project from there. Then run pyinstaller from inside the virtual environment so you only package what you need. This will do most for you
Secondly onedir option is faster than onefile since it does not have to unpack all the files from your exe into a temp folder. Pyinstaller makes it easy to use qny other installer to move it to program files and make a shortcut in start or something.
add a comment |
Try making a virtual environment and run your project from there. Then run pyinstaller from inside the virtual environment so you only package what you need. This will do most for you
Secondly onedir option is faster than onefile since it does not have to unpack all the files from your exe into a temp folder. Pyinstaller makes it easy to use qny other installer to move it to program files and make a shortcut in start or something.
add a comment |
Try making a virtual environment and run your project from there. Then run pyinstaller from inside the virtual environment so you only package what you need. This will do most for you
Secondly onedir option is faster than onefile since it does not have to unpack all the files from your exe into a temp folder. Pyinstaller makes it easy to use qny other installer to move it to program files and make a shortcut in start or something.
Try making a virtual environment and run your project from there. Then run pyinstaller from inside the virtual environment so you only package what you need. This will do most for you
Secondly onedir option is faster than onefile since it does not have to unpack all the files from your exe into a temp folder. Pyinstaller makes it easy to use qny other installer to move it to program files and make a shortcut in start or something.
answered Mar 22 at 16:33
miThommiThom
7018
7018
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f44250280%2fspeeding-up-an-exe-created-with-pyinstaller%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown