Back

Explore Courses Blog Tutorials Interview Questions
+5 votes
1 view
in Python by (47.6k points)

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 the terminal?

2 Answers

+8 votes
by (106k points)

To run the python script in the terminal there is a concept of "Current working directory", which is what directory (folder) it is currently "in".

You can use the following Python command:

python test.py

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

0 votes
by (20.3k points)

You can try executing your file by using this:

python /Users/luca/Documents/python/gameover.py

You can also run the file by moving to the path of the file you want to run and type:

python gameover.py

Related questions

0 votes
1 answer
asked Jan 3, 2021 in SQL by Appu (6.1k points)
0 votes
1 answer
0 votes
1 answer
asked Nov 21, 2020 in GCP by chandra (29.3k points)
0 votes
1 answer

Browse Categories

...