Hello everyone,

I search for this answer, and yeah, it looks like many asked
this question before, but my answer was not on those posts.
now i would liek to double ask the same question again...
how can i invoke a python script from command pronpt?
this is the way i'am doing it:

C:\Python26\python.exe MyScript.py

Now, i understand that python need the whole path for the script
in order to process the python script, am i right? please some one
i some advices with this, thanks in advance.

Recommended Answers

All 8 Replies

There is many variations, I have usually python not in path, because I use both Python 2.7.2 and 3.2.2 installed. Actually I have also PyPy 1.8 also installed. So for more rigorous testing I usually use ConText editor, for which I have defined launching various versions of Python to function keys of .py file type.

From command line I use TAB key a lot to catch proper Python version by TAB completion, and then type my script name. That is I first CD to by scripts directory.

Additionallly I have one version defined associated with .py files and also .PY added to my PATHEXT environment variable, so I can call my_script.py as my_script also.

It might be time to use the editor environment that comes normally with your Python distribution. Since you are using Python26 try this batch file ...
C:\Python26\pythonw.exe -u C:\Python26\Lib\idlelib\idle.pyw

Otherwise you have to give the full file path in your commandline. That does get tiresome.

Hello guys, thanks for your help,
but this one worked for me:

cd c:\ enter
C:\>C:\Python26\python.exe C:\MyScript.py

and vegaseat whats up with those two "w" on each end?
i tried to fallow your suggestion, then i noticed the
two w on each end of the line ...Huh? what the heck?
doing it that way nothing was happening, then decide
to cut and type it in a diferent way and it did work.
Thank you

pyw file is py for which you do not want to bring up the terminal screen when launching.

Oh i see Tony, thats something good to know, thanks.
i did two tests, one on Ubuntu and on Windows, but the
idea was to be made on Windows only, so the .pyw is like
when you execute a batch silently right? oh okay, i see now.
Thank you guys

Hey Tony, let me ask you a question, i would like to write a pythong batch,
something like a batch in windows with something on it, this for example:

@ECHO OFF
TITLE C0ding
COLOR 17

I have my python script that i would like to run without going to Ubuntu
menu and open Terminal and do everything manually, how can i start this out?
Thanks Tony

link the script to one executable directory on your path, common practice is to have one directory called bin in your user directory.

You can put there one script without extension and start the script with shebang line, here is example of script from wxpython installation for launching the editra editor in Linux environment from my python27/Scripts directory:

#!/usr/bin/env python

from wx.tools.Editra.launcher import main
main()

Then you can create a launcher for the script on the desktop.

Thank you Tony, now let me explain what i have...
I have the Ubuntu CD which i've been using to run
in a laptop with Windows 7, then once in Ubuntu...
i drag and drop my python script to Ubunto desktop,
then i open terminal and start typing from there...
this is not something i do every day, but i was just
wondering how i can make my life easier with a batch.
now if this is my case, how can i accomplish the script?

This is how mine look like:
sudo python /home/ubuntu/Desktop/
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.