3

I am having trouble opening a jupyter notebook file. Jupyter notebook is giving me a FileNotFoundError error when looking for Python:

Traceback (most recent call last):
      File "/Users/myusername/anaconda/envs/dlnd/lib/python3.6/site-packages/notebook/base/handlers.py", line 503, in wrapper
        result = yield gen.maybe_future(method(self, *args, **kwargs))
      File "/Users/myusername/anaconda/envs/dlnd/lib/python3.6/site-packages/tornado/gen.py", line 1015, in run
        value = future.result()
      File "/Users/myusername/anaconda/envs/dlnd/lib/python3.6/site-packages/tornado/concurrent.py", line 237, in result
        raise_exc_info(self._exc_info)
      File "<string>", line 3, in raise_exc_info
      File "/Users/myusername/anaconda/envs/dlnd/lib/python3.6/site-packages/tornado/gen.py", line 1021, in run
        yielded = self.gen.throw(*exc_info)
      File "/Users/myusername/anaconda/envs/dlnd/lib/python3.6/site-packages/notebook/services/sessions/handlers.py", line 75, in post
        type=mtype))
      File "/Users/myusername/anaconda/envs/dlnd/lib/python3.6/site-packages/tornado/gen.py", line 1015, in run
        value = future.result()
      File "/Users/myusername/anaconda/envs/dlnd/lib/python3.6/site-packages/tornado/concurrent.py", line 237, in result
        raise_exc_info(self._exc_info)
      File "<string>", line 3, in raise_exc_info
      File "/Users/myusername/anaconda/envs/dlnd/lib/python3.6/site-packages/tornado/gen.py", line 1021, in run
        yielded = self.gen.throw(*exc_info)
      File "/Users/myusername/anaconda/envs/dlnd/lib/python3.6/site-packages/notebook/services/sessions/sessionmanager.py", line 79, in create_session
        kernel_id = yield self.start_kernel_for_session(session_id, path, name, type, kernel_name)
      File "/Users/myusername/anaconda/envs/dlnd/lib/python3.6/site-packages/tornado/gen.py", line 1015, in run
        value = future.result()
      File "/Users/myusername/anaconda/envs/dlnd/lib/python3.6/site-packages/tornado/concurrent.py", line 237, in result
        raise_exc_info(self._exc_info)
      File "<string>", line 3, in raise_exc_info
      File "/Users/myusername/anaconda/envs/dlnd/lib/python3.6/site-packages/tornado/gen.py", line 1021, in run
        yielded = self.gen.throw(*exc_info)
      File "/Users/myusername/anaconda/envs/dlnd/lib/python3.6/site-packages/notebook/services/sessions/sessionmanager.py", line 92, in start_kernel_for_session
        self.kernel_manager.start_kernel(path=kernel_path, kernel_name=kernel_name)
      File "/Users/myusername/anaconda/envs/dlnd/lib/python3.6/site-packages/tornado/gen.py", line 1015, in run
        value = future.result()
      File "/Users/myusername/anaconda/envs/dlnd/lib/python3.6/site-packages/tornado/concurrent.py", line 237, in result
        raise_exc_info(self._exc_info)
      File "<string>", line 3, in raise_exc_info
      File "/Users/myusername/anaconda/envs/dlnd/lib/python3.6/site-packages/tornado/gen.py", line 285, in wrapper
        yielded = next(result)
      File "/Users/myusername/anaconda/envs/dlnd/lib/python3.6/site-packages/notebook/services/kernels/kernelmanager.py", line 87, in start_kernel
        super(MappingKernelManager, self).start_kernel(**kwargs)
      File "/Users/myusername/anaconda/envs/dlnd/lib/python3.6/site-packages/jupyter_client/multikernelmanager.py", line 110, in start_kernel
        km.start_kernel(**kwargs)
      File "/Users/myusername/anaconda/envs/dlnd/lib/python3.6/site-packages/jupyter_client/manager.py", line 257, in start_kernel
        **kw)
      File "/Users/myusername/anaconda/envs/dlnd/lib/python3.6/site-packages/jupyter_client/manager.py", line 203, in _launch_kernel
        return launch_kernel(kernel_cmd, **kw)
      File "/Users/myusername/anaconda/envs/dlnd/lib/python3.6/site-packages/jupyter_client/launcher.py", line 128, in launch_kernel
        proc = Popen(cmd, **kwargs)
      File "/Users/myusername/anaconda/envs/dlnd/lib/python3.6/subprocess.py", line 707, in __init__
        restore_signals, start_new_session)
      File "/Users/myusername/anaconda/envs/dlnd/lib/python3.6/subprocess.py", line 1326, in _execute_child
        raise child_exception_type(errno_num, err_msg)
    FileNotFoundError: [Errno 2] No such file or directory: '/Users/myusername/anaconda3/envs/py3/bin/python'

I am following an online class. I started by creating a conda environment as shown below:

conda create --name dlnd python=3
source activate dlnd
conda install numpy matplotlib pandas jupyter notebook

Then I try to open the file given in the class:

jupyter notebook dlnd-your-first-neural-network.ipynb

And this is when the error occurs.

I suspect the issue is that I have no /Users/myusername/anaconda3/ directory (thus the FileNotFoundError). All of my anaconda stuff installed in /Users/myusername/anaconda/, and I have been using jupyter notebooks for a couple weeks now, running various .ipynb files in various environments, with no major issues.

I'm not sure why jupyter notebook is looking in anaconda3/ in the particular instance. I have tried reinstalling, but again everything is installed at /Users/myusername/anaconda/.

Anyone with more experience know what I'm missing?

Using a Macbook pro on 10.11

David
  • 2,846
  • 3
  • 22
  • 34
  • Do you really need anaconda? Debugging issues similar to this common with anaconda. – Akavall Mar 20 '17 at 05:19
  • Does the file `~/.jupyter/jupyter_notebook_config.py` exist? If yes, what are it's contents? – Nehal J Wani Mar 20 '17 at 05:24
  • 1
    http://stackoverflow.com/q/37433363/1005215 – Nehal J Wani Mar 20 '17 at 05:24
  • 1
    Where did you get the ipynb file from? Each ipynb file specifies which kernel it should use, so that might be the source of the error – darthbith Mar 20 '17 at 20:42
  • @darthbith The file was from an online course. Please see my recently added answer. I am still confused about this. I can see where the kernel is specified but what property of the `.ipynb` file actually specifies the environment? If I wanted to run the file in a specific environment, (like the `dlnd` that I was trying to use and from which I had opened the jupyter notebook interface) how would I do that? – David Mar 21 '17 at 04:09
  • I have posted an answer based on what I have done to solve the issue but if someone has a more articulate and less hacky answer I would be glad to accept it. – David Mar 21 '17 at 04:10
  • @NehalJWani there is no such file. `~/.jupyter/` contains only a file called `migrated` that is just a text timestamp. I had deleted the `~/.jupyter/` directory when trying a uninstall-reinstall solution. – David Mar 21 '17 at 04:12
  • @Akavall I am coming from a front-end background and particularly new to jupyter notebooks. I am just following an online course. Can you suggest some resources for alternatives to anaconda? – David Mar 21 '17 at 04:14
  • 1
    What tools are you going to be using? If it is `numpy`, `scipy`, `sklearn`, `pandas`, `matplotlib`, and so on, you can install them individually without using `anaconda`. You don't need any tools to replace `anaconda`. – Akavall Mar 21 '17 at 04:17
  • Just make sure to use `virtualenv`; it will make your life much easier. – Akavall Mar 21 '17 at 04:18
  • 1
    Do NOT use `virtualenv` with Anaconda - use conda environments! http://stackoverflow.com/q/34398676/2449192 – darthbith Mar 21 '17 at 13:37
  • Ah okay, thanks. I didn't have a clear understanding of the [difference between conda and anaconda](http://stackoverflow.com/questions/30034840/what-are-the-differences-between-conda-and-anaconda). If I have any more issues I will uninstall anaconda and just use conda by itself. – David Mar 21 '17 at 16:54

1 Answers1

4

Based on @NehalJWani suggested post, I found /Users/myusername/Library/Jupyter/kernels/python3/kernal.json, shown here:

{
 "argv": [
  "/Users/myusername/anaconda3/envs/py3/bin/python",
  "-m",
  "ipykernel",
  "-f",
  "{connection_file}"
 ],
 "display_name": "Python 3",
 "language": "python"
}

And modified it to specify anaconda instead of anaconda3:

{
 "argv": [
  "/Users/myusername/anaconda/envs/py3/bin/python",
  "-m",
  "ipykernel",
  "-f",
  "{connection_file}"
 ],
 "display_name": "Python 3",
 "language": "python"
}

Trying to rerun the jupyter notebook, the new error was then:

FileNotFoundError: [Errno 2] No such file or directory: 
'/Users/myusername/anaconda/envs/py3/bin/python'

Which is a step in the right direction, because at least now we are looking in anaconda instead of anaconda3. However, it is also looking in envs/py3/, and I do not have a py3 environment.

Looking at the .ipynb file like @darthbith suggested, the file metadata is:

"metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}

I see that the python3 kernel is specified here, but not the py3 environment.

Ultimately I ended up just making a py3 environment in place of my desired dlnd environment:

conda create -n py3 python=3

Trying to run the notebook again I get this error:

/Users/myusername/anaconda/envs/py3/bin/python:
No module named ipykernel

And so I just install ipykernal along with the other dependencies I would have needed eventually anyways:

conda install ipykernel numpy matplotlib pandas jupyter notebook

And now it works.

Community
  • 1
  • 1
David
  • 2,846
  • 3
  • 22
  • 34