-3

I create an exe file in PyCharm. But the exe file always disappeared very soon after I clicked it. The program is an infinite cycle. The exe file shouldn't disappear and should appear on my screen all the time. The program is shown below. I think the main reason is that I imported the extension library 'openpyxl' in the program. I intentionally used an infinite loop in the code to keep the exe file running all the time. How can I make the exe file run normally? You can paste the code into PyCharm and create an exe file, then you can test if the exe file can run normally. Thank you.

my code:

import openpyxl
import os


excel_path = os.getcwd() + r"//claim.xlsx"

data = openpyxl.load_workbook(excel_path)
print('success')


testdata2 = 1
while True:
    print(testdata2)
    testdata1=testdata2+1

command used to create the .exe:

PS E:\Code\Python\Practice\TestInstallPackage> pyinstaller --onefile main.py
  • 2
    Screenshots and links don't count towards [mre] requirements for the reasons given in [Why should I not upload images of code/data/errors?](https://meta.stackoverflow.com/a/285557/14122); make sure there's enough information to let someone understand and test answers to your question included in _the text of the question itself_. If you used screenshots because you were having trouble making copied-and-pasted text look right, see [How do I format my code blocks?](https://meta.stackoverflow.com/questions/251361/how-do-i-format-my-code-blocks) – Charles Duffy Aug 09 '23 at 02:25
  • My code is as follows: import openpyxl import os excel_path = os.getcwd() + r"//claim.xlsx" data=openpyxl.load_workbook(excel_path) print('success') testdata2=1 while True: print(testdata2) testdata2=testdata2+1 I used the following statement in PyCharm to create exe file: pyinstaller --onefile main.py The exe file can't run normally. How can I solve this problem? – Henry Demking Aug 09 '23 at 02:52
  • The fact you are trying to create an executable inside a PyCharm session is not relevant. The fact you are using the `pyinstaller` program to do so is relevant. You should also not be using screenshots for information that is pure text. That information should be copy/pasted into your question. I predict you are not going to get a useful answer. – Kurtis Rader Aug 09 '23 at 03:50
  • 1
    [Edit] the question to add a [MRE] there rather than pasting code into comments. – Charles Duffy Aug 09 '23 at 04:10
  • You have two `while true` loops in your code (one commented out bu same code). What would end this loop? There is no conditional check to break out of the loop so it will always be `True`. This sort of thing generally causes an infinite loop – moken Aug 09 '23 at 04:52
  • I edited my question. Please reopen my question. Thank you. – Henry Demking Aug 09 '23 at 10:19
  • 1
    @HenryDemking still not very clear what you are trying to achieve or what kind of problem you have. Also: As already mentioned by @KurtisRader, this has nothing to do with PyCharm so don't re-add the tag for it. From what i saw when i tried decrypting what you want to achieve, [this answer](https://stackoverflow.com/a/54645519/13891412) seems to solve the problem (assuming the `.xlsx` file path would be correct and existing and the logic is correct too) and therefore makes this a duplicate. If there are any other issues with this, please think about opening a follow up question. – Clasherkasten Aug 09 '23 at 11:36

0 Answers0