python script does not run from commandline

Anonymous
2020-02-11T00:17:15+00:00

hello,

I'm having problems suddenly running .py scripts from the command line. (CMD) 

Before, *.py was associated with python.exe  (The association was created during python installation, associating python scripts (.py) with the proper executable.

With the proper association of the .py file to python.exe , the location of the python.exe in the %PATH% variable - and the python extension in the %PATHEXT% , just typing '.\myscript.py' would launch the script in using the correct python.exe (using the CMD line) 

However, for some reason this suddenly changed last week. Now, typing '.\myscript.py' does nothing - simply shows me the next prompt in the CMD window.

typing 'python myscript.py'  still works, but since there are a load of batch files lingering around running the .py scripts without the explicit 'python' prefix - I have no idea what changed and i'd like to find out what's going on and fix this. 

I browsed various forums - mentioning assoc and ftype, but these do not seem to do the trick

(in fact, on my tablet, typing .\myscript.py perfectly executes, and assoc/ftype seem to have nothing set for python scripts in the CMD window)

On the pc in question: 

assoc .py returns 'Python.File' , ftype Python.File shows the path/python.exe to my python executable - yet when typing myscript.py in the CMD line, it does nothing. 

I also tried associating the .py extension using the 'Run with' again, (was still showing 'python') but this too changed nothing.

I also checked the registry, to see what windows might be doing with .py extension, but although there are some references to the .py extension, some of which referring to the python.exe I like to use,  it's hard to see what's going on there (not sure which registry items are or used for what or even if they are used in win10.)

I 'repaired' my python install - then completely reinstalled python (adding registry entries) but nothing changed. 

when typing '.\myscript.py' on the command line - nothing happens, just the next prompt. 

when double clicking the python script  - it does seem to be associated with the proper python version, it does start using the right python.exe

My question(s)

  • if possible, how do I see (using the cmd line) what is windows is actually doing (trying to do)  when I type 'myscript.py' (can I start CMD using some debug/verbose options?) 
  • How/where in windows do i control how a .py script runs in the commandline? - apart from the 'run with' is there any way to tell windows how to run my python script, when I type myscript.py on the command line? 
  • are there additional options for the powershell to deal with this? 
  • is there a way, again from windows, to add details to the 'run with' , rather then just starting the .py using a python from the list, to tell it to use certain arguments? 
  • When using 'run with' , and seeing a python logo - is there a way to tell the exact path/execution line associated with that logo? 

(if not, i really think it should be possible to see this when that list pops up using some advanced settings or something ) 

any help and insights would be much appreciated. 

cheers

GJ 

[EDIT]  after further investigation - it has nothing to do with python but, as it seems, rather the way the CMD shell deals with commands. 

Creating a simple file 'test.abc' and creating a file association to this extension, right clicking it and select 'open with' , say notepad.exe.

on the cmd line:

c:\test.abc   , does nothing , simply showing the next commandline, no error, just the next prompt. 

but

c:\cmd /c test.abc   , launches notepad showing the file.

On a different machine, both have the same outcome, opening notepad with the file. 

what's going on with the shell on this machine? I suspect some policy/registry setting preventing it to properly execute, but i dont know why 'cmd /c  ...' would work 

[EDIT] I've observed this behaviour only on 1 specific windows version - all winver 1909 OSBuild 18363.720 , all machines that worked fine are (slightly) older versions/builds.

Windows for home | Windows 10 | Settings

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

6 answers

Sort by: Most helpful
  1. Anonymous
    2020-05-01T19:22:39+00:00

    I keep paying attention to this subject, to see if there is a solution.

    As I mentioned last time, .py doesn't work again, I really don't know what happened on my computer, after read the last reply, I did:

    test.py

    :test.py

    :/test.py

    Same, no any actual response except a simple return.

    Was this answer helpful?

    50+ people found this answer helpful.
    0 comments No comments
  2. Anonymous
    2020-03-14T20:30:37+00:00

    I have exact same issue, which started a few days ago, I can recall it was from a windows update.

    I feel the problem is the system doesn't really search for the associated run file which is "c:\Python27\python.exe" for me. On an old windows7 machine, I did a test "associate .py to python.exe, and then rename python.exe to some else, and type *.py at command line", a pop-up window asking right executable file shows up; but on windows 10 command prompt, it simply do nothing.

    I also tried to run python script in powershell, but it says "Program 'test.py' failed to run: No process is associated with this object"

    BTW, on window 10 command line, if run "ftype Python.file", it shows (Python.file="C:\Python27\python.exe" "%1" %*)

    Was this answer helpful?

    20+ people found this answer helpful.
    0 comments No comments
  3. Anonymous
    2020-03-17T22:02:05+00:00

    did windows by any chance perform an update? what is your current windows version/build ?

    Was this answer helpful?

    5 people found this answer helpful.
    0 comments No comments
  4. Anonymous
    2020-05-01T17:10:12+00:00

    I had the same exact problem. Then found this thread. It wad doing the same thing. It wouldnt do anything with the .py file in the command prompt. 

    All I did was took away the . And just put:

    >: /test.py

    And it ran!

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments
  5. Anonymous
    2020-03-17T12:56:59+00:00

    The problem simply disappeared today, I login my computer (in sleep mode), and opened a command line, and typed python script, and it works again, just like miracle. I totally not know what made it works again, anyway, good news for me, but still hope someone can help with the issue, it recover in miracle, and there is chance it happens again mysteriously.

    Was this answer helpful?

    0 comments No comments