Created
March 2, 2023 20:24
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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