Getting an error when trying to import matplotlib - python

I am using ipython when I am trying to import matplotlib.
I am getting following error
ImportError Traceback (most recent call last)
/home/akajappan/<ipython-input-4-82be63b7783c> in <module>()
----> 1 import matplotlib
/home/akajappan/matplotlib.py in <module>()
----> 1 from pylab import plotfile, show, gca
2 import matplotlib.cbook as cbook
3
4 fname = cbook.get_sample_data('msft.csv', asfileobj=False)
5 fname2 = cbook.get_sample_data('data_x_x2_x3.csv', asfileobj=False)
ImportError: No module named pylab
I tried to install scipy still the error exists.
(sudo apt-get install python-numpy python-scipy python-matplotlib)
Operating system : ubuntu 12.04

If you are satisfied with workaround - install anaconda distribution. This is a python distribution with all (or most) scientific packages installed. It saved me, it may help you as well.
http://continuum.io/downloads

Related

When importing Cartopy ImportError: DLL load failed while importing trace: The specified module could not be found

I installed Christoph Gohlke's prebuilt wheel Cartopy‑0.20.2‑cp39‑cp39‑win_amd64.whl using pip in an active virtual environment. The environment is using Python 3.9.5. When trying to import Cartopy I get the error message below. This used to work before and now it no longer works and I can't figure out why. Does anyone know what the issue could be or what I'm missing?
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
Input In [4], in <cell line: 1>()
----> 1 import cartopy
2 import cartopy.crs as ccrs
3 import cartopy.io.img_tiles as cimgt
File ~\Downloads\GitHub\Project\venv\lib\site-packages\cartopy\__init__.py:110, in <module>
105 pass
108 # Commonly used sub-modules. Imported here to provide end-user
109 # convenience.
--> 110 import cartopy.crs
111 import cartopy.feature
File ~\Downloads\GitHub\Project\venv\lib\site-packages\cartopy\crs.py:27, in <module>
24 from pyproj.exceptions import ProjError
25 from shapely.prepared import prep
---> 27 import cartopy.trace
30 try:
31 # https://github.com/pyproj4/pyproj/pull/912
32 from pyproj.crs import CustomConstructorCRS as _CRS
ImportError: DLL load failed while importing trace: The specified module could not be found.
As mentioned by cgohlke in the comments, installing the wheels of shapely and pyproj from his website solves the issue.
If the libraries are already installed, use --force-reinstall to overwrite the existing installations.

Undefined symbol when importing OpenEXR in Python script

I want to load EXR images in a Python script. Thus I imported it with
import OpenEXR
but unfortunately I am getting the following error when I start my script with
ipython testscript.py
Error Message
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
PATH_TO_SCRIPT/testscript.py in <module>()
8 import numpy as np
9 # import matplotlib.pyplot as plt
---> 10 import OpenEXR
11
12 # import dts_input
ImportError: PATH_TO_SCRIPT/OpenEXR.cpython-37m-x86_64-linux-gnu.so: undefined symbol: _ZTIN7Imf_2_27OStreamE
I have installed OpenEXR with Arch Linux's package manager and the binding module for python locally with
pip install --target ./ openexr
and a file called OpenEXR.cpython-37m-x86_64-linux-gnu.so has been installed in the script folder.
I have no idea how to solve the linking problem since it seams to be a linking error relating to OpenEXR's own imf library.

"No module named plotly"

My problem is very simple. I have installed it with sudo pip3 install plotly but I can't import it. I've already tried to reinstall it without effects.
ImportError Traceback (most recent call last)
<ipython-input-1-9d1f271208ac> in <module>()
----> 1 import plotly.plotly as py
2 import plotly.graph_objs as go
3 import pandas as pd
4 from pandas import Series,DataFrame
5 import numpy as np
ImportError: No module named 'plotly'
If this error occurs open Terminal and if you using different source like ZSH or something else change it to bash by running
bash
in terminal and then run
conda install -c https://conda.anaconda.org/plotly plotly
and the problem resolves.

ImportError: libgeos-3.6.2.so: cannot open shared object file: No such file or directory

I installed mpl_toolkits.basemap yet it is still not working. In ipython I am trying:
In [1]: from mpl_toolkits.basemap import Basemap
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-d9467465a3b6> in <module>()
----> 1 from mpl_toolkits.basemap import Basemap
/usr/local/lib/python2.7/dist-packages/mpl_toolkits/basemap/__init__.py in <module>()
37 import numpy as np
38 import numpy.ma as ma
---> 39 import _geoslib
40 import functools
41
ImportError: libgeos-3.6.2.so: cannot open shared object file: No such file or directory
Still not working. Help.
I got the same error when trying to install PostGIS. Installing the following fixed the error for me
sudo apt-get install binutils libproj-dev gdal-bin
Once I had a similar error. I fixed it finding the location of the library. In my case the location was different that where all my libs where, so I moved it to the correct folder and it worked.

Installing matplotlib on Ubuntu: ImportError

My platform:
Ubuntu 13.04, Python 2.7.4.
Installing matplotlib failed, ImportError: No module named pyplot.
I have tried many ways such as
$ sudo apt-get install python-matplotlib
and easy install, install from source..., I'm folllowing http://matplotlib.org/faq/installing_faq.html
But none of them works, This ImportError always happen, Anyone can help?
EDIT The trace back:
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-4-82be63b7783c> in <module>()
----> 1 import matplotlib
/home/wuhuijia/matplotlib.py in <module>()
1 import numpy as np
----> 2 import matplotlib.pyplot as plt
3 import scipy.optimize as so
4
5 def find_confidence_interval(x, pdf, confidence_level):
ImportError: No module named pyplot
Your script is named matplotlib.py. Python will first look locally when importing modules, that is, on the directory itself. Thus, Python imports your script (and not the installed matplotlib) when you execute import matplotlib.pyplot, and since your script has no submodule pyplot, it fails.
Rename your script to something else (e.g., testmpl.py) and you should be fine.

Categories