Skip to content

Commit 1587a61

Browse files
committed
Add additional entries to troubleshooting section
1 parent a11d686 commit 1587a61

File tree

1 file changed

+150
-7
lines changed

1 file changed

+150
-7
lines changed

docs/source/troubleshooting.rst

Lines changed: 150 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Jupyter doesn't load or doesn't work in the browser
4343
Jupyter can't start a kernel
4444
----------------------------
4545

46-
Files called *kernel specs* tell Jupyter how to start different kinds of kernel.
46+
Files called *kernel specs* tell Jupyter how to start different kinds of kernels.
4747
To see where these are on your system, run ``jupyter kernelspec list``::
4848

4949
$ jupyter kernelspec list
@@ -65,22 +65,165 @@ try deleting or renaming that kernelspec folder to expose the default.
6565
If your problem is with another kernel, not the Python one we maintain,
6666
you may need to look for support about that kernel.
6767

68+
Python Environments
69+
-------------------
70+
Multiple python environments, whether based on Anaconda or Python Virtual environments,
71+
are often the source of reported issues. In many cases, these issues stem from the
72+
Notebook server running in one environment, while the kernel and/or its resources,
73+
derive from another environment. Indicators of this scenario include:
74+
75+
* ``import`` statements within code cells producing ``ModuleNotFound`` exceptions.
76+
* General kernel startup failures exhibited by nothing happening when attempting
77+
to execute a cell.
78+
79+
In these situations, take a close look at your environment structure and ensure all
80+
packages required by your notebook's code are installed in the correct environment.
81+
If you need to run the kernel from different conda environments than your Notebook
82+
server, you might consider using `nb_conda_kernels <https://github.com/Anaconda-Platform/nb_conda_kernels>`_.
83+
84+
Another thing to check is the ``kernel.json`` file that will be located in the
85+
aforementioned *kernel specs* directory identified by running ``jupyter kernelspec list``.
86+
This file will contain an ``argv`` stanza that includes the actual command to run
87+
when launching the kernel. Oftentimes, when reinstalling python environments, a previous
88+
``kernel.json`` will reference an python executable from an old or non-existent location.
89+
As a result, it's always a good idea when encountering kernel startup issues to validate
90+
the ``argv`` stanza to ensure all file references exist and are appropriate.
91+
92+
Windows Systems
93+
---------------
94+
Although Jupyter Notebook is primarily developed on the various flavors of the Unix
95+
operating system it also supports Microsoft
96+
Windows - which introduces its own set of commonly encountered issues,
97+
particularly in the areas of security, process management and lower-level libraries.
98+
99+
pywin32 Issues
100+
^^^^^^^^^^^^^^^^^^
101+
The primary package for interacting with Windows' primitives is ``pywin32``.
102+
103+
* Issues surrounding the creation of the kernel's communication file utilize
104+
``jupyter_core``'s ``secure_write()`` function. This function ensures a file is
105+
created in which only the owner of the file has access. If libraries like ``pywin32``
106+
are not properly installed, issues can arise when it's necessary to use the native
107+
Windows libraries.
108+
109+
Here's a portion of such a traceback::
110+
111+
File "c:\users\jovyan\python\myenv.venv\lib\site-packages\jupyter_core\paths.py", line 424, in secure_write
112+
win32_restrict_file_to_user(fname)
113+
File "c:\users\jovyan\python\myenv.venv\lib\site-packages\jupyter_core\paths.py", line 359, in win32_restrict_file_to_user
114+
import win32api
115+
ImportError: DLL load failed: The specified module could not be found.
116+
117+
* As noted earlier, the installation of ``pywin32`` can be problematic on Windows
118+
configurations. When such an issue occurs, you may need to revisit how the environment
119+
was setup. Pay careful attention to whether you're running the 32 or 64 bit versions
120+
of Windows and be sure to install appropriate packages for that environment.
121+
122+
Here's a portion of such a traceback::
123+
124+
File "C:\Users\jovyan\AppData\Roaming\Python\Python37\site-packages\jupyter_core\paths.py", line 435, in secure_write
125+
win32_restrict_file_to_user(fname)
126+
File "C:\Users\jovyan\AppData\Roaming\Python\Python37\site-packages\jupyter_core\paths.py", line 361, in win32_restrict_file_to_user
127+
import win32api
128+
ImportError: DLL load failed: %1 is not a valid Win32 application
129+
130+
Resolving pywin32 Issues
131+
""""""""""""""""""""""""""""
132+
In this case, your ``pywin32`` module may not be installed correctly and the following
133+
should be attempted:
134+
::
135+
136+
pip install --upgrade pywin32
137+
138+
or::
139+
140+
conda install --force-reinstall pywin32
141+
142+
followed by::
143+
144+
python.exe Scripts/pywin32_postinstall.py -install
145+
146+
where ``Scripts`` is located in the active Python's installation location.
147+
148+
* Another common failure specific to Windows environments is the location of various
149+
python commands. On ``*nix`` systems, these typically reside in the ``bin`` directory
150+
of the active Python environment. However, on Windows, these tend to reside in the
151+
``Scripts`` folder - which is a sibling to ``bin``. As a result, when encountering
152+
kernel startup issues, again, check the ``argv`` stanza and verify it's pointing to a
153+
valid file. You may find that it's pointing in ``bin`` when ``Scripts`` is correct, or
154+
the referenced file does not include its ``.exe`` extension - typically resulting in
155+
``FileNotFoundError`` exceptions.
156+
157+
This Worked An Hour Ago
158+
-----------------------
159+
The Jupyter stack is very complex and rightfully so, there's a lot going on. On occassion
160+
you might find the system working perfectly well, then, suddenly, you can't get past a
161+
certain cell due to ``import`` failures. In these situations, it's best to ask yourself
162+
if any new python files were added to your notebook development area.
163+
164+
These issues are usually evident by carefully analyzing the traceback produced in
165+
the notebook error or the Notebook server's command window. In these cases, you'll typically
166+
find the Python kernel code (from ``IPython`` and ``ipykernel``) performing *its* imports
167+
and notice a file from your Notebook development error included in that traceback followed
168+
by an ``AttributeError``::
169+
170+
File "C:\Users\jovyan\anaconda3\lib\site-packages\ipykernel\connect.py", line 13, in
171+
from IPython.core.profiledir import ProfileDir
172+
File "C:\Users\jovyan\anaconda3\lib\site-packages\IPython_init.py", line 55, in
173+
from .core.application import Application
174+
...
175+
File "C:\Users\jovyan\anaconda3\lib\site-packages\ipython_genutils\path.py", line 13, in
176+
import random
177+
File "C:\Users\jovyan\Desktop\Notebooks\random.py", line 4, in
178+
rand_set = random.sample(english_words_lower_set, 12)
179+
AttributeError: module 'random' has no attribute 'sample'
180+
181+
What has happened is that you have named a file that conflicts with an installed package
182+
that is used by the kernel software and now introduces a conflict preventing the
183+
kernel's startup.
184+
185+
**Resolution**: You'll need to rename your file. A best practice would be to prefix or
186+
*namespace* your files so as not to conflict with any python package.
187+
188+
68189
Asking for help
69190
---------------
70191

71192
As with any problem, try searching to see if someone has already found an answer.
72193
If you can't find an existing answer, you can ask questions at:
73194

195+
* The `Jupyter Discourse Forum <https://discourse.jupyter.org/>`_
74196
* The `jupyter-notebook tag on Stackoverflow <https://stackoverflow.com/questions/tagged/jupyter-notebook>`_
75-
* The `jupyter/help repository on Github <https://github.com/jupyter/help>`_
197+
* Peruse the `jupyter/help repository on Github <https://github.com/jupyter/help>`_ (read-only)
76198
* Or in an issue on another repository, if it's clear which component is
77-
responsible.
199+
responsible. Typical repositories include:
200+
201+
* `jupyter_core <https://github.com/jupyter/jupyter_core>`_ - ``secure_write()``
202+
and file path issues
203+
* `jupyter_client <https://github.com/jupyter/jupyter_core>`_ - kernel management
204+
issues found in Notebook server's command window.
205+
* `IPython <https://github.com/ipython/ipython>`_ and
206+
`ipykernel <https://github.com/ipython/ipykernel>`_ - kernel runtime issues
207+
typically found in Notebook server's command window and/or Notebook cell execution.
208+
209+
Gathering Information
210+
^^^^^^^^^^^^^^^^^^^^^
211+
Should you find that your problem warrants that an issue be opened in
212+
`notebook <https://github.com/jupyter/notebook>`_ please don't forget to provide details
213+
like the following:
214+
215+
* What error messages do you see (within your notebook and, more importantly, in
216+
the Notebook server's command window)?
217+
* What platform are you on?
218+
* How did you install Jupyter?
219+
* What have you tried already?
78220

79-
Don't forget to provide details. What error messages do you see?
80-
What platform are you on? How did you install Jupyter?
81-
What have you tried already?
82221
The ``jupyter troubleshoot`` command collects a lot of information
83-
about your installation, which can be useful.
222+
about your installation, which can also be useful.
223+
224+
When providing textual information, it's most helpful if you can *scrape* the contents
225+
into the issue rather than providing a screenshot. This enables others to select
226+
pieces of that content so they can search more efficiently and try to help.
84227

85228
Remember that it's not anyone's job to help you.
86229
We want Jupyter to work for you,

0 commit comments

Comments
 (0)