If I execute any system commend in ipython2/3 on my Ubuntu 16.04 machine, I get permission denied error as follows:

In [1]: ls
PermissionError                           Traceback (most recent call last)
<ipython-input-1-5b21b94dda0e> in <module>()
----> 1 get_ipython().magic('ls ')

I did not need to do anything special in Ubuntu 14.04. I have installed ipython2 and ipython3 with

pip2 install ipython --user
pip3 install ipython --user

I also tried installing it system-wide with sudo as

sudo pip2 install ipython
sudo pip3 install ipython

But the problem still persists. I do not get this problem in jupyter notebook.

How can I use system commands in IPython?

2 Answers 2


As written in ipython docs - You should prefix the command with !

e.g. for ls you should execute !ls

String lists (IPython.utils.text.SList) are handy way to process output from system commands. They are produced by var = !cmd syntax.

First, we acquire the output of ‘ls -l’:

[Q:doc/examples]|2> lines = !ls -l
['total 23',
 '-rw-rw-rw- 1 ville None 1163 Sep 30  2006 example-demo.py',
 '-rw-rw-rw- 1 ville None 1927 Sep 30  2006 example-embed-short.py',
 '-rwxrwxrwx 1 ville None 4606 Sep  1 17:15 example-embed.py',
 '-rwxrwxrwx 1 ville None 1017 Sep 30  2006 example-gnuplot.py',
 '-rwxrwxrwx 1 ville None  339 Jun 11 18:01 extension.py',
 '-rwxrwxrwx 1 ville None  113 Dec 20  2006 seteditor.py',
 '-rwxrwxrwx 1 ville None  245 Dec 12  2006 seteditor.pyc']
  • Thanks @Yaron for quick response, however, it gives same error even with how you suggested. By the way, if you execute ls command, do you also see error? In my case on Ubuntu 14.04 and on another system with Ubuntu 16.04 I do not get error even with plain ls command. Only on my laptop I see this error and i have no clue why ....
    – Imran
    Jun 19, 2017 at 16:04

When I was setting up my machine, I created a dummy rootUser as the first admin user. Later on, I created another user with the same name, uid and gid as my workplace and added it to sudo. This some how causes permission problems which is really strange. Though I do not know the actual cause of the problem but I did reproduce it with the above steps. I solved this problem by creating the first user with the name same as my workplace. Later i changed the uid and gid and file/directly permissions accordingly. This solved the problem and I can now use ipython2/3 normally.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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