I have a Python program that has the following import command:
import matplotlib.pyplot as plt
and on line:
ax.imshow(worldmap, cmap=plt.cm.cmapname)
throws the following error:
<module>
ax.imshow(worldmap, cmap=plt.cm.cmapname)
AttributeError: module 'matplotlib.cm' has no attribute 'cmapname'
The matplotlib library was installed with pip install matplotlib.
Strangely, this same program runs on another person's PC with no problem, and he has never seen this error before. Would anyone know what is causing this error and how to fix it?
I'm running Python 3.9.1. I'm wondering if we might be using different versions of matplotlib and whether this might be an issue.
Ali Irani had the right answer. I was using Python 3.9.5 with matplotlib 3.4.2, and my friend was using Python 3.7.1 with matplotlib 3.0.3. I installed what my friend was using, and his code worked. By the way: I first tried installing matplotlib with Python 3.9.5, and it wouldn't install. It seems that successive matplotlib versions are not upwardly compatible. Really, you would expect that whatever worked with older versions should also work with newer versions, but this evidently is not the case.
Related
I'm trying to run a Python program in VSCode and it always stops in the first line
from sklearn.gaussian_process.kernels import WhiteKernel, RationalQuadratic, RBF, Matern, ExpSineSquared
The error it gives me is pretty big, I'll paste it at the end.
However, when when I open python in my conda terminal, I can import with no issues at all. Since I'm using the conda interpreter in VSCode, I don't understand what the issue is.
My Python version is 3.7.6, numpy 1.19.1, scipy 1.5.2, sklearn 0.23.2 and am working with Windows 10. I have already tried what the webpage mentioned suggested. And on the bottom left of VSCode it says that the interpreter is Python 3.7.6 64-bit ('base':conda).
Just tried, and I can't import numpy either, but can in conda with no problems. The python versions are the same. EDIT: The error message here asks me to be sure that the Numpy version is 1.18.1, instead of 1.19.1.
Exception has occurred: 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.7 from "C:\Users\jdion\anaconda3\python.exe"
The NumPy version is: "1.19.1"
and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.
Original error was: DLL load failed: The specified module could not be found.
File "C:\Users\jdion\OneDrive\Ambiente de Trabalho\Tese\Code\The Sea Exploration Problem _aux.py", line 13, in
from sklearn.gaussian_process.kernels import WhiteKernel, RationalQuadratic, RBF, Matern, ExpSineSquared
I uninstalled both conda and all my Python versions and when I reinstalled Python 3.7.9 and selected it as the interpreter in VSCode there were no more issues. I think the problem was having too many Python versions, anaconda, pip, and I was probably installing and removing things in the wrong places.
I've tried several fixes for this suggested in other threads, but no luck.
I'm new to Python. I had 3.8.5 installed and wrote a few simple scripts that worked using PyCharm and the numpy and sympy modules. Today I opened PyCharm and tried to write a simple script using numpy, but I got an error saying the numpy module did not exist. I also got this error when trying to run the older scripts. I checked in cmd with pip3, and got the result that it was already satisfied. I uninstalled Python, numpy, and PyCharm, reinstalled all and I'm having the same problem. This problem seemed to crop up on its own - I don't recall making any changes that would've caused this.
Can anyone give me other options?
One of the most common issues with Python is having multiple versions installed and losing track of which one you are using and/or which one you're installing to with pip.
In Pycharm check what interpreter your project is using. If there is more than one available chance are you installed numpy on the other one.
https://www.jetbrains.com/help/pycharm/configuring-python-interpreter.html#add-existing-interpreter
You can also install numpy direct from Pycharm, simply hover over the import statement and if it's not installed on the current interpreter it will offer you a link to click in install it.
If that doesn't help, post the exact error message and your code.
I'm using a remote machine for computation and data analysis. I don't have sudo access in this machine, for data analysis purposes I want to use python libraries such as vtk etc since pip is not installed in this machine, I set up a 'virtual-environment' and install VTK there,
I used the method explained here (https://stackoverflow.com/a/13958308/10755782). Then I could install vtk in the virtual environment using pip.
But now the problem is that I can't import matplotlib.pyplot, it is giving me the error
ImportError: No module named Tkinter.
This error is strange because matplotlib.pyplot works in this particular system outside my virtual-environment. There are a few workarounds to start using matplotlib.pyplot without tkinter such as this (https://stackoverflow.com/a/49988926/10755782), but this is not helpfull in my case as this machine is remote-accessed and I need 'tkinter' to view the graphs on my screen.
I tried installing 'tkinter' inside my virtual-env, but I could not ( since we can't install 'tkinter' with pip and I don't have sudo access).
As I could not find any immediate solution to this problem anywhere I tried to fix this myself and I did the following,
inside my virtual environment, the version of matplotlib was 2.2.4 and outside it was 1.2.0 ( which is working fine). So I downgraded the version of matplotlib inside my virtual environment to 1.2.0
pip install 'matplotlib==1.2.0' --force-reinstall
now I have the same version of matplotlib inside and outside the virtual env. But now, when I try import matplotlilb.pyplot as plt I'm getting the error
ImportError: /b/home/ipcms/rcheenik/Python_virt-env/python2.7/my_new_env/lib/python2.7/site-
packages/matplotlib/_cntr.so: undefined symbol: _intel_fast_memset
Is there any way to fix this ^^ error? any of these following will be able to help me.
without OR is there any way to install tkinter without sudo ? or inside the 'virtual-environment' ?
OR is there any alternatives to matplotlib.pyplot which works without 'tkinter' and still display graphs remotely? ( not favourable, as I have to rewrite the entire code )
Thanks in advance for the help.
I found this answer to a similar question however, which I believe would solve your issue.
https://stackoverflow.com/a/49988926/8775307
It imports matplotlib.pyplot without tkinter. I don't know if all the features are actually included though, so you'll have to test and let us know :).
You could always write to the administrator and request Tkinter - it's a widely used and useful package, so they might be willing to include it.
I'm newer to python, but have seem to screwed things up trying out the new python.
I have an older mac which runs python 2.5 as it's default. I've installed python 3.3. However, when I upgraded numpy my python 2.5 now gives me the:
Error importing numpy: you should not try to import numpy from
its source directory; please exit the numpy source tree, and relaunch
your python intepreter from there.
regardless of the directory I run python from. And python 3.3 can't find the numpy module. Did I miss something? How can I get 2.5 running numpy again and get python 3.3 to find the module?
I also can't get virtualenv to work as it gives me the error that the script needs python2.6, even after I installed virtualenv-2.5 and can't get the python=python3.3 to do anything either. I seem to have tried everything I can find. I'm afraid I've installed too much and have some hidden conflict.
Thanks
download numpy from this site : http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy
In case you want to check the version of numpy on your system , write this following code on your IDE :
import numpy
numpy.version.version
Hope this would help !
When i try to run a python script in which i do an import statement matplotlib.patheffects, i get an error message saying there is no module called patheffects.
the statement is
import matplotlib.patheffects
Kindly help me to figure out the reason for this error and how to make the code run without this glitch.
import matplotlib.patheffects works perfectly well for me. Please make sure you have matplotlib installed. The most current version is 1.0.1. You can download from here.
Matplotlib depends on numpy, so make sure you have it installed before installing matplotlib.
Also check out the tips on installing matplotlib.