I would like to run python in a Quarto document. I followed the docs about installing and using python in Quarto, but the error stays. Here is some reproducible code:
---
title: "matplotlib demo"
format:
html:
code-fold: true
jupyter: python3
---
For a demonstration of a line plot on a polar axis, see #fig-polar.
```{python}
#| label: fig-polar
#| fig-cap: "A line plot on a polar axis"
import numpy as np
import matplotlib.pyplot as plt
r = np.arange(0, 2, 0.01)
theta = 2 * np.pi * r
fig, ax = plt.subplots(
subplot_kw = {'projection': 'polar'}
)
ax.plot(theta, r)
ax.set_rticks([0.5, 1, 1.5, 2])
ax.grid(True)
plt.show()
```
Error output:
Starting python3 kernel...Traceback (most recent call last):
File "/Applications/RStudio.app/Contents/Resources/app/quarto/share/jupyter/jupyter.py", line 21, in <module>
from notebook import notebook_execute, RestartKernel
File "/Applications/RStudio.app/Contents/Resources/app/quarto/share/jupyter/notebook.py", line 16, in <module>
import nbformat
ModuleNotFoundError: No module named 'nbformat'
I also checked with Quarto if Jupyter is installed in the terminal like this:
quarto check jupyter
Output:
[✓] Checking Python 3 installation....OK
Version: 3.7.11 (Conda)
Path: /Users/quinten/Library/r-miniconda/envs/r-reticulate/bin/python
Jupyter: 4.12.0
Kernels: julia-1.8, python3
[✓] Checking Jupyter engine render....OK
Which seems to be OK. So I was wondering if anyone knows how to fix this error?
Edit: output conda info --envs
Output of conda info:
# conda environments:
#
/Users/quinten/.julia/conda/3
/Users/quinten/Library/r-miniconda
/Users/quinten/Library/r-miniconda/envs/r-reticulate
/Users/quinten/Library/rminiconda/general
/Users/quinten/opt/anaconda3
base * /Users/quinten/opt/miniconda3
Edit: conda install Jupyter
The condo install Jupyter was installed (thanks to #shafee), now when I check with quarto if Jupyter exists, I get the following error:
quarto check jupyter
[✓] Checking Python 3 installation....OK
Version: 3.7.11 (Conda)
Path: /Users/quinten/Library/r-miniconda/envs/r-reticulate/bin/python
Jupyter: 4.11.1
Kernels: julia-1.8, python3
(/) Checking Jupyter engine render....Unable to load extension: pydevd_plugins.extensions.types.pydevd_plugin_pandas_types
Unable to load extension: pydevd_plugins.extensions.types.pydevd_plugin_pandas_types
[✓] Checking Jupyter engine render....OK
This error usually occurs when jupyter is not installed in the environment that is being used and from the output of quarto checks, its seems that Quarto is referring to the r-reticulate environment and possibly jupyter is not installed in that environment. If thats the case, you simply need to install jupyter in the r-reticulate environment.
Option 01
One option could be to activate the r-reticulate environment and then install the jupyter there.
So first, activate the environment.
conda activate r-reticulate
and then install jupyter there,
conda install jupyter
Option 02
If conda could not find that environment, use the specific path to that environment to install jupyter in that environment,
/Users/quinten/Library/r-miniconda/envs/r-reticulate/bin/python -m pip install jupyter
Option 03
If the r-reticulate environment is created by the {reticulate} R package, then an easy option could be using reticulate::conda_install to install a package.
reticulate::conda_install(envname = "r-reticulate", "jupyter")
Also, if you are wondering, why jupyter command runs even though it did not exist in the r-reticulate environment, its because you probably installed jupyter in the base environment and quarto is detecting that jupyter installation while checking.
Related
I'm executing this code on Kaلgle, and install autokeras library on it,
!pip install autokeras
import matplotlib.pyplot as plt
import pandas as pd
import datetime
%matplotlib inline
#Control the default size of figures in this Jupyter notebook
%pylab inline
pylab.rcParams['figure.figsize'] = (14, 9) # Change the size of plots
#cib = pd.read_csv("../input/balmhils1/balmhils1015.csv")
# load data from csv
cib_f = pd.read_csv("../input/jkse1234/JKSE.csv") # load data from csv
f, ax = plt.subplots(figsize=(11,8))
plt.xlabel("Number of trading day")
plt.ylabel("Close price")
but I got this error.
No module named 'keras_tuner'
Upgrade the keras_tuner
!pip install keras-tuner --upgrade
I had a similar issue using PyCharm. When I installed the keras-tuner package in the Anaconda 3 prompt, I got the message that everything is already installed. The problem was, that the keras-tuner was installed in my base environment and not in the environment (virtual) which I use in PyCharm. You simply need to do the following.
check out your environments in the anaconda prompt using: conda env list
you will probably see the * on the base environment
now change to your working environment for example conda activate tf_cpu -> tf_cpu needs to be changed by your envs name (see on your list)
install your package such as pip install keras_tuner
Recently my jupyter notebook stopped launching. When I try the command jupyter notebook from anaconda prompt but it gives error
Traceback (most recent call last):
File "C:\Users\Dell\anaconda3\Scripts\jupyter-notebook-script.py", line 6, in
from notebook.notebookapp import main
File "C:\Users\Dell\anaconda3\lib\site-packages\notebook\notebookapp.py", line 51, in
from zmq.eventloop import ioloop
File "C:\Users\Dell\anaconda3\lib\site-packages\zmq_init_.py", line 50, in
from zmq import backend
File "C:\Users\Dell\anaconda3\lib\site-packages\zmq\backend_init_.py", line 40, in
reraise(*exc_info)
File "C:\Users\Dell\anaconda3\lib\site-packages\zmq\utils\sixcerpt.py", line 34, in reraise
raise value
File "C:\Users\Dell\anaconda3\lib\site-packages\zmq\backend_init_.py", line 27, in
ns = select_backend(first)
File "C:\Users\Dell\anaconda3\lib\site-packages\zmq\backend\select.py", line 28, in select_backend
mod = import(name, fromlist=public_api)
File "C:\Users\Dell\anaconda3\lib\site-packages\zmq\backend\cython_init.py", line 6, in
from . import (constants, error, message, context,
ImportError: DLL load failed while importing error: The specified module could not be found.
I even tried reinstalling anaconda and upgraded to python 3.8.3 on windows 10 but still get the same error. When I tried to check jupyter notebook's version it said that ipykernel and some other things were not installed. jupyter --version gives me this:
jupyter core : 4.6.3
jupyter-notebook : 6.1.1
qtconsole : 4.7.6
ipython : 7.18.1
ipykernel : not installed
jupyter client : not installed
jupyter lab : not installed
nbconvert : 5.6.1
But installing ipykernel with conda install ipykernel says
All requested packages already installed.
I also tried ipython kernel install --name <env_name> --user but this gives another dll error.
Reading some other problems in stackoverflow I went and checked my enviroment variables.
Is there a problem with this environment variable. Please help.
Screenshot of the anaconda prompt with error.
Edit: The anaconda navigator does not launch either. anaconda-navigator on the anaconda prompt gives another error:
I also tried:
conda install qt --force
conda install pyqt --force
But that did'nt help. Does previously installed anaconda cause such error?
Just for other people having similar issue.
In my case, when I run jupyter notebook on command line, I got the same error as #Anav Katwal . However if I run jupyter notebook on Anaconda Prompt, then the error is gone.
If you truly want to execute jupyter notebook on cmd, then you could add the following paths to your system environment variable:
C:\Users\USERNAME\anaconda3\Library\bin
C:\Users\USERNAME\anaconda3\Scripts
C:\Users\USERNAME\anaconda3\condabin
What worked for me was reinstalling one of the modules jupyter calls and reinstalling the newer version manually, via another SO answer:
pip uninstall pyzmq
pip install pyzmq==20
Import error while trying to run jupyter notebook
I found what I did wrong (silly me). Microsoft visual C++ 2015-2019 was somehow removed when I tried to install openCV manually. Didn't think that such an install would make such big impact, have to keep that in mind now but installing the latest solved all the problems.
P.S.: This solution might not work for someone else with similar problem. But its worth taking a note.
Use this code, instead of conda
pip install jupyter
I am new to jupyter notebooks and virtualenvironment. I think that I am incurring in a really trivial problem.
I am trying to import matplotlib in a Jupyter notebook and the import works fine. However, it uses the wrong version of the library (installed also systemwide) and I don't know how to force it to use the one in the virtualenvironment.
In my virtualenvironment I want to use a most recent version of matplotlib and therefore I did
pip install --upgrade matplotlib in my virtualenvironment. The upgrade worked fine.
Now if I do pip show matplotlib in my virtualenvironment I get:
Name: matplotlib
Version: 2.2.5
...
Instead, if I do the same command in my home, I get:
Name: matplotlib
Version: 1.5.1
However, if in my jupyter notebook I do
import matplotlib
print ("matplotlib version:",matplotlib.__version__)
I get:
('matplotlib version:', '1.5.1')
Could you please help me understanding what I do wrong?
I found a solution to my problem. First of all, I read this long post that I suggest to everyone using conda or pip.
Then I understood that the shell environment is determined when the Jupyter notebook is launched, while the Python executable is determined by the kernel, and the two do not necessarily match.
I understood this by putting at the beginning of my jupyter notebook the following:
paths = !type -a python
for path in set(paths):
path = path.split()[-1]
print(path)
!{path} -c "import sys; print(sys.path)"
print()
!type python
import sys
sys.executable
!pip show matplotlib
It showed me that I was still using an older version of the matplotlib library.
Therefore I added
!{sys.executable} -m pip install --upgrade matplotlib
Restarted my jupyter kernel and this solved my problem.
I hope this solution will help someone else in the same situation.
I tried to execute this line in my application in Jupyter notebook.
from tensorflow.contrib.learn.python.learn.datasets.mnist import read_data_sets
I get the following error:
.conda/envs/py27/lib/python2.7/site-packages/tensorflow/contrib/__init__.py in <module>()
23
24 # Add projects here, they will show up under tf.contrib.
---> 25 from tensorflow.contrib import batching
26 from tensorflow.contrib import bayesflow
27 from tensorflow.contrib import cloud
ImportError: cannot import name batching
I do not get this error if I ran it like this:
python -c "from tensorflow.examples.tutorials.mnist import input_data"
Can someone tell me what's causing the error in Jupyter Notebook
I have run into similar issue with importing libraries from jupyter notebook, and the problem has always been that I forgot to install jupyter in my new conda environment, but jupyter is installed in the root environment.
Based on the error given, make sure you have jupyter installed within the py27 conda environment. If it not installed, it will default to open the one in the root environment.
So in the terminal:
source activate py27 # activate py27 if on windows
conda install jupyter
I'm just now trying to integrate to Jupyter and I have been using Anaconda for a long while now.
When trying to import the matplotlib in the IPython Notebook,
import matplotlib.pyplot as plt
%matplotlib inline
I get this error:
ImportError Traceback (most recent call last)
<ipython-input-2-385145dcc870> in <module>()
----> 1 import matplotlib.pyplot as plt
2 get_ipython().magic(u'matplotlib inline')
ImportError: No module named matplotlib.pyplot
I faced the same problem. Then I used folllowing command to install matplotlib library to my virtual environment.
pip install matplotlib
Then I could import matplotlib to jupyter notebook.
I think you should install matplotlib library if using conda then in terminal type:
# create a new environment with the required packages
conda create -n "matplotlib_build" python=3.5 numpy python-dateutil pyparsing pytz tornado cycler tk libpng zlib freetype
activate matplotlib_build
# if you want a qt backend, you also have to install pyqt (be aware that pyqt doesn't mix well if
# you have created the environment with conda-forge already activated...)
conda install pyqt
# this package is only available in the conda-forge channel
conda install -c conda-forge msinttypes
# copy the libs which have "wrong" names
set LIBRARY_LIB=%CONDA_PREFIX%\Library\lib
mkdir lib || cmd /c "exit /b 0"
copy %LIBRARY_LIB%\zlibstatic.lib lib\z.lib
copy %LIBRARY_LIB%\libpng_static.lib lib\png.lib
# Make the header files and the rest of the static libs available during the build
# CONDA_DEFAULT_ENV is a env variable which is set to the currently active environment path
set MPLBASEDIRLIST=%CONDA_PREFIX%\Library\;.
# build the wheel
python setup.py bdist_wheel
This code was taken from https://matplotlib.org/users/installing.html#conda-packages. Hope this helps.
Thanks
Michael