Skip to content

Commit 2e5cf49

Browse files
authored
Merge pull request #5695 from kevin-bates/troubleshooting-docs
Add additional entries to troubleshooting section
2 parents 138b406 + bb55a1b commit 2e5cf49

File tree

1 file changed

+153
-7
lines changed

1 file changed

+153
-7
lines changed

docs/source/troubleshooting.rst

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

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

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

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?
82224
The ``jupyter troubleshoot`` command collects a lot of information
83-
about your installation, which can be useful.
225+
about your installation, which can also be useful.
226+
227+
When providing textual information, it's most helpful if you can *scrape* the contents
228+
into the issue rather than providing a screenshot. This enables others to select
229+
pieces of that content so they can search more efficiently and try to help.
84230

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

0 commit comments

Comments
 (0)