14 Replies - 1042 Views - Last Post: 03 November 2011 - 11:27 AM Rate Topic: -----

#1 cupidvogel  Icon User is offline

  • D.I.C Addict

Reputation: 31
  • View blog
  • Posts: 593
  • Joined: 25-November 10

Invoking Python scripts from command prompt

Posted 18 October 2011 - 11:13 AM

Hi, I find in all books and websites that in order to run a Python script from the command prompt, I have to run something like this

python example.py 1.3



where example.py script is provided with an argument of 1.3. However, it is not working for me in Windows 7 until I delete the python part, so that the command looks like:

example.py 1.3



I have already changed the path variable of Windows to include the Python directory. Why isn't the python word necessary for me, even though it's mentioned everywhere?

Is This A Good Question/Topic? 0
  • +

Replies To: Invoking Python scripts from command prompt

#2 ATC3  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 54
  • Joined: 04-October 11

Re: Invoking Python scripts from command prompt

Posted 18 October 2011 - 11:50 AM

I think your problem is that your are in a python shell. In the shell you do not have to put python.
Was This Post Helpful? 0
  • +
  • -

#3 cupidvogel  Icon User is offline

  • D.I.C Addict

Reputation: 31
  • View blog
  • Posts: 593
  • Joined: 25-November 10

Re: Invoking Python scripts from command prompt

Posted 18 October 2011 - 11:55 AM

Come on now, do you really think that I am in Python shell (IDLE) and I don't know! I am invoking the script from the command line. And even if I am in Idle, typing example.py 1.3 won't do anything but throw an error. I have to use import to use the script in Idle, plus the argv thing works for command line only, not from within Idle!
Was This Post Helpful? 1
  • +
  • -

#4 ATC3  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 54
  • Joined: 04-October 11

Re: Invoking Python scripts from command prompt

Posted 18 October 2011 - 12:05 PM

Sorry I am new. I really don't know what your problem is then.
Was This Post Helpful? 0
  • +
  • -

#5 cupidvogel  Icon User is offline

  • D.I.C Addict

Reputation: 31
  • View blog
  • Posts: 593
  • Joined: 25-November 10

Re: Invoking Python scripts from command prompt

Posted 18 October 2011 - 12:10 PM

No problem. Keep coding, and you won't be new any more! Best of luck. :online2long:
Was This Post Helpful? 0
  • +
  • -

#6 Motoma  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 452
  • View blog
  • Posts: 796
  • Joined: 08-June 10

Re: Invoking Python scripts from command prompt

Posted 18 October 2011 - 12:56 PM

You say only that it won't work. Do you get an error message? Post it.
Was This Post Helpful? 0
  • +
  • -

#7 cupidvogel  Icon User is offline

  • D.I.C Addict

Reputation: 31
  • View blog
  • Posts: 593
  • Joined: 25-November 10

Re: Invoking Python scripts from command prompt

Posted 18 October 2011 - 01:00 PM

I am posting the snapshot.

Attached image(s)

  • Attached Image

Was This Post Helpful? 0
  • +
  • -

#8 Motoma  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 452
  • View blog
  • Posts: 796
  • Joined: 08-June 10

Re: Invoking Python scripts from command prompt

Posted 18 October 2011 - 01:08 PM

I would venture a guess that your PATH or PYTHONPATH environment variable is not properly set to include the current directory. I can't really give more insight than that, this is more of a system setup issue than a python issue.

This post has been edited by Motoma: 18 October 2011 - 01:08 PM

Was This Post Helpful? 1
  • +
  • -

#9 cupidvogel  Icon User is offline

  • D.I.C Addict

Reputation: 31
  • View blog
  • Posts: 593
  • Joined: 25-November 10

Re: Invoking Python scripts from command prompt

Posted 18 October 2011 - 01:13 PM

Ok, I will enlighten you. My Python installation folder is C:\\Python27, as shown in the image (you surely know what is inside the different folders shown inside it), and the provided here is the present value of the system path variable.

C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files\WIDCOMM\Bluetooth Software\;C:\Program Files\WIDCOMM\Bluetooth Software\syswow64;;C:\Program Files\Dell\DW WLAN Card;c:\Program Files (x86)\Common Files\Roxio Shared\DLLShared\;c:\Program Files (x86)\Common Files\Roxio Shared\OEM\DLLShared\;c:\Program Files (x86)\Common Files\Roxio Shared\OEM\DLLShared\;c:\Program Files (x86)\Common Files\Roxio Shared\OEM\12.0\DLLShared\;c:\Program Files (x86)\Roxio\OEM\AudioCore\;C:\Program Files (x86)\Windows Live\Shared;C:\MySQL\bin;C:\Program Files\MySQL\MySQL Server 5.1\bin;C:\Python27

Attached image(s)

  • Attached Image

Was This Post Helpful? 0
  • +
  • -

#10 Motoma  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 452
  • View blog
  • Posts: 796
  • Joined: 08-June 10

Re: Invoking Python scripts from command prompt

Posted 18 October 2011 - 01:18 PM

Try adding ";." to both. If not, I'm out of ideas.
Was This Post Helpful? 0
  • +
  • -

#11 cupidvogel  Icon User is offline

  • D.I.C Addict

Reputation: 31
  • View blog
  • Posts: 593
  • Joined: 25-November 10

Re: Invoking Python scripts from command prompt

Posted 18 October 2011 - 01:20 PM

What do you mean by both?
Was This Post Helpful? 0
  • +
  • -

#12 Motoma  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 452
  • View blog
  • Posts: 796
  • Joined: 08-June 10

Re: Invoking Python scripts from command prompt

Posted 18 October 2011 - 01:21 PM

PATH and PYTHONPATH
Was This Post Helpful? 1
  • +
  • -

#13 cupidvogel  Icon User is offline

  • D.I.C Addict

Reputation: 31
  • View blog
  • Posts: 593
  • Joined: 25-November 10

Re: Invoking Python scripts from command prompt

Posted 18 October 2011 - 01:23 PM

Will do and let you know the result tomorrow. Now gotta go to sleep. It's past 2 A.M in India!
Was This Post Helpful? 0
  • +
  • -

#14 cupidvogel  Icon User is offline

  • D.I.C Addict

Reputation: 31
  • View blog
  • Posts: 593
  • Joined: 25-November 10

Re: Invoking Python scripts from command prompt

Posted 19 October 2011 - 09:14 PM

I did, and it didn't work. :helpsmilie:
Was This Post Helpful? 0
  • +
  • -

#15 poker158149  Icon User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 70
  • Joined: 29-June 11

Re: Invoking Python scripts from command prompt

Posted 03 November 2011 - 11:27 AM

I don't understand what your problem is with not having to type "python" in front of the script. That's just one less word for you to type and it still works.

Also, just for future reference, the Python Shell and the IDLE are not the same thing. The shell looks like a command prompt, so when ATC3 suggested you might have been in the shell, he was not talking about the IDLE.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1