Repository: ipython/ipython

Issue:
Dealing with images in multidirectory environment
I am playing with this and I found this behaviour:

My directory have the following structure:
/Desarrollos
---/damian_blog
---/pyconar2013_talks
---/etc...

I started the notebook in `Desarrollos` using: `ipython notebook pyconar2013_talks/IPython_fu_talk.ipynb`

Then if I load an image in  markdown cell, `<img src="figs/logo.png" />` the files prepend is no longer necessary, which is great...

But if I try to load the image in a code cell, 

```
from IPython.display import Image
Image(filename='pyconar2013_talks/figs/logo.png')
```

I have to preppend with the `pyconar2013_talks` to make it render in the code cell... and if a preppend the src in the markdown cell `<img src="pyconar2013_talks/figs/logo.png" />`, it is not rendered...

This is the intended behaviour? Because we have a lack of consistency? Or a I missing something?

Dami]an.



Discussion:
What is the cwd of the kernel?

On Wed, Oct 23, 2013 at 6:32 AM, Damián Avila notifications@github.comwrote:

> I am playing with this and I found this behaviour:
> 
> My directory have the following structure:
> /Desarrollos
> /damian_blog
> /pyconar2013_talks
> /etc...
> 
> I started the notebook using: `ipython notebook
> pyconar2013_talks/IPython_fu_talk.ipynb
> 
> Then if I load an image in markdown cell, <img src="figs/logo.png" /> the
> files prepend is no longer necessary, which is great...
> 
> But if I try to load the image in a code cell,
> 
> from IPython.display import Image
> Image(filename='pyconar2013_talks/figs/logo.png')
> 
> I have to preppend with the pyconar2013_talks to make it render in the
> code cell... and if a preppend the src in the markdown cell <img
> src="pyconar2013_talks/figs/logo.png" />, it is not rendered...
> 
> This is the intended behaviour? Because we have a lack of consistency? Or
> a I missing something?
> 
> Damian.
> 
> —
> Reply to this email directly or view it on GitHubhttps://github.com/ipython/ipython/issues/4424
> .

## 

Brian E. Granger
Cal Poly State University, San Luis Obispo
bgranger@calpoly.edu and ellisonbg@gmail.com

Apparently the cwd of the kernel is the cwd of where the server start.
I don't think that was our plan.

Right, that is what I was thinking.  The cwd of the kernel should match the
location of the notebook.

On Wed, Oct 23, 2013 at 9:20 AM, Matthias Bussonnier <
notifications@github.com> wrote:

> Apparently the cwd of the kernel is the cwd of where the server start.
> I don't think that was our plan.
> 
> —
> Reply to this email directly or view it on GitHubhttps://github.com/ipython/ipython/issues/4424#issuecomment-26919509
> .

## 

Brian E. Granger
Cal Poly State University, San Luis Obispo
bgranger@calpoly.edu and ellisonbg@gmail.com


Resolving patch:
diff --git a/IPython/html/services/sessions/handlers.py b/IPython/html/services/sessions/handlers.py
--- a/IPython/html/services/sessions/handlers.py
+++ b/IPython/html/services/sessions/handlers.py
@@ -62,7 +62,7 @@ def post(self):
         if sm.session_exists(name=name, path=path):
             model = sm.get_session(name=name, path=path)
         else:
-            kernel_id = km.start_kernel(cwd=nbm.notebook_dir)
+            kernel_id = km.start_kernel(cwd=nbm.get_os_path(path))
             model = sm.create_session(name=name, path=path, kernel_id=kernel_id, ws_url=self.ws_url)
         location = url_path_join(self.base_kernel_url, 'api', 'sessions', model['id'])
         self.set_header('Location', url_escape(location))


Test patch: