2

When I printed the sys.path in IPython I was surprised to see the bin of the python installation inserted at the second position (sys.path[1]).

~> /opt/local/bin/ipython -c "import sys; [print(p) for p in sys.path]"

/opt/local/Library/Frameworks/Python.framework/Versions/3.4/bin
/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python34.zip
/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4
/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/plat-darwin
/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/lib-dynload
/Users/kenter/Library/Python/3.4/lib/python/site-packages
/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages
/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/IPython/extensions
/Users/kenter/.ipython
Out[1]: [None, None, None, None, None, None, None, None, None, None]

I'm referring to the /opt/local/Library/Frameworks/Python.framework/Versions/3.4/bin directory. It is not present when I print it using the regular python.

~> /opt/local/bin/python -c "import sys; [print(p) for p in sys.path]"

/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python34.zip
/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4
/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/plat-darwin
/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/lib-dynload
/Users/kenter/Library/Python/3.4/lib/python/site-packages
/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages

So, why does IPython add the bin directory to the sys.path? What's the purpose of this?

It doesn't cause any problems for me, I'm just curious.

titusjan
  • 5,376
  • 2
  • 24
  • 43
  • did you get an answer to this? I'm looking for an answer to the same question.. Funnily, when I launch the python console in pycharm (which also uses ipython), I don't see the bin directory being added to `sys.path` – kapad Feb 11 '20 at 15:24
  • No I didn't. I forgot even that I asked. Note that PyCharm does a lot of path manipulation itself, so it doesn't surprise me that the bin directory is gone in that case. – titusjan Feb 12 '20 at 12:06
  • 1
    Was trying to figure this out and I think it's something quite basic. Possibly, in IPython, your cwd, would probably always be getting set as the `python` executables `bin/` directory. And when you run a script or a program, that is being set to the directory of the shell you are executing from. – kapad Feb 16 '20 at 12:40

0 Answers0