Skip to content

Instantly share code, notes, and snippets.

@tweekmonster
Created March 2, 2023 20:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tweekmonster/fd4b258f0c3fad8b35c41f39e80cc4fe to your computer and use it in GitHub Desktop.
Save tweekmonster/fd4b258f0c3fad8b35c41f39e80cc4fe to your computer and use it in GitHub Desktop.
Startup script to use ipython (if available in environment) when python is ran without arguments
import os
import sys
import site
if len(sys.argv) == 1:
del os.environ['PYTHONSTARTUP']
sys.path.append(site.USER_SITE)
try:
if 'IPython' in sys.modules:
raise ImportError('IPython is already imported')
import IPython
env = os.environ.copy()
env['PYTHONPATH'] = site.USER_SITE
print('Replacing with IPython...')
os.execve(
sys.executable, (os.path.basename(sys.executable), '-m', 'IPython'), env
)
except ImportError:
try:
import readline
import rlcompleter
readline.parse_and_bind('tab: complete')
except ImportError:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment