I get the error in the title when I try to import matplotlib. Please I have been searching for 3 hours and still no solution.I've tried source activate base changing the interpreter, I have updated to latest matplotlib. and I have tried echo "backend : TkAgg" > ~/.matplotlib/matplotlibrc but none of these works. But numpy works but for some reason matplotlib does not. any help is appreciated.
terminal message:
Traceback (most recent call last):
File "/Users/MacBook/python/code/stats.py", line 2, in <module>
import matplotlib
ModuleNotFoundError: No module named 'matplotlib'
(base) MacBook-Air:~ MacBook$
My matplotlib version:
On another note: when trying to import matplotlib I see a matplotlib_inline but not matplotlib on VS CODE
Since You already installed matplotlib and since I had a similar problem, heres what I did:
1.) change your python interpreter: In VSCODE there's usually a "recommended" interpreter that they will recommend, try that one. If that dosen't work try to use the interpreter with "conda" in the name.
2.) This is the most important but overlooked step: RESTART your VS code to see the changes. bring up the command palate via cmd + shift + p, then type in "reload" and a "reload window" should pop up, click on it to reload.
3.) once reloaded you should be able to import matplotlib now.
Restarting vsCode after a library installation is underrated. it solved my problem with accesssing urllib3 after an installation
Related
I'm kind a new Python user - using Anaconda Python and VS code. I'm trying to launch my jupyter notebook, but I'm not able to import geopandas.
import geopandas
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
in
----> 1 import geopandas
ModuleNotFoundError: No module named 'geopandas'
I can see geopandas in 'conda list' in myenv, but still if I want to check it in my jupyter notebook I get negative response
import sys
'geopandas' in sys.modules
False
enter image description here
I already tried a lots of advices from here and git hub, but I'm not able to figure it out.
Am I missing something?
Thanks a lot for help!
Did you install the geopandas library before? If you don't do this before Please open your anaconda prompt form start menu and command the below lines
conda install -c conda-forge geopandas
and then press the enter button.
After that, You may apply below the line on your code
Update Code:
from geopy import geocoders # For matching the buildings' cities with time zones
from geopy.exc import GeocoderTimedOut # Catch timeouts while using Google geocoding API
from geopy.exc import GeocoderUnavailable # Catch other network problems
As long as you are sure that you can access the environment on jupyter,
What you have to do is to to manually install the packages.
Go to https://www.lfd.uci.edu/~gohlke/pythonlibs/, to download the compatible version for GDAL, Pyproj, Fiona, Shapely and Geopandas.
Then manually installed each using:
pip install the_file_path_to_the_downloaded_file
I hope this helps!
I ran into a similar problem with visual studio code. For me there is a button in the upper right corner of the VS Code window with the current environment selected. I clicked it and it allows me to change the kernel for the notebook :
This is assuming you have the dependencies installed.
First of all, I want to note that I've read a lot of links related to my problem.
I have some problems with running the code when I want to import a module.
Here is an example of the code:
import numpy as np
Then PyCharm gives me an exception:
Traceback (most recent call last):
File "/Users/Alexander 1
2/PycharmProjects/Coursera/Week1/Vectors/Vecors.py", line 1, in
import numpy as np
ModuleNotFoundError: No module named 'numpy'
Process finished with exit code 1
I have read this and did all what was written. However, it hasn't been working. I've reloaded the PyCharm – no result.
Help me, please! I'm using MacOS 10.13.5, PyCharm 2018.1.4 CE.
You probably have created a new project using virtualenv, read about it here.
It basically creates a new project specific environment, so the libraries inside won't cause a conflict with python2 and python3 packages. So, inside Pycharm, open terminal by pressing alt+f12 , which will open a terminal inside Pycharm, and install numpy usually by pip install numpy
I don't know why, but when I rebooted the computer and created a new project, this problem has disappeared.
I have Anaconda 3 installed (Python 3.6.3) and I am working on a project that uses the CV2 package in python. Now I am relatively new to python but I have been using this package (via "import cv2" command) in PyCharm with no problems. However, today, I wanted to give Spyder a try. I started using the IDE and everything was working. But all of a sudden, Spyder kept giving me an error when I try to import cv2. I really did not change anything and I only was debugging the script. The error I am getting is as follows:
"""
In [1]: import cv2
Traceback (most recent call last):
File "", line 1, in
import cv2
ImportError: DLL load failed: The specified procedure could not be found.
"""
I cannot figure out how this can be related to the IDE since PyCharm still can import it. Could anybody give me a hint please?
As I know CV2 is python 2x related. When You use CV2 You need copy cv2.pyd file directly to python 2x site-packages.
I realize this seems like a generic question, but all answers pointed to having two simultanious python installations - I already uninstalled the other one.
Currently I run my code from PyCharm 2017.1.5 (windows 10) with Python interpreter set as Python 3.6.1 (C:\Anaconda3\python.exe), i.e. I installed Anaconda3, which includes the matplotlib, and run from PyCharm using the Ananconda3-interpreter.
I've checked in Anaconda Navigator that matplotlib 2.0.2 is installed in the environment.
A minimal (non-working) example:
import matplotlib.pyplot as plt
plt.plot(range(10))
plt.show()
Returns the following error:
C:\Anaconda3\python.exe C:/Users/John/Documents/CPU/master/untitled/main11.py
Traceback (most recent call last):
File "C:/Users/John/Documents/CPU/master/untitled/main11.py", line 1, in <module>
import matplotlib.pyplot as plt
File "C:\Anaconda3\lib\site-packages\matplotlib\pyplot.py", line 29, in <module>
import matplotlib.colorbar
File "C:\Anaconda3\lib\site-packages\matplotlib\colorbar.py", line 34, in <module>
import matplotlib.collections as collections
File "C:\Anaconda3\lib\site-packages\matplotlib\collections.py", line 37, in <module>
import matplotlib.lines as mlines
File "C:\Anaconda3\lib\site-packages\matplotlib\lines.py", line 28, in <module>
from matplotlib.markers import MarkerStyle
ModuleNotFoundError: No module named 'matplotlib.markers'
Process finished with exit code 1
This ran fine 2 weeks ago, but not now. To my knowledge, I didn't change or update anything. The module loads correctly, but it seems to be a change in the module content? If so: How did that happen and how can I fix it?
In my case, I could fix it by setting PYTHONPATH to the path to site-packages folder where the needed packages are located, excluding site-pacages.
I use a pyenv virtual environment, whose path is /home/apk/.pyenv/versions/python-3-7-4. When the environment is activated, pip installs packages to /home/apk/.pyenv/versions/python-3-7-4/lib/python3.7/site-packages. Therefore, in terminal, I set:
$ PYTHONPATH=/home/apk/.pyenv/versions/python-3-7-4/lib/python3.7/
The same should be true for Windows installations of python.
If virtual environmets are used, then one could edit activate script to set PYTHONPATH.
After I did it, I checked in a python shell.
$ python
Python 3.7.4 (default, Feb 5 2020, 17:11:33)
[GCC 5.5.0 20171010] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['', '/home/apk/.pyenv/versions/3.7.4/lib/python37.zip', '/home/apk/.pyenv/versions/3.7.4/lib/python3.7', '/home/apk/.pyenv/versions/3.7.4/lib/python3.7/lib-dynload', '/home/apk/.pyenv/versions/python-3-7-4/lib/python3.7']
>>> sys.executable
'/home/apk/.pyenv/versions/python-3-7-4/bin/python'
Good luck!
References
https://github.community/t5/Programming-Help-and-Discussion/Python-ModuleNotFoundError-although-module-is-installed-aiohttp/td-p/28525
#ImportanceOfBeingErnest lead me in the right direction. I post my solution here s.t. others may find the answer. The problem was a corrupted disk sector - an unlikely event of chance.
The problem was indeed in the matplotlib-package itself. Retrospectively, pointers to the issue were that errors in pre-distributed packages should not exist. If they do, external circumstances must have corrupted and the problem is not with the Python-installation itself.
I uninstalled matplotlib through Anaconda Prompt with conda remove matplotlib and re-installed with conda install matplotlib. This gave me this error:
(C:\Anaconda3) C:\Users\John>conda install matplotlib
[...]
ERROR conda.core.link:_execute_actions(337): An error occurred while installing package 'defaults::matplotlib-2.0.2-np112py36_0'.
OSError(22, 'Invalid argument') Attempting to roll back.
OSError(22, 'Invalid argument')
Before #Ernest's comment, I thought it maybe had to do with non-ASCII in PATH or similar.
Instead I tried to reinstall Anaconda3 completely, restarted and found that part of the Anaconda3-folder weren't removed (the one containing the matplotlib).
Deleting it manually gave a Windows error 0x80070570. Following this post on ServerFault (the comment to OP) I ran a check and afterwards a repair from Windows Explorer GUI: Right-click on the drive in This PC --> Properties --> Tab Tools --> Check (repair appears if any errors are found).
After some restarts, reinstalling Anaconda3 from scratch and restarting again, I was able to run my project again!
It is difficult to answer this question directly, however, I have seen a large amount of issues in corporate Windows environments with PyCharm and Anaconda these are some of the issues you may be having
Check you PATH is correctly pointing to all Anaconda locations
import sys
sys.path
Check that your files have not been migrated to C:\Users\username\AppData\Roaming by your IT team
Purge your system for any python distributions. There may be software distributions that you use internally that package their own python distribution. This can often be included in the PATH. Another example could be installing Anaconda to your C:\ but also having it already installed in Users\Local\AppData or 'C:\Program Files' months before and forgotten!
A good way of directly debugging your problem would be to navigate to the following directory in ipython
C:\Anaconda3\lib\site-packages\matplotlib
and they try import matplotlib.markers
If this fails then you could then try
import matplotlib
matplotlib.__file__
you should check that this result gives
'C:\\Anaconda3\\lib\\site-packages\\matplotlib\\__init__.pyc'
as most likely there will be another matplotlib version installed that is taking precedence. This will then fall under one of the issues above to correct.
Got the same type of error while using pip. created new VENV and execute the app agaist that resolved my issue
PyCharm requires installing packages available in the interpreter.
You can find matplotlib and other packages available for an install using the following steps:
Open the File--Settings--Project--Project Interpreter menu.
You should see all packages you currently have installed, and matplotlib should be missing from this list.
Click the + (add) button to the right and install the matplotlib package.
Once complete, close the top dialog box, and you should see matplotlib in the list of installed packages.
I'm trying to run a simple python program in eclipse. This is the first time that I'm importting any module.
So I downloaded: numpy and pylab (I'm using a mac) restarted my eclipse and the red line below the
import numpy
import pylab
disappeared so I understood that the reference to that module is ok.
Problem is that I still see red line below the code and wonder why? I have to stress out that I believe numpy was already 'pre-installed' I just upgraded the version (using 1.5.1-py2.7).
Can anyone tell what should I do to run this code?
my interpreter setting on eclipse:
If you are using PyDev, you should first have to go to Preferences, then Pydev, then Interpreter Python and then Libraries to add NumPy.
Else, verify that you have NumPy installed, from the interpreter, just call from numpy import *
Edit:
Also check you already have Matplotlib installed, the error you are getting on the console points to that being the cause, you can download Matplotlib here.
I recently installed Anaconda3 and just started learning how to use Pandas and I wanted to be able to work with Pandas in Eclipse as well.
I first tried adding a reference to the site-libraries at:
C:\Anaconda3\Lib\site-packages
And it seemed to work by allowing me to import numpy and pandas. However, since I had just used conda to update everything, my Python34 interpreter seemed to fail when I tried running some code and numpy was looking for my Python35 installation. For some reason this was located at:
C:\Users\myname\AppData\Local\Programs\Python\Python35-32
However, Anacondas installed another version somewhere else. By going into:
Windows > Preferences > PyDev > Interpreters > Python Interpreter
and clicking on Quick Auto-Config it found my Anacondas version of Python35 and then I just had to figure out how to make my current project use the Python35 interpreter.
Hint: To do this, you need to go into the Project properties by opening the project and choosing File > Properties or right-click the project to choose Properties.
Simply removed the old numpy and installed version 6. located here
Another way to circumvent this problem is to use pip install numpy check how to install pip