Python Forum

Full Version: "usr" directory not present and needed for cmd commands?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
hi guys,

I'm getting started with python and I need a push here. Everything I read online about executing cmds via the command prompt whether they be literal commands or pointers to .py scripts, they all have indicated that the .py scripts should be located in the "usr\...." directory. However, when I installed mine, python 3.7.1 believe, no dir like that exists. can you guys tell me if I run the following command:
python helloworld.py
what full path that command is actually trying to point at and run? In the attached image, you can see that the python installer did not install a dir named "usr":

python dir contents

[Image: open?id=1YHe8sMr-6LNHO91wAoPIUqBuuILvyDb9]

thanks!

Adam
EDIT: It depends if you have checked during installation that Python should be in Path, then you just could use python from command line.
If it's not in your PATH, then you should use the installed tool py.
This will find the interpreter for you. There is no need to change the PATH. In some situations it's really bad to put Python into the PATH.

With PATH I mean the environment variable, which holds different paths, where other programs use this information to execute something. So if you type only a name in your terminal, the Windows seeks all .exe and .com files in the PATHs and on the first hit, it executes it.

Further information about py.exe: https://docs.python.org/3/using/windows....or-windows

(Dec-19-2019, 10:47 AM)ajetrumpet Wrote: [ -> ]what full path that command is actually trying to point at and run? In the attached image, you can see that the python installer did not install a dir named "usr":

/usr is a Path on Linux-Systems and on Windows you won't find it.
Which interpreter is used, depends on the PATH variable. Since Python 3, the installer ships together with py.exe.
This tool is able to find the right interpreter.

The command python helloworld.py takes the interpreter which occurs in PATH and executes the script helloworld.py in your current working directory. You can put your program where you want. There is no special path for it.

If you want to execute a program, which is not in current working directory, you have to change the directory or you address the script with an absolute Path (C:\somewhere\my_script.py).

If you're working with pip, use also the py tool.

py -3 -m pip install something
This will take an the existing latest Python3 installation and will execute __main__.py from pip.
Then you address the right interpreter. If you have more than one Python Version installed, you should use this tool together with pip in module mode. The -m switch executes the __main__.py of the module.
thank you dead eye! I have managed to run a simple "hello.py" script from the CMD and I will see how far I can go before I get stuck again. I'm reading through the documentation on docs.python.org thoroughly and I'm sure I will learn a lot there. I will start a new thread when I get stuck again. thanks again!

Adam