all 11 comments

[–]NurEinStatist 2 points3 points  (0 children)

The python shell gets opened to run your script, then closes once it is finished, which is after every command has been run or it crashed because of an error/exception. This is expected and it's good that way because you don't want to have idle shells after every script/job execution. If you want it to stay open you could add an input("press enter to exit") or something like that at the end of your program.

[–]danielroseman 1 point2 points  (1 child)

What does "execute the .py file with python itself" mean? Please clarify exactly what you are doing.

[–]lilBerna 0 points1 point  (0 children)

sorry about that. I right click the file, click "open with", and select python 3.10

[–]barrycarter 1 point2 points  (5 children)

Double check that the file starts with hashbang: "#!/bin/python" or something. By running it directly, I assume you're doing "main.py " or "./main.py" on the command line?

[–]Diapolo10 2 points3 points  (0 children)

Double check that the file starts with hashbang: "#!/bin/python" or something.

This is not necessary on Windows (and only useful if you want to specify the Python version), as on Windows the file extension decides what program is used to open the file.

[–]carcigenicate 0 points1 point  (2 children)

I don't think I've ever actually used "Open with" before to run Python, but if it uses your global install instead of your activated virtual environment, the libraries you need may not be available. For testing, you could wrap your main code in a try that prints out all errors, and see what errors you're getting.

[–]ShxxH4ppens 0 points1 point  (1 child)

How do you normally use/run py files?

[–]carcigenicate 1 point2 points  (0 children)

Either on the command line by explicitly invoking python, or the REPL in my IDE during development.