Python Forum
"usr" directory not present and needed for cmd commands?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
"usr" directory not present and needed for cmd commands?
#1
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
Reply
#2
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.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply
#3
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Check if a value is present in each group Menthix 8 2,592 May-16-2022, 12:25 PM
Last Post: Menthix
  Anaconda pip install mpyc Error pip-script.py is not present Anldra12 2 7,725 Dec-13-2021, 06:59 PM
Last Post: Anldra12
  No Scripts File present after python installation ag2207 5 4,769 Jul-30-2020, 11:11 AM
Last Post: buran
  Python function executes twice when region loop is present bluethundr 2 2,595 Jan-07-2020, 03:01 PM
Last Post: bluethundr
  Deleting files not present in CSV spw2515 1 1,903 Sep-04-2019, 06:06 PM
Last Post: ichabod801
  Comparing the count of rows from the tables that are present in two different databas krt5 6 3,892 Feb-15-2019, 03:20 PM
Last Post: krt5
  check log filename with present date CyberDaemon 5 3,786 Aug-22-2018, 08:42 PM
Last Post: CyberDaemon
  How to find the list of dependencies not present in the remote artifactory repository csplrj 6 4,637 Mar-30-2018, 03:43 PM
Last Post: csplrj
  Need Help: Sort of Binary numbers based on 1's present abinashj 5 5,044 Jul-25-2017, 12:23 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020