I tried to upgrade matplotlib using pip install --upgrade matplotlib, then after upgrading an import error occurred: import matplotlib.pyplot as plt
ImportError: No module named artist
The whole error is:
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-18-eff513f636fd> in <module>()
----> 1 import matplotlib.pyplot as plt
C:\Users\TZ\AppData\Local\Continuum\Anaconda2\lib\site-packages\matplotlib\pyplot.py in <module>()
25
26 import matplotlib
---> 27 import matplotlib.colorbar
28 from matplotlib import style
29 from matplotlib import _pylab_helpers, interactive
C:\Users\TZ\AppData\Local\Continuum\Anaconda2\lib\site-packages\matplotlib\colorbar.py in <module>()
30
31 import matplotlib as mpl
---> 32 import matplotlib.artist as martist
33 import matplotlib.cbook as cbook
34 import matplotlib.collections as collections
ImportError: No module named artist
Anyone could solve this problem? (PS: I use python 2.7)
When I faced this issue (system: Windows - 64 bit OS) after upgrading Anaconda to the latest version (yesterday), I saw that Anaconda was trying to load the package from a location different from the default site-packages. Hence:
I fist checked the path my jupyter notebook was defaulting to as mentioned in one of the git hub posts (sorry I don't remember which one) using:
import sys
print(sys.path)
Since this path is not the default site-packages folder, I uninstalled Anaconda completely from add or remove programs - Anaconda (this will take some time to uninstall)
Anaconda will also remove jupyter notebook from your system. Hence, just reinstall jupyter notebook alone and open it from command line using
jupyter notebook
When you now try to import the matplotlib.pyplot in your notebook, it should not give any errors and you can use the same sys.path to check the path it is defaulting to. It should look something like:
Now, it is importing from the site-packages folder.
I am yet to investigate why and how this issue was caused but removing the upgraded Anaconda version helped me.
Run this command on your prompt:
pip install --user matplotlib --force
If it asks any packages related to it. Please install them also . It succeded for me. I hope for you also
Running this command worked for me:
conda install matplotlib --force
Related
I know that this is quite a common problem but when I installed this package I can't seem to get pyplot to be imported with matplotlib. My computer is currently running Pop os and I am using Pycharm as my IDE. When I run anything involved pyplot I get an the console prints out
Traceback (most recent call last):
File "/home/msm/PycharmProjects/Beginner/testing.py", line 1, in <module>
import matplotlib.pyplot as plt
ModuleNotFoundError: No module named 'matplotlib.pyplot'; 'matplotlib' is not a package
I have already tried the following
sudo apt-get install python3-matplotlib in the terminal
Searching for the package within Pycharm
Updating Python
Any help would be greatly appreciated.
try:
pip install matplotlib
if it isn't working try:
pip install --upgrade pip
and try it again
if it isn't working again try start terminal with administrator and add python -m to head of code
I am running a Python package called pymatgen in Jupyter. Jupyter and pymatgen are installed in a conda environment. I have manually installed ruamel using conda's python3, but the same error occurs. The strange thing is that the same code (in this case just a library load statement) gives no errors when run with ipython. Both Jupyter and ipython are running from the miniconda installation (I check with the command which). I noticed some postings on the web stating that ruamel has problems with conda due to the remapping of a "." to an underscore character, but none of the proposed solutions helped the above problem. I also don't understand why ipython is fine and Jupyter fails. Any suggestions?
from pymatgen.core.structure import Structure, Lattice
from pymatgen.core.periodic_table import Element
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-1-753da7cc5963> in <module>
----> 1 from pymatgen.core.structure import Structure, Lattice
2 from pymatgen.core.periodic_table import Element
~/.local/lib/python3.7/site-packages/pymatgen/__init__.py in <module>
13 import os
14 import warnings
---> 15 import ruamel.yaml as yaml
16 from fnmatch import fnmatch
17
ModuleNotFoundError: No module named 'ruamel'
Use the below command to install it:
pip install ruamel.yaml
I have been working with Anaconda and VS Code on my Windows and everything was fine until my computer once crashed. After that, I couldn't run my scripts that worked perfectly fine before.
For example, I now get the the error when running:
import os
import datetime
import IPython
import IPython.display
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import seaborn as sns
import tensorflow as tf
from tensorflow import keras
from pmdarima import auto_arima
from kerastuner import HyperModel, Objective
from kerastuner import BayesianOptimization
import keras.backend as K
from tensorflow.keras.layers import (
Dense,
Dropout,
LSTM,
GRU
)
mpl.rcParams['figure.figsize'] = (8, 6)
mpl.rcParams['axes.grid'] = False
C:\Users\myname\AppData\Local\Programs\Python\Python39\lib\site-packages\numpy\__init__.py:138: UserWarning: mkl-service package failed to import, therefore Intel(R) MKL initialization ensuring its correct out-of-the box operation under condition when Gnu OpenMP had already been loaded by Python process is not assured. Please install mkl-service package, see http://github.com/IntelPython/mkl-service
from . import _distributor_init
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
~\AppData\Local\Programs\Python\Python39\lib\site-packages\numpy\core\__init__.py in <module>
21 try:
---> 22 from . import multiarray
23 except ImportError as exc:
~\AppData\Local\Programs\Python\Python39\lib\site-packages\numpy\core\multiarray.py in <module>
11
---> 12 from . import overrides
13 from . import _multiarray_umath
~\AppData\Local\Programs\Python\Python39\lib\site-packages\numpy\core\overrides.py in <module>
6
----> 7 from numpy.core._multiarray_umath import (
8 add_docstring, implement_array_function, _get_implementing_args)
ModuleNotFoundError: No module named 'numpy.core._multiarray_umath'
During handling of the above exception, another exception occurred:
ImportError Traceback (most recent call last)
<ipython-input-1-aaaeab3b7b86> in <module>
4 import IPython
5 import IPython.display
----> 6 import matplotlib as mpl
7 import matplotlib.pyplot as plt
8 import numpy as np
~\AppData\Local\Programs\Python\Python39\lib\site-packages\matplotlib\__init__.py in <module>
105 # cbook must import matplotlib only within function
106 # definitions, so it is safe to import from it here.
--> 107 from . import cbook, rcsetup
108 from matplotlib.cbook import MatplotlibDeprecationWarning, sanitize_sequence
109 from matplotlib.cbook import mplDeprecation # deprecated
~\AppData\Local\Programs\Python\Python39\lib\site-packages\matplotlib\cbook\__init__.py in <module>
26 import weakref
27
---> 28 import numpy as np
29
30 import matplotlib
~\AppData\Local\Programs\Python\Python39\lib\site-packages\numpy\__init__.py in <module>
138 from . import _distributor_init
139
--> 140 from . import core
141 from .core import *
142 from . import compat
~\AppData\Local\Programs\Python\Python39\lib\site-packages\numpy\core\__init__.py in <module>
46 """ % (sys.version_info[0], sys.version_info[1], sys.executable,
47 __version__, exc)
---> 48 raise ImportError(msg)
49 finally:
50 for envkey in env_added:
ImportError:
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.
We have compiled some common reasons and troubleshooting tips at:
https://numpy.org/devdocs/user/troubleshooting-importerror.html
Please note and check the following:
* The Python version is: Python3.9 from "C:\Users\myname\AppData\Local\Programs\Python\Python39\python.exe"
* The NumPy version is: "1.19.2"
and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.
Original error was: No module named 'numpy.core._multiarray_umath'
I have been reading multiple posts but couldn't find a solution. I tried multiple things:
I have uninstalled and reinstalled anconda
I have added C:\Users\myname\AppData\Local\Programs\Python\Python39 to my system variable path
use pip uninstall numpy and after that conda install numpy
set my python path in VS code to either C:\Users\myname\AppData\Local\Programs\Python\Python39 (pythn verison 3.9.4) or C:\Users\myname\anaconda3 (Python version 3.8.5)
I went to the link mentioned in the error message but couldn't find a solution
tried to upgarde my numpy version (I have 1.20.2)
(pip install numpy --upgrade
Requirement already up-to-date: numpy in c:\users\myname\anaconda3\lib\site-packages (1.20.2))
Python Verison: 3.8.5 and 3.9.4 (tried both)
Numpy Version: 1.20.1
Matplotlib Version: 3.4.1
This
import os
print(sys.version)
print("PYTHONPATH:", os.environ.get('PYTHONPATH'))
print("PATH:", os.environ.get('PATH'))
leads to this output:
3.9.4 (tags/v3.9.4:1f2e308, Apr 6 2021, 13:40:21) [MSC v.1928 64 bit (AMD64)]
PYTHONPATH: c:\Users\myname\.vscode\extensions\ms-toolsai.jupyter-2021.5.745244803\pythonFiles;c:\Users\myname\.vscode\extensions\ms-toolsai.jupyter-2021.5.745244803\pythonFiles\lib\python
PATH: C:\Users\myname\anaconda3;C:\Users\myname\anaconda3\Library\mingw-w64\bin;C:\Users\myname\anaconda3\Library\usr\bin;C:\Users\myanme\anaconda3\Library\bin;C:\Users\myname\anaconda3\Scripts;C:\Users\myname\anaconda3\bin;C:\Users\myname\anaconda3\condabin;C:\Users\myname\anaconda3;C:\Users\myname\anaconda3\Library\mingw-w64\bin;C:\Users\myname\anaconda3\Library\usr\bin;C:\Users\myname\anaconda3\Library\bin;C:\Users\myname\anaconda3\Scripts;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Windows\System32\OpenSSH;C:\Program Files\MATLAB\R2020a\bin;C:\Users\myname\AppData\Local\Programs\Python\Python39;C:\Users\myname\AppData\Local\Microsoft\WindowsApps;C:\Users\myname\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\myname\AppData\Local\Programs\MiKTeX\miktex\bin\x64;C:\Users\myname\AppData\Local\Programs\Git\cmd;C:\Program Files (x86)\GitHub CLI;C:\Users\myname\AppData\Local\GitHubDesktop\bin
Thanks in advance for any help!
You have a lot going on here, including multiple installations of Python. It looks like you have both an Anaconda installation of Python, and a standard Python installation as well.
My first recommendation is to use virtual Python environments. These create isolated environments where you can install packages without worrying about messing up your base installation. There are a handful of ways to do this, Anaconda comes with Conda, and Python comes with venv. Both work well. I prefer Conda.
Step 1 - one or more of the packages in your standard Python installation are corrupted or incompatible; I would recommend uninstalling completely.
-- Windows Key > Settings (Gear icon) > Apps > Click on Python > Uninstall
Step 2 - assuming your Anaconda installation is not also corrupted, we can use Conda to create a new environment.
-- Windows Key > "Anaconda Prompt" > this opens a terminal with the base Anaconda environment.
conda create -n myenv python tensorflow ipython matplotlib pandas seaborn numpy -y
Step 3 - activate the environment to use it and install PyPi packages.
conda activate myenv
pip install pmdarima
Fells like magic, but after applying the steps mentioned by #James, restarting my laptop, disabling and reenabling all extensions in VS Code as well as setting the environment to myenv in Anaconda itself before launching VS Code, it finally works now. Don't know what exactly made the difference though. Thanks again #James for the help!
I'm trying to use the seaborn module in jupyter notebook,I alredy installed all the dependecies and the seaborn too,but when I try to run,it's said that it does not have a module seaborn installed
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-1-ed806232820c> in <module>
1 import pandas as pd
2 import matplotlib.pyplot as plt
----> 3 import seaborn as sns
ModuleNotFoundError: No module named 'seaborn'
Try restarting notebook first.
Make sure that seaborn is installed by same python interpreter used in the notebook.
Easiest way to be certain of this is to run
!pip install --user seaborn in the active notebook (! allows you to run shell command from your notebook)
Additional info for detecting the cause of the problem
You can check which interpreter is used by the notebook by running:
import sys
print(sys.executable)
I assume pip you used initially is not used by python you used to run the notebook (multiple python installations of the system or conda).
To specify which python is used for pip install you can run
<python-path> -m pip install seaborn where <python-path> is output of sys.executable.
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