2

This is an update to the question below, because I've discovered the same thing happens when I start bokeh_server in a directory containing any script named code.py.

I have a directory, /Users/xnx/temp/ containing many (mostly disposable) files including various scripts. When I start IPython from the command within my Anaconda py33 virtual environment, it seems to run one of these scripts before dropping me into the IPython shell, because I get a list of the numbers and their cubes output to the screen before IPython shows its prompt:

Xnx-Mac:temp xnx$ py33
discarding /Users/xnx/anaconda/bin from PATH
prepending /Users/xnx/anaconda/envs/py33/bin to PATH
(py33)Xnx-Mac:temp xnx$ ipython
0
0
1
1
2
8
...
99
970299
Python 3.3.5 |Anaconda 2.0.1 (x86_64)| (default, Sep  2 2014, 13:57:31) 
Type "copyright", "credits" or "license" for more information.

IPython 2.3.0 -- An enhanced Interactive Python.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://binstar.org
?         -> 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]: 

(py33 is just a bash alias for source activate py33).

This doesn't seem to be causing any harm, but I'd like to know why it's happening. Any ideas?

EDIT: OK: the offending script is a file called code.py in my /Users/xnx/temp/ directory. Why is IPython executing this file before starting its shell? What if it had contained commands deleting files from my system? Can anyone else reproduce this? It doesn't seem to happen for Python 2.

3
  • What other bash aliases are set? Commented Apr 7, 2015 at 20:09
  • None of note... but see my edit. Commented Apr 7, 2015 at 20:15
  • look for an environmental variable PYTHON_STARTUP (I think) ... print env right before you start ipython Commented May 12, 2015 at 18:00

1 Answer 1

2

Well, with a little (lot of) help from chat.stackoverflow.com, I've tracked down the problem: My ~/.bash_profile file contained the line

export PYTHONPATH="/Users/xnx/research/python_modules:$PYTHONPATH"

which set the environment variable PYTHONPATH to /Users/xnx/research/python_modules: since $PYTHONPATH was not previously defined. The trailing colon leads to '' being added to sys.path, and the current working directory gets searched for the file code.py before the correct one in an IPython import on start-up.

Lesson learned: don't let $PYTHONPATH have a trailing colon.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.