Setting IPython as Default Python Environment



Different environment variables influence Python’s behaviour. PYTHONSTARTUP environment variable is assigned to a Python script. As an effect, this script gets executed before Python prompt appears. This is useful if certain modules are to be loaded by default every time a new Python session starts.

The following script (start.py) imports IPython module and executes start_ipython() function to replace default Python shell with prompt (>>>) by IPython shell when Python executable is invoked.

import os, IPython
os.environ['PYTHONSTARTUP'] = ''
IPython.start_ipython()
raise SystemExit

Assuming that this file is stored in Python’s installation directory (c:\python36), set PYTHONSTARTUP environment variable and start Python from command line. Then IPython shell appears as shown below −

Python’s Installation Directory

Note that the environment variable can be permanently set using System Properties dialog in Windows and using export command on Linux.

Advertisements