Using the gedit editor I have made a file ex1.py. My system is Linux Ubuntu 16.04 LTS. I have tried many solutions including giving the full path like python /home/xyzpc/mystuff/learnpython/ex1.py. For understanding purpose mystuff and learnpython are the two folders I have created and inside learnpython I have kept the ex1.py file. BUT again it is showing python: can't open file 'ex1.py': [Errno 2] No such file or directory. Please help. I know it is a duplicate one but unable to fix the issue

  • What does the command ls -l $HOME/mystuff/learnpython/ say? – Timo Aug 1 '18 at 7:38
  • My input as per your instruction was xyzpc:$ ls -l $home/mystuff/learnpython/. When I entered this it gave me ls: cannot access '/mystuff/learnpython/': No such file or directory. No way out, please help – Shirshendu De Aug 1 '18 at 8:08
  • @ShirshenduDe Linux is case sensitive - $home is not the same thing as $HOME – steeldriver Aug 1 '18 at 9:04
  • Thanks @steeldriver, one more addition to my knowledge. This input as directed gave output as - total 12 (first line) -rwxrwxr- x 1 username username 216 Aug 1 14:20 ex1 (second line) – Shirshendu De Aug 1 '18 at 9:26
  • So as you can see, you didn't make a file ex1.py - you made a file ex1 – steeldriver Aug 1 '18 at 9:38

Open the terminal and type python (python followed by a space), then drag the ex1.py file into the terminal and press Enter. If the command executes successfully you now know two things.

  1. ex1.py executed successfully.

  2. When you drag a file from the file manager into the terminal it automatically prints the complete path to that file. In order to access ex1.py using cd change directories to the directory that contains ex1.py which can be identified from the path to ex1.py.

  • Thanks @karel, it worked greatly. Thanks again as this added to my knowledge that as to what happens when we drag a file from a file folder to a terminal. – Shirshendu De Aug 1 '18 at 8:21
  • For future users of this thread. When I dragged the file into the terminal automatically it took the path and executed what I had written in the gedit text editor and the same which I saved with the extension .py. When I pressed enter it gave the results and the the first line appeared as python 'home/username/mystuff/learnpython/ex1'. Now again to try in a different way I tried using the same line without the quotation marks at the start and at the end. Again it worked. Now the mistake which I was doing was to put .py after ex1. Write only ex1. This solves the issue – Shirshendu De Aug 1 '18 at 8:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.