Jupyter gets Import Error when importing matplotlib - python

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

Related

Anaconda-Error: cannot import name Transformer from pyproj

I try to install Transformer from pyproj and get the message "cannot import name".
I installed pyproy using Anaconda Navigator. There it tells me I have version 1.9.6. (newest update). I found a thread about same issue but it didn't help me (cannot import name Transformer from pyproj).
I checked pyproj-Documentation and installed via terminal conda install -c conda-forge proj-datumgrid-europe proj-datumgrid-north-america proj-datumgrid-oceania proj-datumgrid-world.
Not sure if that's the right thing to do. I'm a noob .-. help is appreciated.
ImportError Traceback (most recent call last)
/var/folders/jy/1f2tlvb965g30zhw9q3cvdw07r5rb_/T/ipykernel_49825/1776791710.py in <module>
4 from shapely.geometry import Point, LineString
5 import pyproj as pi
----> 6 from pyproj import Transformer
ImportError: cannot import name 'Transformer' from 'pyproj' (/Users/vob/opt/anaconda3/envs/geopandas/lib/python3.8/site-packages/pyproj/__init__.py)
The latest version of pyproj is 3.3 at the moment. To update, recommend looking at pyproj installation instructions: https://pyproj4.github.io/pyproj/stable/installation.html
Here is a snippet:
conda config --prepend channels conda-forge
conda config --set channel_priority strict
conda create -n pyproj_env pyproj
conda activate pyproj_env

fbprophet installation in conda env failed

I want to install the package fbprophet (it may now also be known as prophet). I tried importing both like so (not all at once):
import fbprophet
import prophet
from fbprophet import Prophet
from prophet import Prophet
Error I receive is as follows:
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_5908/2493871459.py in <module>
----> 1 from prophet import Prophet
ModuleNotFoundError: No module named 'prophet'
I have already gone through all the other questions asking the same problem, yet those solutions didn't work for me. I also tried changing python version to 3.7 when installing it in a new env for testing purposes.
installing prophet in jupyter nb
No module named 'fbprophet'?
Prophet / fbprophet package in Python
some code solution for installation
My advice is to create a fresh conda environment for prophet. You will avoid conflicts and let conda retrieve without any other constraints the required dependencies. Here is how to do it as per the doc.
# create a new env called prophet
# with no other spec than prop
conda create -c conda-forge -n prophet prophet
Use the env.
# activate the env
conda activate prophet
# test
python -c "import prophet; print(prophet.__version__)"
# Importing plotly failed. Interactive plots will not work.
# 1.0
Register it as a Jupyter Kernel as per the doc
# install ipykernl
conda install ipykernel
# register it
python -m ipykernel install --user --name prophet --display-name "Prophet"

No module named 'keras_tuner'

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

Cannot import matplotlib on Spyder after conda installation

I installed matplotlib on Anaconda Prompt with conda install -c conda-forge matplotlib.
However, when I run import matplotlib.pyplot as plt on Spyder 4.1.5 (with Python 3.7), I got an error message:
ModuleNotFoundError: No module named 'matplotlib.pyplot'
Before getting this error message, I installed matplotlib_scalebar with conda install -c conda-forge matplotlib-scalebar. I had no issue importing matplotlib.pyplot before this, and I suspect that installing this might have caused the problem.
Under C:\ProgramData\Anaconda3\Lib\site-packages, I have folders with the following names:
matplotlib
matplotlib-3.0.2.dist-info
matplotlib-3.3.2.dist-info
I'm not sure if having different folders (3.0.2 and 3.3.2) is an issue here.
How can I fix this No module issue?

Python - Can't import Seaborn

I'm running iPhyton Notebooks and I'm trying to import the Seaborn package. When I try to import it from the Terminal, it loads up fine, but when I import it through iPython Notebooks, it give me the following error.
I have even tried to re-install Seaborn using both Conda and Pip inside iPython notebooks and still it wont work.
Any idea why?
Thanks.
ImportError Traceback (most recent call last)
<ipython-input-1-417274a1ae6c> in <module>()
1 get_ipython().system(u'conda install seaborn')
2 get_ipython().system(u'pip install seaborn')
----> 3 import seaborn as sb
4
ImportError: No module named seaborn
Try this
import sys
print sys.path
sys.path.append('<path to package in your syste>')
import seaborn
In my Ubuntu 14.4LTS the packages get installed in the following folder
/usr/local/lib/python2.7/dist-packages
So I simply add the package path at run time
Donit install Ipython on all your system. Install it only in the environments you want it. Otherwise Ipython will look for modules in the default path instead of the environment's path.
This is probably where your ipython is looking:
/home/user/anaconda2/lib/python2.7/
It should be looking for modules here:
/home/user/anaconda2/envs/name-of-env/lib/python3.4/
To check the path you type:
import sys
sys.path
Try entering the following in your terminal:
conda install seaborn
It will install seaborn and make it available for you to import into your notebook
Open anaconda prompt and Type
pip install seaborn

Categories