Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to add directory to sys.path on ipython startup

Tags:

python

ipython

env:

  • windows 7 English 32bit
  • python 2.7.3
  • ipython 0.13.1

I try the config:

ipython -i -c "import sys; sys.path.append('path_name')"

But it does not seem to work.
So what's the proper solution?

Or how to add current directory to sys.path on ipython startup?
Thanks.

like image 247
Honghe.Wu Avatar asked Feb 28 '13 14:02

Honghe.Wu


2 Answers

just a little follow up to Honghe.Wu's answer.

One might want to add:

c.InteractiveShellApp.exec_lines = [
'import sys; sys.path.append("/absolute/path/")']

to the ipython_config.py to add an arbitrary directory.

Also, if you are new to ipython (as I am) you need to create the standard profile first, so the ipython_config.py actually exists. So you need:

ipython profile create

and you can locate the configuration directory by

ipython locate

Best S

like image 88
stevosn Avatar answered Sep 20 '22 20:09

stevosn


With the help of @cartman, I currently use the flowing config in the file ipython_config.py to add current directory to sys.path:

c.InteractiveShellApp.exec_lines = [
'import sys,os; sys.path.append(os.getcwd())'
]

Until there is a better solution.

like image 39
Honghe.Wu Avatar answered Sep 23 '22 20:09

Honghe.Wu