Python Forum

Full Version: How To Set Up And Execute A Python File
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi all,

I've been slowly trying different things with Python whenever I get time and last year I created a couple of python files in Pycharm on my windows 10 machine. I found out a month or so later that I could just double click any Python file and the code would execute without me having to open Pycharm. I've been doing that for months.

Last week I needed to reinstall Windows 10 and since then I've reinstalled Pycharm and also installed Python (also ensured the "Ádd Python to PATH" was selected).

But if I click on any python file to execute it, I get a black screen appear and disappear within a second (I cannot read what it says) and nothing seems to happen.

I don't know what other information you may require to diagnose (please let me know if there is any), but can anyone please tell me how I can execute any python files like I used to without having to open Pycharm?

Thank you.

  1. from menu choose file --> Open
  2. select directory containing python code
  3. Click OK.
  4. follow any other requests.

Not sure, but once you open the file once, I'd expect that you can use the old method, there's probably (maybe) a file index that pycharm keeps.
(May-31-2022, 01:28 AM)Larz60+ Wrote: [ -> ]
  1. from menu choose file --> Open
  2. select directory containing python code
  3. Click OK.
  4. follow any other requests.

Not sure, but once you open the file once, I'd expect that you can use the old method, there's probably (maybe) a file index that pycharm keeps.

Thanks Larz60+ for such a quick reply and for your help.

I tried following exactly what you said. Unfortunately nothing seems to happen still.

Last year I originally used to keep Pycharm open all the time and run the code. One day I just randomly tried to fire up just the file by double clicking it in windows explorer without Pycharm opened, just to see what happens and it worked! So maybe I'll just put it down to some magic for the time and just have to keep Pycharm opened moving forward. Smile
I seem to have got it working now.

After trying what Larz60+ said, in Python, I right clicked on the code I had opened and selected "Run Code in Python Console". When I did, I noticed that it was telling me that none of the packages I required for the code were installed- although I had them installed for this code file on Pycharm. So the code was falling over and hence not working outside Pycharm.

I went and installed all the required packages for my code in the directory of the file I was trying to use and ran it again in "Run Code in Python Console" inside Pycharm to check for any other errors. Nothing came up so the code worked there.

Now when I double click the .py file in windows explorer, it fires up Python and runs it successfully without needing to open Pycharm.

Thanks again Larz60+. I have spend hours outside Pycharm fiddling without success to get this to work and only after you directed me back inside Pycharm, I tried other things and got lucky.
from command line, use pip3 install packagename