I can't use matplotlib from a script [duplicate] - python

This question already has answers here:
No module named 'matplotlib.pyplot'; 'matplotlib' is not a package
(5 answers)
Why I receive ModuleNotFoundError, while it is installed and on the sys.path?
(1 answer)
Closed 1 year ago.
Can somebody help me with this problem?
Python recognises matplotlib from the command line:
import matplotlib
matplotlib.__version__
'3.4.3'
But not from a script
This is my script (to keep it simple):
import matplotlib.pylab as plt
import numpy as np
These are the errors:
Traceback (most recent call last):
File "C:/Program Files/Python39/Scripts/matplotlib.py", line 1, in <module>
import matplotlib.pylab as plt
File "C:\Program Files/Python39/Scripts\matplotlib.py", line 1, in <module>
import matplotlib.pylab as plt
ModuleNotFoundError: No module named 'matplotlib.pylab';
'matplotlib' is not a package

Try Reinstalling the package or downgrading it to a more stable version like 2.02

Related

Python "Import missingno" results in "ImportError: attempted relative import with no known parent package"

I am using jupyter nb running python 3.9.1 using pip to install modules etc.
All imports work smoothly except missingno.
All the modules being imported are located in the same location Python39\lib\site-packages but missingno results in Import Error.
The missingno module had been imported and it has run smoothly before but after a kernel restart, the Import Error cropped up.
ImportError Traceback (most recent call last)
<ipython-input-16-fad26a6fb4fe> in <module>
6 #Visualization
7 import matplotlib.pyplot as plt
----> 8 import missingno
9 import seaborn as sns
10 plt.style.use('seaborn-whitegrid')
~\AppData\Local\Programs\Python\Python39\Lib\site-packages\missingno\missingno.py in <module>
6 import seaborn as sns
7 import pandas as pd
----> 8 from .utils import nullity_filter, nullity_sort
9 import warnings
10
ImportError: attempted relative import with no known parent package
How to fix it?
I have tried to delete the missingno files and reinstalling it using pip install missingno but nothing works.
Running Python in shell and importing missingno, I still get the same error. There is nothing fancy in my code, a simple, generic import which showed no signs of error before kernel restart.
>>> import missingno
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\OK\AppData\Local\Programs\Python\Python39\Lib\site-packages\missingno\missingno.py", line 8, in <module>
from .utils import nullity_filter, nullity_sort
ImportError: attempted relative import with no known parent package
Try opening the missingno.py file in site-packages.
Change
from .utils import nullity_filter, nullity_sort
to
from utils import nullity_filter, nullity_sort

I cannot import pylab - even though matplotlib, numpy and scipy are already installed (Python)

I am sorry for asking this question again, but I could not find any answer to my problem that helped me. I don't have much experience with python. I use python version 3.6.8 on Windows and I have already installed matplotlib, numpy and scipy. The 'pylab.py' file is also contained in the matplotlib folder. Edit: Using matplotlib.pyplot also doesn't work.
Edit: After some more trials I got the error that the module 'six.names" could not be found. The six package has been installed.
import pylab
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import pylab
ModuleNotFoundError: No module named 'pylab'
import matplotlib.pyplot
Traceback (most recent call last):
File "<pyshell#21>", line 1, in <module>
import matplotlib.pyplot
File "C:\...\Python36-32\lib\matplotlib\pyplot.py", line 30, in <module>
from cycler import cycler
File "C:\...\Python36-32\lib\cycler\cycler.py", line 48, in <module>
from six.moves import zip, reduce
ModuleNotFoundError: No module named 'six.moves'
Per https://matplotlib.org/faq/usage_faq.html#matplotlib-pyplot-and-pylab-how-are-they-related, pylab is not recommended; you should use pyplot instead.
The correct way to import either is
import matplotlib.pyplot # use this
import matplotlib.pylab # only if you cannot avoid it
(pyplot and pylab are not standalone modules, but submodules of matplotlib.)

import matplotlib.pyplot as plt in python3.7

when i run python3.7 in pycharm(matplotlib error)
import matplotlib.pyplot as plt
then i get
Traceback (most recent call last):
File "D:/PyCharm 2017.2.3/Workplace/SimpleGA-master/ga.py", line 3, in
<module>
import matplotlib.pyplot as plt
ModuleNotFoundError: No module named 'matplotlib'
and i tried to find matplotlib in https://pypi.python.org/pypi/matplotlib,but not find python3.7 package
Make sure you have installed the matplotlib modules.
+ pip install matplotlib
Then try again.
Thanks!

ImportError: cannot import name 'show_config' [duplicate]

This question already has answers here:
Python csv import fails
(2 answers)
Closed 1 year ago.
i don't know why i get this error even i installed correctly the libraries:
Traceback (most recent call last):
File "D:/Doc/Diagnostic-Technology/Browser.py", line 4, in <module>
import scipy.stats as stat
File "D:\Doc\Diagnostic-Technology\scipy\__init__.py", line 61, in <module>
from numpy import show_config as show_numpy_config
ImportError: cannot import name 'show_config'
packages wich i imported :
import pandas as pd
import numpy as np
import scipy.stats as stat
import math as math
help please!
I have the same problem and solved it this way
find any file named as "numpy.py" in your script directory and change it into another name.
delete any file named as "numpy.pyc" or any other file generated while compiling your code.

from scipy.integrate import odeint returns error [duplicate]

This question already has answers here:
Installing scipy in Python 3.5 on 32-bit Windows 7 Machine
(4 answers)
Closed 7 years ago.
I ran this command from scipy.integrate import odeint but I get the errors below. I am new to python. I have installed scipy and numpy but I don't have any idea what more is missing to run this. Please help.
Traceback (most recent call last):
File "<pyshell#8>", line 1, in <module>
from scipy.integrate import odeint
File "C:\Python34\lib\site-packages\scipy\integrate\__init__.py", line 51, in <module>
from .quadrature import *
File "C:\Python34\lib\site-packages\scipy\integrate\quadrature.py", line 6, in <module>
from scipy.special.orthogonal import p_roots
File "C:\Python34\lib\site-packages\scipy\special\__init__.py", line 601, in <module>
from ._ufuncs import *
ImportError: DLL load failed: The specified module could not be found.
you need to install the Numpy from the following link which has Numpy+MKL build linked to the IntelĀ® Math Kernel Library.
link: http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy

Categories

Resources