500 internal server error when I launch Jupyter notebook - python

I currently decided to re-install jupyter since the kernel was continuously stopping. After having conda uninstalled ipykernel and re-installed it back, I incurred in a series of issues:
First once I opened the notebooks on jupyter a 500 internal error occurred;
Second I tried to re-install nbconvert as suggested in some issues on the topic but nothing changed;
third I tried to conda re-install jupyter but now even jupyter command is not working
I am currently on Mac OS Catalina Version 10.15.7. I have done a conda list and apparently everything is installed on the (base) environment where I am operating, namely:
ipykernel 6.15.2 pypi_0 pypi
...
jupyter 1.0.0 py38hecd8cb5_8
jupyter-client 7.3.5 pypi_0 pypi
jupyter-console 6.4.4 pypi_0 pypi
jupyter-telemetry 0.1.0 pypi_0 pypi
jupyter_client 7.3.4 py38hecd8cb5_0
jupyter_console 6.4.3 pyhd3eb1b0_0
jupyter_core 4.10.0 py38hecd8cb5_0
jupyter_server 1.13.5 pyhd3eb1b0_0
jupyterhub 2.3.1 pypi_0 pypi
jupyterlab 3.3.2 pyhd3eb1b0_0
jupyterlab-pygments 0.2.2 pypi_0 pypi
jupyterlab-widgets 3.0.3 pypi_0 pypi
jupyterlab_server 2.10.3 pyhd3eb1b0_1
jupyterlab_widgets 1.0.0 pyhd3eb1b0_1
...
nbconvert 7.0.0 pypi_0 pypi
Am I doing something wrong? How can I solve the issue with all the needed packages up to date?
EDIT: Furthermore when I type simple commands such as conda list the following appears:
(base) MacBook-Pro-di-federico:Dropbox federiconutarelli$ conda list
Error processing line 1 of /Users/federiconutarelli/opt/anaconda3/lib/python3.8/site-packages/matplotlib-3.5.2-py3.8-nspkg.pth:
Traceback (most recent call last):
File "/Users/federiconutarelli/opt/anaconda3/lib/python3.8/site.py", line 169, in addpackage
exec(line)
File "<string>", line 1, in <module>
File "<frozen importlib._bootstrap>", line 553, in module_from_spec
AttributeError: 'NoneType' object has no attribute 'loader'
Reminder of file ignored
...
before listing the packages.
Thank you

If you have installed a more recent version of "jinja2", it may break "nbconvert".
You can either try to update "nbconvert" or downgrade "jinja2".
Jupyter Notebook 500 : Internal Server Error

Related

Jupyter: `ipykernel_launcher.py: error: the following arguments are required: --config` when opening notebook in project directory

I am trying to create and run a jupyter notebook (jupyter notebook --port xxxx) in the directory of a project I am working on to do some debugging. When I try to run it the notebook fails to connect to a kernel with the following error returned by the server repeatedly:
[I 17:29:24.011 NotebookApp] KernelRestarter: restarting kernel (5/5), new random ports
2022-01-28 17:29:24.789877: I tensorflow/stream_executor/platform/default/dso_loader.cc:49]
Successfully opened dynamic library libcudart.so.11.0
usage: ipykernel_launcher.py [-h] --config CONFIG [--results_dir RESULTS_DIR]
ipykernel_launcher.py: error: the following arguments are required: --config
This is an empty notebook where I am trying to execute the first cell, it happens irrespective of the code that this cell contains. On top of that I CAN RUN A NOTEBOOK IN ANY OTHER DIRECTORY FROM THE SAME SERVER which makes this extra strange!
It seems that jupyter implicitly runs some code during kernel start that reads whatever is in my project directory out of context and inevitably fails to run it. I want to run it in that very directory to test the module I am working on.
I tried deleting .ipynb_checkpoints, restarting the server and recreating the notebook from scratch, but that didn't help.
Here is a selected pip list of the modules I have installed in my conda environment. Python version == 3.7.0
Package Version
----------------------- ---------
importlib-metadata 4.10.1
importlib-resources 5.4.0
ipykernel 6.7.0
ipython 7.31.1
ipython-genutils 0.2.0
ipywidgets 7.6.5
jupyter 1.0.0
jupyter-client 7.1.2
jupyter-console 6.4.0
jupyter-core 4.9.1
jupyterlab-pygments 0.1.2
jupyterlab-widgets 1.0.2
Keras-Preprocessing 1.1.2
matplotlib 3.5.1
matplotlib-inline 0.1.3
nbclient 0.5.10
nbconvert 6.4.1
nbformat 5.1.3
notebook 6.4.8
numpy 1.19.5
pandas 1.1.5
scipy 1.7.3
tensorboard 2.8.0
tensorboard-data-server 0.6.1
tensorboard-plugin-wit 1.8.1
tensorflow-estimator 2.4.0
tensorflow-gpu 2.4.0
typing 3.7.4.3
typing_extensions 4.0.1
Edit: This file is contained in the same directory as the notebook I am trying to run:
import argparse
from myModule.training import main
parser = argparse.ArgumentParser()
parser.add_argument('--config', type=str, required=True)
parser.add_argument('--results_dir', type=str, default='results_training')
args = parser.parse_args()
config = args.config
results_dir = args.results_dir
hist = main(config, results_dir)

Matplotlib style.use('tex') error in MacOS

Firstly apologies for the similarity to other questions, but I believe this is a different issue from all the previous questions/answers I have found. Please refer me to other questions if you think I'm wrong, but please also read the full question to check I haven't already tried the solution provided in the other question.
I had a working setup using Conda and matplotlib to do data-processing and plot figure with latex formatted captions etc, due to some lingering issues I did a full clean install. Trying to recreate my environment from before produces this error, unsure exactly what version of Catalina I was running pre-reboot but the Big Sur version I'm now running is 11.2.1.
Code required to reproduce the issue (running in a miniconda environment, full package list at the end):
import matplotlib.pyplot as plt
plt.style.use('tex')
I have confirmed the following:
tex and latex are both installed and work, both are found by "which" and both run, version information:
tex: Version 3.14159265 (TeX Live 2020)
latex: pdfTeX, Version 3.14159265-2.6-1.40.21 (TeX Live 2020)
dvipng is installed and runs (v 1.17)
Ghostscript is installed and runs (v 9.50)
The above are all present in PATH, as well as os.environ['PATH']:
latex, tex, dvipng are in /Library/TeX/texbin/
gs is in /usr/local/bin
Full error output:
Traceback (most recent call last):
File "/Users/will_gerrard/opt/miniconda3/envs/plotting/lib/python3.8/site-packages/matplotlib/style/core.py", line 121, in use
rc = rc_params_from_file(style, use_default_template=False)
File "/Users/will_gerrard/opt/miniconda3/envs/plotting/lib/python3.8/site-packages/matplotlib/__init__.py", line 883, in rc_params_from_file
config_from_file = _rc_params_in_file(fname, fail_on_error=fail_on_error)
File "/Users/will_gerrard/opt/miniconda3/envs/plotting/lib/python3.8/site-packages/matplotlib/__init__.py", line 812, in _rc_params_in_file
with _open_file_or_url(fname) as fd:
File "/Users/will_gerrard/opt/miniconda3/envs/plotting/lib/python3.8/contextlib.py", line 113, in __enter__
return next(self.gen)
File "/Users/will_gerrard/opt/miniconda3/envs/plotting/lib/python3.8/site-packages/matplotlib/__init__.py", line 790, in _open_file_or_url
with open(fname, encoding=encoding) as f:
FileNotFoundError: [Errno 2] No such file or directory: 'tex'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/will_gerrard/opt/miniconda3/envs/plotting/lib/python3.8/site-packages/matplotlib/style/core.py", line 124, in use
raise IOError(
OSError: 'tex' not found in the style library and input is not a valid URL or path; see `style.available` for list of available styles
Questions I have:
How can I have the following sequence of outputs:
os.environ['PATH'] and sys.path both show '/Library/TeX/texbin'
os.path.isfile('/Library/TeX/texbin/tex') -> True
os.path.isfile('tex') -> False
Why is Matplotlib trying to open the tex executable as if its a (utf-8) text file ?
What other things should I try / verify ?
Thanks in advance !
Full Conda list output:
# Name Version Build Channel
blas 1.0 mkl
ca-certificates 2020.12.5 h033912b_0 conda-forge
cairo 1.16.0 h0ab9d94_1001 conda-forge
certifi 2020.12.5 py38h50d1736_1 conda-forge
curl 7.71.1 hb0a8c7a_1
cycler 0.10.0 py38_0
fontconfig 2.13.1 hd23ceaa_1004 conda-forge
freetype 2.10.4 ha233b18_0
gettext 0.19.8.1 h7937167_1005 conda-forge
glib 2.67.4 hdf23fa2_1
gmp 6.1.2 h0a44026_1000 conda-forge
graphite2 1.3.13 h12caacf_1001 conda-forge
harfbuzz 1.8.8 hb8d4a28_0
icu 58.2 h0a44026_1000 conda-forge
intel-openmp 2019.4 233
jpeg 9b he5867d9_2
kiwisolver 1.3.1 py38h23ab428_0
krb5 1.18.2 h75d18d8_0
lcms2 2.11 h92f6f08_0
libcurl 7.71.1 h8a08a2b_1
libcxx 10.0.0 1
libedit 3.1.20191231 h1de35cc_1
libffi 3.3 hb1e8313_2
libgfortran 3.0.1 h93005f0_2
libiconv 1.16 haf1e3a3_0 conda-forge
libpng 1.6.37 ha441bb4_0
libssh2 1.9.0 h52ee1ee_6 conda-forge
libtiff 4.1.0 hcb84e12_1
libxml2 2.9.10 h7cdb67c_3
lz4-c 1.9.3 h23ab428_0
matplotlib 3.3.4 py38hecd8cb5_0
matplotlib-base 3.3.4 py38h8b3ea08_0
mkl 2019.4 233
mkl-service 2.3.0 py38h9ed2024_0
mkl_fft 1.3.0 py38ha059aab_0
mkl_random 1.1.1 py38h959d312_0
mpfr 4.0.2 h44b798e_0 conda-forge
ncurses 6.2 h0a44026_1
numpy 1.19.2 py38h456fd55_0
numpy-base 1.19.2 py38hcfb5961_0
olefile 0.46 py_0
openjpeg 2.3.1 h254dc36_3 conda-forge
openssl 1.1.1j hbcf498f_0 conda-forge
ordered-set 4.0.2 pypi_0 pypi
pandas 1.2.3 py38hb2f4e1b_0
pcre 8.44 h4a8c4bd_0 conda-forge
pillow 8.1.2 py38h5270095_0
pip 21.0.1 py38hecd8cb5_0
pixman 0.38.0 h01d97ff_1003 conda-forge
poppler 0.81.0 h2ef9dbd_1
poppler-data 0.4.10 0 conda-forge
pyparsing 2.4.7 pyhd3eb1b0_0
python 3.8.8 h88f2d9e_4
python-dateutil 2.8.1 pyhd3eb1b0_0
python_abi 3.8 1_cp38 conda-forge
pytz 2021.1 pyhd3eb1b0_0
readline 8.1 h9ed2024_0
scipy 1.6.1 py38h2515648_0
seaborn 0.11.1 pyhd3eb1b0_0
setuptools 52.0.0 py38hecd8cb5_0
six 1.15.0 py38hecd8cb5_0
sqlite 3.33.0 hffcf06c_0
texlive-core 20180414 ha09c46f_0
tk 8.6.10 hb0a8c7a_0
tornado 6.1 py38h9ed2024_0
wheel 0.36.2 pyhd3eb1b0_0
xz 5.2.5 h1de35cc_0
zlib 1.2.11 h1de35cc_3
zstd 1.4.5 h41d2c2f_0
UPDATE:
Tried using
plt.rcParams.update({
"text.usetex": True})
And producing a simple plot, the following error occurs:
Traceback (most recent call last):
File "/Users/will_gerrard/opt/miniconda3/envs/plotting/lib/python3.8/site-packages/matplotlib/texmanager.py", line 275, in _run_checked_subprocess
report = subprocess.check_output(command,
File "/Users/will_gerrard/opt/miniconda3/envs/plotting/lib/python3.8/subprocess.py", line 415, in check_output
return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
File "/Users/will_gerrard/opt/miniconda3/envs/plotting/lib/python3.8/subprocess.py", line 516, in run
raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['latex', '-interaction=nonstopmode', '--halt-on-error', '/Users/will_gerrard/.matplotlib/tex.cache/d2acc2706db635f7f7afe7dc80ac47f1.tex']' returned non-zero exit status 1.
Here is the full report generated by latex:
warning: kpathsea: configuration file texmf.cnf not found in these directories: /Users/will_gerrard/opt/miniconda3/envs/plotting/bin:/Users/will_gerrard/opt/miniconda3/envs/plotting/bin/share/texmf-local/web2c:/Users/will_gerrard/opt/miniconda3/envs/plotting/bin/share/texmf-dist/web2c:/Users/will_gerrard/opt/miniconda3/envs/plotting/bin/share/texmf/web2c:/Users/will_gerrard/opt/miniconda3/envs/plotting/bin/texmf-local/web2c:/Users/will_gerrard/opt/miniconda3/envs/plotting/bin/texmf-dist/web2c:/Users/will_gerrard/opt/miniconda3/envs/plotting/bin/texmf/web2c:/Users/will_gerrard/opt/miniconda3/envs/plotting:/Users/will_gerrard/opt/miniconda3/envs/plotting/share/texmf-local/web2c:/Users/will_gerrard/opt/miniconda3/envs/plotting/share/texmf-dist/web2c:/Users/will_gerrard/opt/miniconda3/envs/plotting/share/texmf/web2c:/Users/will_gerrard/opt/miniconda3/envs/plotting/texmf-local/web2c:/Users/will_gerrard/opt/miniconda3/envs/plotting/texmf-dist/web2c:/Users/will_gerrard/opt/miniconda3/envs/plotting/texmf/web2c:/Users/will_gerrard/opt/miniconda3/texmf-local/web2c:/Users/will_gerrard/opt/miniconda3/envs:/Users/will_gerrard/opt/miniconda3/envs/share/texmf-local/web2c:/Users/will_gerrard/opt/miniconda3/envs/share/texmf-dist/web2c:/Users/will_gerrard/opt/miniconda3/envs/share/texmf/web2c:/Users/will_gerrard/opt/miniconda3/envs/texmf-local/web2c:/Users/will_gerrard/opt/miniconda3/envs/texmf-dist/web2c:/Users/will_gerrard/opt/miniconda3/envs/texmf/web2c.
This is pdfTeX, Version 3.14159265-2.6-1.40.19 (TeX Live 2018) (preloaded format=latex)
kpathsea: Running mktexfmt latex.fmt
warning: kpathsea: configuration file texmf.cnf not found in these directories: /Users/will_gerrard/opt/miniconda3/envs/plotting/bin:/Users/will_gerrard/opt/miniconda3/envs/plotting/bin/share/texmf-local/web2c:/Users/will_gerrard/opt/miniconda3/envs/plotting/bin/share/texmf-dist/web2c:/Users/will_gerrard/opt/miniconda3/envs/plotting/bin/share/texmf/web2c:/Users/will_gerrard/opt/miniconda3/envs/plotting/bin/texmf-local/web2c:/Users/will_gerrard/opt/miniconda3/envs/plotting/bin/texmf-dist/web2c:/Users/will_gerrard/opt/miniconda3/envs/plotting/bin/texmf/web2c:/Users/will_gerrard/opt/miniconda3/envs/plotting:/Users/will_gerrard/opt/miniconda3/envs/plotting/share/texmf-local/web2c:/Users/will_gerrard/opt/miniconda3/envs/plotting/share/texmf-dist/web2c:/Users/will_gerrard/opt/miniconda3/envs/plotting/share/texmf/web2c:/Users/will_gerrard/opt/miniconda3/envs/plotting/texmf-local/web2c:/Users/will_gerrard/opt/miniconda3/envs/plotting/texmf-dist/web2c:/Users/will_gerrard/opt/miniconda3/envs/plotting/texmf/web2c:/Users/will_gerrard/opt/miniconda3/texmf-local/web2c:/Users/will_gerrard/opt/miniconda3/envs:/Users/will_gerrard/opt/miniconda3/envs/share/texmf-local/web2c:/Users/will_gerrard/opt/miniconda3/envs/share/texmf-dist/web2c:/Users/will_gerrard/opt/miniconda3/envs/share/texmf/web2c:/Users/will_gerrard/opt/miniconda3/envs/texmf-local/web2c:/Users/will_gerrard/opt/miniconda3/envs/texmf-dist/web2c:/Users/will_gerrard/opt/miniconda3/envs/texmf/web2c.
/Users/will_gerrard/opt/miniconda3/envs/plotting/bin/mktexfmt: kpsewhich -var-value=TEXMFROOT failed, aborting early.
BEGIN failed--compilation aborted at /Users/will_gerrard/opt/miniconda3/envs/plotting/bin/mktexfmt line 25.
I can't find the format file `latex.fmt'!

Can't find correct directory for Python module

I'm using a docker container with from base image jupyter/tensorflow-notebook While trying to run a command kale , it shows error
Traceback (most recent call last):
File "/usr/local/bin/kale", line 7, in <module>
from kale.command_line import main
File "/usr/local/lib/python3.6/dist-packages/kale/command_line.py", line 2, in <module>
import nbformat as nb
File "/usr/local/lib/python3.6/dist-packages/nbformat/__init__.py", line 9, in <module>
from ipython_genutils import py3compat
ModuleNotFoundError: No module named 'ipython_genutils'
While trying to install ipython_genutils using pip install ipython_genutils, it says
Requirement already satisfied: ipython_genutils in /opt/conda/lib/python3.7/site-packages (0.2.0)
The same can be confirmed with conda list which does among others show
ipython_genutils 0.2.0 py_1 conda-forge
However pip list doesn't show the same. My question is how can I make kale know to find the module in the correct directory?
You described three different python environments-
Requirement already satisfied: ipython_genutils in /opt/conda/lib/python3.7/site-packages
File "/usr/local/lib/python3.6/dist-packages/nbformat/__init__.py"
ipython_genutils 0.2.0 py_1 conda-forge
The first is a conda python3.7 environment. The second is a user-global python3.6 environment. The third is inside conda (am not an expert, could be the first one and the third are the same)
So "kale" is using python3.6, but ipython_genutils is installed in conda. I would uninistall kale using pip (python3.6 -m pip - have to make sure the pip for the correct environment!), and reinstall it with conda.

ipywidgets.embed missing dependencies? Key error when run in venv

I am writing a script that simply asks the google api for the latitudes and longitudes for a list of addresses read in from a csv file and outputs an html with the googlemap widget embedded. Further I hoped to run pyinstaller in order to make this into a .exe.
Running the code on my original conda environment it works fine however the .exe that pyinstaller creates is massive for such a small script (over 300mb). As such, I created a new virtual environment in which to work and have installed what I believe to be the bare minimum packages necessary and have rewritten the code to use as few packages as I am able which for the currently working portion of the code dropped it down considerably to just over 10 mb. (No numpy or pandas for me... ah well).
The code again works fine up until the final step:
from ipywidgets.embed import embed_minimal_html
embed_minimal_html("exporttest.html", None)
The above line should take any widgets, in particular the figure created from
fig = gmaps.figure(layout=figure_layout)
markers = gmaps.marker_layer(coordinates)
fig.add_layer(markers)
fig
Running the currently modified version in my original conda environment with all my of my usual packages installed this runs as expected without errors. Running on the virtual environment however on the mentioned lines I get the following key error:
KeyError Traceback (most recent call last)
c:\programdata\anaconda3\envs\synod_environ\lib\sre_parse.py in
parse_template(source, pattern)
1020 try:
-> 1021 this = chr(ESCAPES[this][1])
1022 except KeyError:
KeyError: '\\u'
During handling of the above exception, another exception occurred:
error Traceback (most recent call last)
<ipython-input-5-3359941239ab> in <module>
1 from ipywidgets.embed import embed_minimal_html
2
----> 3 embed_minimal_html("exporttest.html", None)
...
error: bad escape \u at position 0
(For clarification, key error has two slashes before the u, some frustration in getting this to post correctly)
As the code runs correctly in the one environment but not the other, I can only assume that I'm missing a package somewhere that ipywidgets requires, but running pip check doesn't notify me of anything missing.
pip list returns the following packages:
altgraph 0.16.1
backcall 0.1.0
bleach 3.0.2
certifi 2018.10.15
chardet 3.0.4
colorama 0.4.0
decorator 4.3.0
defusedxml 0.5.0
entrypoints 0.2.3
future 0.17.1
geojson 2.4.1
gmaps 0.8.2
idna 2.7
ipykernel 5.1.0
ipython 7.1.1
ipython-genutils 0.2.0
ipywidgets 7.4.2
jedi 0.13.1
Jinja2 2.10
jsonschema 2.6.0
jupyter 1.0.0
jupyter-client 5.2.3
jupyter-console 6.0.0
jupyter-core 4.4.0
macholib 1.11
MarkupSafe 1.0
mistune 0.8.4
nbconvert 5.4.0
nbformat 4.4.0
notebook 5.7.0
pandocfilters 1.4.2
parso 0.3.1
pefile 2018.8.8
pickleshare 0.7.5
pip 10.0.1
prometheus-client 0.4.2
prompt-toolkit 2.0.7
Pygments 2.2.0
PyInstaller 3.4
python-dateutil 2.7.5
pywin32-ctypes 0.2.0
pywinpty 0.5.4
pyzmq 17.1.2
qtconsole 4.4.2
requests 2.20.0
Send2Trash 1.5.0
setuptools 40.4.3
six 1.11.0
terminado 0.8.1
testpath 0.4.2
tornado 5.1.1
traitlets 4.3.2
urllib3 1.24
wcwidth 0.1.7
webencodings 0.5.1
wheel 0.32.2
widgetsnbextension 3.4.2
wincertstore 0.2
Any thoughts on how to further identify what went wrong, what package might be missing or how to fix the issue, and/or alternate ways to save a googlemaps output?
Fiddling with it and comparing from one environment to the other, I found that my virtual environment had ipywidgets 7.4.2 while the base environment had ipywidgets 7.2.1. Downgrading versions fixed the issue I was having.

Jupyter does not create a new notebook under the current directory

I updated my Jupyter Notebook and it does not create a new notebook under the current directory as it used to. Instead, it always creates a new notebook under the start-up directory.This happens on my Mac and Windows computers. How can I fix this?
1) Creating a new notebook under project1
2) A new notebook was successfully created
3) However, this notebook was created under the jupyter start-up directory rather than project1
Jupyter did not behave like this before. Is this a bug or intended behavior?
Here are my Jupyter related package versions.
# Name Version Build Channel
jupyter 1.0.0 py36h598a6cc_0
jupyter_client 5.2.2 py36_0
jupyter_console 5.2.0 py36hccf5b1c_1
jupyter_contrib_core 0.3.3 py36_1 conda-forge
jupyter_contrib_nbextensions 0.3.3 py36_0 conda-forge
jupyter_core 4.4.0 py36h79cf704_0
jupyter_highlight_selected_word 0.1.0 py36_0 conda-forge
jupyter_latex_envs 1.4.0 py36_1 conda-forge
jupyter_nbextensions_configurator 0.4.0 py36_0 conda-forge
jupyterlab 0.27.0 py36hd3092eb_2
jupyterlab_launcher 0.4.0 py36h93e02e9_0
notebook 5.3.1 py36_1
Per ilyas's advice, updated my notebook to 5.4.0 and this issue was resolved.
Solution: Run
conda update conda
And then:
conda update --all
in your anaconda prompt. There are recent updates to jupyter that will fix this issue.

Categories

Resources