Run python script on terminal ubuntu

0 votes

I've just changed my OS and I'm now using ubuntu and I can't run any script on my terminal.

I made sure to have the #!/usr/bin/env python but when I go to the terminal and type, for example python test.py the terminal shows an error message like this

python: can't open file 'test.py': [Errno 2] No such file or directory

I must save the file in any specific folder to make it run on terminal?

Oct 31, 2018 in Python by findingbugs
• 3,260 points
4,903 views

1 answer to this question.

0 votes

Your shell in the terminal has a concept of "Current working directory", which is what directory (folder) it is currently "in".

Thus, if you type something like:

python test.py

test.py needs to be in the current working directory. In Linux, you can change the current working directory with cd.

answered Oct 31, 2018 by Priyaj
• 58,020 points

Related Questions In Python

0 votes
2 answers
0 votes
1 answer

How to run django unit-tests on production database in Python?

In case someone googles here searching for ...READ MORE

answered Nov 28, 2018 in Python by Nymeria
• 3,560 points
1,551 views
0 votes
1 answer

How can I run terminal commands in python?

You can use the subprocess or os module to do this. Using ...READ MORE

answered Feb 4, 2019 in Python by Omkar
• 69,220 points
1,243 views
0 votes
1 answer

How Do You Run A Python Script In Blender?

Blender is a free and open-source 3D ...READ MORE

answered Jul 30, 2019 in Python by Mohammad
• 3,230 points
8,680 views
0 votes
1 answer
0 votes
1 answer

How do I set variable if a specific package version is installed in CFEngine?

Here is what you can do.Just use packagesmatching to ...READ MORE

answered Jul 12, 2018 in Other DevOps Questions by Atul
• 10,240 points
1,180 views
0 votes
1 answer

How to enable python3 in vim?

You didn't tell us the platform you're ...READ MORE

answered Jan 21, 2019 in Python by SDeb
• 13,300 points
1,916 views
0 votes
1 answer

Install Python on Ubuntu

@Abha you are right about pre-installation of python, ...READ MORE

answered Mar 1, 2019 in Python by Pratibha
• 3,690 points
1,143 views
0 votes
1 answer

Is there a way to run Python on Android?

YES! here’s a barcode scanner written in six ...READ MORE

answered Sep 19, 2018 in Python by Priyaj
• 58,020 points
1,019 views
+1 vote
3 answers

How to run the Python program forever?

you can also do the old fashioned ...READ MORE

answered Jun 10, 2019 in Python by brianno
21,308 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP