Search code examples
pythonvariablessystemlauncher

Executing scripts without the Python 3.7 launcher and extenstion on Windows 10


I would like to execute script as

"foo"

instead of

"py foo.py"

I have already had the proper setup but I had to reinstall the python and now it doesn't work.

In PATH I added the Python3 root folder and Scripts subfolder.

In PATHEXT I added ".PY" and ".PYW".

I also associated the file group with .py and redirected the executable by

assoc .py=Python.File
ftype Python.File=C:\Python3\pythonw.exe "%1" %*

If I type "py foo.py" I get desired output.

After typing "foo" or "foo.py" I won't get any output or error.

After typing "py foo" I get (null): can't open file 'hello': [Errno 2] No such file or directory.

It looks like the system variables are not effected by new settings, I have tried to restart pc, it din't help.


Solution

  • This works for me:

       assoc .py=PythonScript 
       ftype PythonScript=py.exe %1 %*
       set PATHEXT=.py;%PATHEXT%
    

    py.exe is the Python launcher and is located in C:\windows\py.EXE by default