Setting IPython as Default Python Environment



Different environment variables influence Pythons 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.

Starting IPython using Script

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.

start.py

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

Output

(myenv) D:\Projects\python\myenv>py start.py
Python 3.14.2 (tags/v3.14.2:df79316, Dec  5 2025, 17:18:21) [MSC v.1944 64 bit (AMD64)]
Type 'copyright', 'credits' or 'license' for more information
IPython 9.8.0 -- An enhanced Interactive Python. Type '?' for help.
Tip: Use `object?` to see the help on `object`, `object??` to view its source

In [1]:

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

Pythons Installation Directory

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

Advertisements