Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I want to know how to run a script (.py) I've written
At the top of the script I have entered
#!/usr/bin/python
In a shell I have
cd'd to the directory the script is sitting in.
Typed in "python" to invoke the interpretor
then
typed "python linux_python_test.py"
tried "./ linux_python_test.py"
and "linux_python.py"
HAve also tried removing the .py extention and tried those three again.
All the while the same error message crops up....
File "<stdin>", line 1
python linux_python_test.py
^
#!<path> on the first line tells the shell to use a specific interpreter when executing the script. The file must then have the execute bit set: "chmod 775 script.py"
Not specifying it requires you to call the interpreter with the file as an argument (i.e. python script.py)
Try removing the #!... on the first line and simply executing the script as an option to the interpreter: "python script.py"
If you really want to keep the #!, then make sure the path you're specifying is the true path to the interpreter: "which python" will help you with that.
by the way I changed directory before going into the Python Interpreter.
If you want to execute a python script as an executable file you need to be at the normal Linux command line (bash), not in the python interpreter.
(Of course you could do it from the interpreter as well but you'd need to write code).
So simply go back to your normal Linux command line, cd into the directory where the script is and type 'python scriptname' where script name is the name of the file.
If you want to execute a python script as an executable file you need to be at the normal Linux command line (bash), not in the python interpreter.
(Of course you could do it from the interpreter as well but you'd need to write code).
So simply go back to your normal Linux command line, cd into the directory where the script is and type 'python scriptname' where script name is the name of the file.
Thank you for all the replies.
This is what I was doing wrong. I was trying to invoke the script though the Python Interpreter
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.