In an interactive python shell, ''
is the first entry in sys.path
, but in IPython, the interpreters stdlib paths come first:
Python:
Python 3.10.5 (main, Jul 22 2022, 17:09:35) [GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys; sys.path
['', '/usr/local/lib/python310.zip', '/usr/local/lib/python3.10', '/usr/local/lib/python3.10/lib-dynload', '/usr/local/lib/python3.10/site-packages']
IPython:
Python 3.10.5 (main, Jul 22 2022, 17:09:35) [GCC 9.4.0]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.3.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: import sys; sys.path
Out[1]:
['/usr/local/bin',
'/usr/local/lib/python310.zip',
'/usr/local/lib/python3.10',
'/usr/local/lib/python3.10/lib-dynload',
'',
'/usr/local/lib/python3.10/site-packages']
I get this on several systems and also on https://www.pythonanywhere.com/try-ipython/, so it's not a local configuration issue. This did not use to be the case, see also the paths in IPython sys.path different from python sys.path (old question with a different problem).
Is this supposed to happen, and how can I disable it and have the same path as Python (without manually editing sys.path
in every session)?