Skip to content

IPython 0.13.1 ignoring $PYTHONSTARTUP #2706

Closed
rouge8 opened this Issue Dec 18, 2012 · 7 comments

4 participants

@rouge8
rouge8 commented Dec 18, 2012

IPython is ignoring the $PYTHONSTARTUP environment variable.

$HOME/.pythonrc.py:

print 'hello?'
$ PYTHONSTARTUP=$HOME/.pythonrc.py ipython
Python 2.7.3 (default, Nov 29 2012, 15:33:55) 
Type "copyright", "credits" or "license" for more information.

IPython 0.13.1 -- 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]: 
$ PYTHONSTARTUP=$HOME/.pythonrc.py python
Python 2.7.3 (default, Nov 29 2012, 15:33:55) 
[GCC 4.2.1 Compatible Apple Clang 4.1 ((tags/Apple/clang-421.11.66))] on darwin
Type "help", "copyright", "credits" or "license" for more information.
hello?
>>> 
@takluyver
IPython member

See also discussion on #2655, which was about tests.

IPython has its own methods for running things at startup - see IPYTHONDIR/profile_default/startup/. I'm not sure whether we should also support $PYTHONSTARTUP. If you want to make a pull request - which would speed up the question, but not guarantee we'd agree - a good place to start looking is here: https://github.com/ipython/ipython/blob/master/IPython/core/shellapp.py#L231

@rouge8
rouge8 commented Dec 18, 2012

IPYTHONDIR/profile_default/startup/ works fine for me. Are there any potential downsides to just executing $PYTHONSTARTUP from there?

import os

if os.environ['PYTHONSTARTUP']:
    execfile(os.environ['PYTHONSTARTUP'])

This seems to work, and if there aren't any problems with that, I'm perfectly content.

@takluyver
IPython member

That should be fine (although if you try to use IPython on Python 3, you'll probably see an error as it fails to find execfile, but that's easily worked around). It's just a question of whether we build something like that in by default.

@minrk
IPython member
minrk commented Jan 19, 2013

This looks resolved, shall we close?

@takluyver
IPython member

@minrk : The only question is whether we should run $PYTHONSTARTUP by default. It might be least-surprise if someone uses it for e.g. from __future__ import division.

@minrk minrk added a commit to minrk/ipython that referenced this issue Jul 6, 2013
@minrk minrk add PYTHONSTARTUP to startup files
closes #2706
9b4ad81
@Carreau Carreau closed this in #3569 Jul 9, 2013
@yang
yang commented Apr 11, 2014

I enable tab-completion in my ~/.pythonrc and have PYTHONSTARTUP set to this. This however now conflicts with ipython's tab completion. Is there some way to check if I'm in ipython vs regular python?

import readline, rlcompleter
readline.parse_and_bind( 'tab: complete' )
@minrk
IPython member
minrk commented Apr 11, 2014

@yang:

try:
    get_ipython
except NameError:
    in_ipython = False
else:
    in_ipython = True

This shouldn't be an issue anymore after #5582.

@mattvonrocketstein mattvonrocketstein pushed a commit to mattvonrocketstein/ipython that referenced this issue Nov 3, 2014
@minrk minrk add PYTHONSTARTUP to startup files
closes #2706
dd470b8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.