ipython reads wrong python version

Okay quick fix: which python gives you /usr/bin/python, right? Do which ipython and I bet that’ll be /usr/local/bin/ipython. Let’s look inside: Edit 9/7/16 — The file now looks like this: cat /usr/local/bin/ipython #!/usr/bin/python # -*- coding: utf-8 -*- import re import sys from IPython import start_ipython if __name__ == ‘__main__’: sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$’, ”, sys.argv[0]) … Read more

How to reload modules in django shell?

I’d suggest use IPython autoreload extension. ./manage.py shell In [1]: %load_ext autoreload In [2]: %autoreload 2 And from now all imported modules would be refreshed before evaluate. In [3]: from x import print_something In [4]: print_something() Out[4]: ‘Something’ # Do changes in print_something method in x.py file. In [5]: print_something() Out[5]: ‘Something else’ Works also … Read more

Disable IPython Exit Confirmation

If you also want Ctrl-D to exit without confirmation, in IPython 0.11, add c.TerminalInteractiveShell.confirm_exit = False to your config file *. If you don’t have a config file yet, run ipython profile create to create one. Note this ticket if you’re working within the Django shell. * The config file is located at: $HOME/.ipython/profile_default/ipython_config.py

How can I check if code is executed in the IPython notebook?

The following worked for my needs: get_ipython().__class__.__name__ It returns ‘TerminalInteractiveShell’ on a terminal IPython, ‘ZMQInteractiveShell’ on Jupyter (notebook AND qtconsole) and fails (NameError) on a regular Python interpreter. The method get_ipython() seems to be available in the global namespace by default when IPython is started. Wrapping it in a simple function: def is_notebook() -> bool: … Read more

OSX El Capitan: sudo pip install OSError: [Errno: 1] Operation not permitted

Instructions telling people to use sudo pip install are inherently wrong. If there is any tutorial out there which says you should use sudo pip then please file a bug against this package. The author is dis-educating the Python community, as time has proven sudo pip to be a broken practice. OSX El Capitan introduced … Read more

Javascript Error: IPython is not defined in JupyterLab

Jupyter Lab does support interactive matplotlib through the jupyter-matplotlib extension. The installation procedure is slightly more involved, but works fine. Since the ipympl Jupyter Lab version requires NodeJS, and NodeJS requires Windows 8.1, ipympl also has this requirement. As before, it is important to invoke the iPython magic command before plotting: Usage: %matplotlib widget Installation: … Read more

Passing IPython variables as arguments to bash commands

Prefix your variable names with a $. Example Say you want to copy a file file1 to a path stored in a python variable named dir_pth: dir_path = “/home/foo/bar” !cp file1 $dir_path from Ipython or Jupyter notebook EDIT Thanks to the suggestion from Catbuilts, if you want to concatenate multiple strings to form the path, … Read more