Once I opened a notebook file with Jupyter (it asks me to convert the file) I never can open it in the standard IPython notebook anymore. I get the following error:
Error loading notebook
Bad Request
2014-12-21 04:13:03.203 [NotebookApp] WARNING | Unreadable Notebook: /FunIT experiment.ipynb global name 'NBFormatError' is not defined
WARNING:tornado.access:400 GET /api/notebooks/FunIT%20experiment.ipynb?_=1419153182928 (::1) 3.11ms referer=http://localhost:8888/notebooks/FunIT%20experiment.ipynb
An example of such corrupted files is this one:
https://www.dropbox.com/s/7io99wpoivxmc8f/FunIT%20experiment.ipynb?dl=0
How can I revert this process? I need to open these files with the standard IPython notebook (v2.2.0).
This problem has to do with incompatibility of the notebook and your IPython version. In my current version of IPython:
ipython --version
2.3.1
When I try to open the file (FunIT\ experiment.ipynb):
ipython notebook FunIT\ experiment.ipynb
I get the following error message
Error loading notebook
Unreadable Notebook: FunIT experiment.ipynb Unsupported nbformat
version 4
The error message indicates that the notebook format is not supported. Let's install the development version, https://github.com/ipython/ipython. I used virtual Environment, http://docs.python-guide.org/en/latest/dev/virtualenvs/, but it's not necessary.
Install virtual environment
pip install virtualenv
mkdir test
cd test
virtualenv venv
source venv/bin/activate
Ipython Notebook development installation
git clone --recursive https://github.com/ipython/ipython.git
cd ipython
pip install -e ".[notebook]" --user
Now I have the current development version.
ipython --version
3.0.0-dev
And I can open the file with ipython notebook
ipython notebook FunIT\ experiment.ipynb
Here is a snippet of the code:
import pandas as pd
import numpy as np
from pandas.tools.pivot import pivot_table
#from sklearn.metrics import roc_auc_score
import matplotlib.pyplot as plt
%pylab inline
#from sklearn.neighbors.kde import KernelDensity
import seaborn as sns
import scipy.stats as st
sns.set()
Upgrading IPython fixed it for me:
pip install ipython --upgrade
This works for me perfectly:
pip install jupyter
Related
Starting from a new anaconda environment, it looks like this (summarized, not a full paste):
[myenv]$ python
Python 3.8.8 ...
>> import matplotlib.pyplot as plt
>>
[myenv]$ conda install tensorflow-gpu
...
[myenv]$ python
>> import tensorflow
>> tensorflow.__version__
'2.4.1'
>> import matplotlib.pyplot as plt
ModuleNotFoundError: No module named 'matplotlib'
>>
[myenv]$ conda install matplotlib
...
[myenv]% python
>> import tensorflow
>> import matplotlib.pyplot as plt
<tons of traceback>
RunTimeError: the sip module implements API v12.0 to v12.4 but the PyQt5.core module requires API v12.5
How can I have tensorflow and matplotlib at the same time?
Do you have the complete traceback? Based on the Error you posted, it seems like its a dependency issue on the sip module. I'll recommend using you own virtualenv instead of anacondas.
FOR CREATING YOUR OWN VIRTUALENV:
open terminal
go to the directory you want your project to be
pip install virtualenv
virtualenv venv
source venv/bin/activate (for linux or mac)
pip install tensorflow
pip install matplotlib
pip install <whatever library you want>
I'm facing weird issue in my Jupyter-notebook.
In my first cell:
import sys
!{sys.executable} -m pip install numpy
!{sys.executable} -m pip install Pillow
In the second cell:
import numpy as np
from PIL import Image
But it says : ModuleNotFoundError: No module named 'numpy'
I have used this command to install Jupyter notebook :
sudo apt install python3-notebook jupyter jupyter-core python-ipykernel
Additional information :
pip --version
pip 20.2.2 from /home/maifee/.local/lib/python3.7/site-packages/pip (python 3.7)
python --version
Python 3.7.5
Thanks to #suuuehgi.
When Jupyter Notebook isn't opened as root:
import sys
!{sys.executable} -m pip install --user numpy
I've had occasional weird install issues with Jupyter Notebooks as well when I'm running a particular virtual environment. Generally, installing with pip directly in the notebook in this form:
!pip install numpy
fixes it. Let me know how it goes.
Restarting the kernal from the Jupyter Notebook solved this issue for me
I had a similar issue. Turns out I renamed an upstream path. And I hadn't deactivated my conda env first. When I deactivated the env.
conda deactivate
Then when I activated it again, everything was as it should have been.
conda activate sample
Now I am seeing other issues with jupyter themes... but its not impacting my numpy code. So, at least I fixed the "ModuleNotFoundError: No module named 'numpy'" error
I have the same problem. My numpy is installed, I am using the same folder as usual.
If I try 'conda deactivate', I get the message:
ValueError: The python kernel does not appear to be a conda environment. Please use %pip install instead.
I added a print of the 'pip install numpy' result and the 'Module not found error' after
Here is a solution which worked for me:
lib_path="c:\\users\\user\\python_39\\lib\\site-packages\\"
MODULE_NAME = "module_to_import"
MODULE_PATH = lib_path+MODULE_NAME+"\\__init__.py"
import importlib
import sys
spec = importlib.util.spec_from_file_location(MODULE_NAME, MODULE_PATH)
module = importlib.util.module_from_spec(spec)
sys.modules[spec.name] = module
spec.loader.exec_module(module)
import module_to_import
I have technically already installed pandas-profiling using
pip install pandas-profiling
But when I try to import it, I get the following error:
import numpy as np
import pandas as pd
import pandas_profiling
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-1-e1a23f2a6f04> in <module>()
1 import numpy as np
2 import pandas as pd
3 import pandas_profiling
ModuleNotFoundError: No module named 'pandas_profiling'
First Error Image
So I tried installing it in Jupyter Notebook and got the following error as well:
import sys
!{sys.executable} -m pip install pandas-profiling
Collecting pandas-profiling
Could not find a version that satisfies the requirement pandas-profiling
(from versions: )
No matching distribution found for pandas-profiling
Second Error Image
I am also unable to install it using conda for both as I am unable to establish a connection to conda.anaconda.org for some reason.
To others who are looking to resolve this issue try these alternate steps :
Run pip install pandas-profiling command in a separate cell in the jupyter notebook.
After this just restart the kernal and run again. This should definitely work. Worked for me.
Based on the comments I was able to figure out the issue. I had to install jupyter notebook outside of the Anaconda root env and open it from the terminal.
pip3 install jupyter notebook
Once I did that it imported properly.
Steps:
Download the ZIP
Open Anaconda Prompt and go to the directory and extract the files to a folder
cd
C:\Users\farah\Downloads\pandas-profiling-master\pandas-profiling-master
Then type python setup.py install
Now you can use:
import pandas_profiling as pp
df = pd.read_csv('1234.csv')
pp.ProfileReport(df)
Reference: Pandas profiling
!pip install pandas_profiling # Run this from Jupytor notebook Ignore the warnings if any
from pandas_profiling import ProfileReport #restart the kernel if throws error
ProfileReport(df)
Note: This worked for me on Windows 10
From Anaconda Prompt:
conda install -c conda-forge pandas-profiling
I am trying to export my dependencies to a requirements.txt or environment.yml file for pip or conda respectively - in order to host a Binder notebook.
How can I get only the dependencies that my notebook is using?
When I tried pip freeze or conda env export, I get all my installed packages, which leads to errors when building the Docker environment.
You might want to try watermark:
Install:
pip install watermark
Then, in your notebook:
# Load the extension
%load_ext watermark
# import your libraries
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
# Determine the dependency version
%watermark -p numpy,matplotlib,seaborn
The results will look like this:
numpy 1.14.3
matplotlib 2.2.2
seaborn 0.9.0
I am trying to install plotnine for a notebook I am using. I have done the following:
Created a conda environment using python 3.6, and adding plotnine
Launching jupyter lab with the above environment activated
In the notebook, I added the following line:
!conda install -c conda-forge --yes plotnine
However, my output makes no sense. First it says that all requested packages have been installed, and then it says it cannot find the module
!conda install -c conda-forge --yes plotnine
from plotnine import *
Solving environment: done
# All requested packages already installed.
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-386ef81e08ff> in <module>()
11 get_ipython().system('conda install -c conda-forge --yes plotnine')
12 ######
---> 13 from plotnine import * # python clone of ggplot2
14 matplotlib.rcParams['figure.figsize'] = [12, 8]
15 matplotlib.rcParams['lines.linewidth'] = 2
ImportError: No module named 'plotnine'
In case there is a known conflict, here is the entire import statement:
import gsc # proprietary module
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
import pandas as pd
from ipywidgets import interact, FloatSlider
from util_demo import *
# adding installation of plotnine, which is not included by default
# import sys
!conda install -c conda-forge --yes plotnine
######
from plotnine import * # python clone of ggplot2
matplotlib.rcParams['figure.figsize'] = [12, 8]
matplotlib.rcParams['lines.linewidth'] = 2
matplotlib.rcParams['xtick.labelsize'] = 24
matplotlib.rcParams['ytick.labelsize'] = 24
matplotlib.rcParams['legend.fontsize'] = 24
matplotlib.rcParams['axes.labelsize'] = 24
EDIT: I also checked sys.path within the jupyter notebook and get the following. I do not see anything about conda here. Should I update either PATH or PYTHONPATH?
['',
'/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python35.zip',
'/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5',
'/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/plat-darwin',
'/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/lib-dynload',
'/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages',
'/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/IPython/extensions',
'/Users/adamg/.ipython']
I had the same problem. It looks like for me, my notebook in Jupyter Lab was running the base kernel and not the kernel of the virtual environment. Type
import sys
sys.executable
into your notebook. For me, I got the result
'/anaconda3/bin/python'
instead of the desired
'/anaconda3/envs/myenv/bin/python'
I solved it by following the instructions in the iPython documentation. In summary, you need to install a new iPython kernel for your new environment. Run:
conda install -n myenv ipython
conda activate myenv
python -m ipykernel install --user --name myenv --display-name "Python (myenv)"
Then, to run Jupyter Lab in the new environment:
conda activate myenv
jupyter lab
And you should be able to select the kernel "Python (myenv)" when you open a new notebook (also in the top right of an existing notebook).
#try pip install first and rerun; the code line below should solve it:
pip install plotnine