What i want to do is to start a terminal session with the python command line interpreter and and further run a python file using the interpreter the python file could located anywhere.

What i mean to say is I have a python file demo.py in /home/one/two/


so that when terminal opens i see the message something followed by the console prompt.


My approach:

gnome-terminal --python -i ~/home/one/two/demo.py

this gives me following result

python: can't open file '~/Desktop/pydemo/demo.py': [Errno 2] No such file or directory

However when i run the same command from terminal window(not opened in the same directory as the demo.py file ) it works properly.

Can someone please explain what is happening here and if possible suggest a way t0 achieve whatever i mentioned above.

1 Answer 1


You did not say HOW you start that command. If run from command line, gnome-terminal -- python -i ~/demo.py will work, because the shell will change ~ into your home before the arguments are passed to gnome-terminal. But here in your case, the error message states ~/... : not found : There was no shell to interpret the ~, so it was left as is, and effectively, there is no directory whose name is the sole character ~ in the directory the command happent to be started in.

Either explicitely use a shell to interpret the ~ :

gnome-terminal -- sh -c 'exec python -i ~/demo.py'

or do it yourself and proivde the full path name :

gnome-terminal -- python -i /home/me/demo.py

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.