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
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.
ex1.py executed successfully.
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
ls -l $HOME/mystuff/learnpython/
say? – Timo Aug 1 '18 at 7:38$home
is not the same thing as$HOME
– steeldriver Aug 1 '18 at 9:04ex1.py
- you made a fileex1
– steeldriver Aug 1 '18 at 9:38