Executing Python script from command line on Windows 7

I seem to have a problem executing a Python script from terminal Win+ R.

I followed these steps:

  • The shebang line is used before entering my script for all .py files. An example of what I did below for a script called Primefactorization.py

    .

    #! python3
    
          

  • I created a batch file in the same folder with the same name and enter the following code:

    @python.exe C:\Python Scripts\Primefactorization.py %*
    
          

  • I added path ( C:\Python Scripts

    ) to the variable PATH

    in the environment variables window.

  • When I try to invoke a script using the Run command in Windows 7, the shell opens and disappears immediately.

  • Building on a past answer to a similar issue on Stack Overflow, I also added the following code prompting the user for input before exiting. But it doesn't work.

    x = input('press enter to close')
    
          

Could you please let me know where the problem might be?

+3


source to share


1 answer


There is a gap in your path. Put it in double quotes. For example:



python.exe "C:\Python Scripts\Primefactorization.py"

      

+1


source







All Articles