[IPython-dev] ipython bash interaction?

Mark Voorhies mark.voorhies at ucsf.edu
Thu Sep 26 10:02:00 EDT 2013


On 09/26/2013 12:18 AM, Zoltán Vörös wrote:
> Hi Fernando,
>
> Thanks for the pointer! Based on your comment, I could figure out what
> the solution is.
>> >On 09/25/2013 06:11 PM, Fernando Perez wrote:
>>> >>I think it's possible to declare those in another one of the bash
>>> >>startup files that does get read by the GUI systems, but I've never
>>> >>bothered to look which one it should be. If you spend the time to make
>>> >>it work that way, let us know!
> Setting the path in .profile (for user), or in /etc/environment
> (system-wide) works for me. I suspect that .profile has to be replaced
> by something else, if one uses KDE or XCFE,

Yes, I've run into problems with .profile on KDE.  I think the Xsession link I gave is more general, but I haven't tried it.

> but I believe, .profile
> should work for gnome-derivatives.
>> >A related thread for getting the proper PYTHONSTARTUP when starting IDLE from a graphical session:
>> >http://lists.debian.org/debian-python/2009/11/msg00071.html
>> >I think an equivalent IPython hack would be to modify os.environ in the ipython launcher script.
> But it is quite obvious that this is not an ipython issue. As Fernando
> pointed out, the launcher doesn't know about the environmental
> variables, because it is not operating at the shell level.

The launcher sees the same environment as the kernel, which is the important detail for hacking environment variables.
E.g.:

Given:

#!/usr/bin/python
"""Terminal-based IPython entry point.
"""
from os import environ
from IPython import start_ipython
environ["THIS_IS_A_TEST"] = "Hello, world"
environ["PATH"] += ":/My/Favorite/Path"
start_ipython()

The following works from the console or the notebook:

mvoorhie at virgil:~$ ipython console
Python 2.7.3 (default, Apr 10 2013, 06:20:15)
Type "copyright", "credits" or "license" for more information.

IPython 1.1.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: !echo "$THIS_IS_A_TEST"
Hello, world

In [2]: !echo "$PATH"
/home/mvoorhie/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/My/Favorite/Path

--Mark




More information about the IPython-dev mailing list