[GH-ISSUE #386] python function 'exit' raise exception #314

Closed
opened 2026-02-26 12:21:11 +03:00 by kerem · 4 comments
Owner

Originally created by @boyapavel on GitHub (Apr 11, 2023).
Original GitHub issue: https://github.com/brentvollebregt/auto-py-to-exe/issues/386

Traceback (most recent call last):
File "gw_stat_gen.py", line 255, in
File "gw_stat_gen.py", line 11, in get_list_files
NameError: name 'exit' is not defined
[20944] Failed to execute script 'gw_stat_gen' due to unhandled exception!

line 11 looks like : exit('can not open your directory '+path+' .exit')

Originally created by @boyapavel on GitHub (Apr 11, 2023). Original GitHub issue: https://github.com/brentvollebregt/auto-py-to-exe/issues/386 Traceback (most recent call last): File "gw_stat_gen.py", line 255, in <module> File "gw_stat_gen.py", line 11, in get_list_files NameError: name 'exit' is not defined [20944] Failed to execute script 'gw_stat_gen' due to unhandled exception! line 11 looks like : exit('can not open your directory '+path+' .exit')
kerem closed this issue 2026-02-26 12:21:11 +03:00
Author
Owner

@github-actions[bot] commented on GitHub (Apr 11, 2023):

👋 Hi, just a reminder that if you haven't read the help post yet, give it a read to see if your issue is covered in it and make sure to follow the debugging section.

Also please note, as stated in the README, if your issue is only associated with your application and not auto-py-to-exe itself, please do not create an issue in this repository - instead, comment on the help post, video or create a new discussion.

<!-- gh-comment-id:1502931826 --> @github-actions[bot] commented on GitHub (Apr 11, 2023): 👋 Hi, just a reminder that if you haven't read [the help post](https://nitratine.net/blog/post/issues-when-using-auto-py-to-exe/) yet, give it a read to see if your issue is covered in it and make sure to follow [the debugging section](https://nitratine.net/blog/post/issues-when-using-auto-py-to-exe/#debugging). Also please note, as stated in the README, if your issue is only associated with your application and not auto-py-to-exe itself, please do not create an issue in this repository - instead, comment on the help [post](https://nitratine.net/blog/post/issues-when-using-auto-py-to-exe/), [video](https://youtu.be/OZSZHmWSOeM) or create a [new discussion](https://github.com/brentvollebregt/auto-py-to-exe/discussions).
Author
Owner

@boyapavel commented on GitHub (Apr 11, 2023):

i change fuction exit() to sys.exit() - it`s a good workaround for me.
but why exit() function raise exception like "NameError: name 'exit' is not defined" ?

<!-- gh-comment-id:1503194560 --> @boyapavel commented on GitHub (Apr 11, 2023): i change fuction exit() to sys.exit() - it`s a good workaround for me. but why exit() function raise exception like "NameError: name 'exit' is not defined" ?
Author
Owner

@boyapavel commented on GitHub (Apr 11, 2023):

for example, i wrote simple python script with exit() function.
script:
test = ''
while test != '2':
test = input('please give me 2 or anything else. 2 - is exit; your choise: ')
exit('bye, bye')
debug attached here.
test_debug_all.txt

<!-- gh-comment-id:1503218294 --> @boyapavel commented on GitHub (Apr 11, 2023): for example, i wrote simple python script with exit() function. script: `test = ''` `while test != '2':` ` test = input('please give me 2 or anything else. 2 - is exit; your choise: ')` `exit('bye, bye')` debug attached here. [test_debug_all.txt](https://github.com/brentvollebregt/auto-py-to-exe/files/11200182/test_debug_all.txt)
Author
Owner

@brentvollebregt commented on GitHub (Apr 12, 2023):

I have added a section to the debugging help for this: https://nitratine.net/blog/post/issues-when-using-auto-py-to-exe/#nameerror-name-exit-is-not-defined.

Here is a snippet from the additions:

Typically when developing in IDLE, sys is automatically imported. This means calls like exit() will work in IDLE without having to import sys explicitly. However, when packaging, sys is not automatically imported so you will have to import it yourself. This is a simple fix and can be done by adding import sys to the top of your script.

<!-- gh-comment-id:1504697782 --> @brentvollebregt commented on GitHub (Apr 12, 2023): I have added a section to the debugging help for this: https://nitratine.net/blog/post/issues-when-using-auto-py-to-exe/#nameerror-name-exit-is-not-defined. Here is a snippet from the additions: > Typically when developing in IDLE, `sys` is automatically imported. This means calls like `exit()` will work in IDLE without having to import `sys` explicitly. However, when packaging, sys is not automatically imported so you will have to import it yourself. This is a simple fix and can be done by adding `import sys` to the top of your script.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/auto-py-to-exe#314
No description provided.