ImportError libqhull.so.5 when importing pyplot - python

I'm getting an ImportError whenever I try to import pyplot from matplotlib. Matplotlib is installed via pip in a virtual environment. This is the error I'm getting:
>>> import matplotlib.pyplot
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/mikefrank/.virtualenvs/pv-hrt/local/lib/python2.7/site-packages/matplotlib/pyplot.py", line 36, in <module>
from matplotlib.figure import Figure, figaspect
File "/home/mikefrank/.virtualenvs/pv-hrt/local/lib/python2.7/site-packages/matplotlib/figure.py", line 40, in <module>
from matplotlib.axes import Axes, SubplotBase, subplot_class_factory
File "/home/mikefrank/.virtualenvs/pv-hrt/local/lib/python2.7/site-packages/matplotlib/axes/__init__.py", line 4, in <module>
from ._subplots import *
File "/home/mikefrank/.virtualenvs/pv-hrt/local/lib/python2.7/site-packages/matplotlib/axes/_subplots.py", line 10, in <module>
from matplotlib.axes._axes import Axes
File "/home/mikefrank/.virtualenvs/pv-hrt/local/lib/python2.7/site-packages/matplotlib/axes/_axes.py", line 38, in <module>
import matplotlib.tri as mtri
File "/home/mikefrank/.virtualenvs/pv-hrt/local/lib/python2.7/site-packages/matplotlib/tri/__init__.py", line 9, in <module>
from .triangulation import *
File "/home/mikefrank/.virtualenvs/pv-hrt/local/lib/python2.7/site-packages/matplotlib/tri/triangulation.py", line 7, in <module>
import matplotlib._qhull as _qhull
ImportError: libqhull.so.5: cannot open shared object file: No such file or directory

This can occur after a system upgrade. In my specific case, I upgraded Ubuntu 14.04 to 16.04. Matplotlib links to specific versions of \*.so, and these go out of date. I presume this is because the different versions are not (always) backward compatible.
(For me, I went from libqhull.so.6 to libqhull.so.7 during the OS upgrade, and matplotlib was linked to libqhull.so.6.)
Firstly, you can probably make sure libqhull exists on your system by using something like:
sudo apt install libqhull-dev
or the equivalent for your system.
(mine was already installed, so nothing changed.)
Since nowadays, pip often installs a wheel, which is already compiled, we'll need to force pip to do the compilation, so it links with the new so file.
I used:
py35 -m pip install --upgrade matplotlib --no-binary matplotlib --force
The options:
--no-binary matplotlib tells pip to not use a wheel for matplotlib (but it may still use wheels for dependencies such as numpy).
--upgrade should be obvious
--force, because we may already be at the latest matplotlib version, and then --upgrade will not do anything.

Related

Unable to import TorchVision after installation Mac OSX

I've installed Pytorch and Torchvision in the way suggested on their website via pip within a virtual environment (env), and whilst no errors occur during installation when I go to import torchvision in my python code the following error occurs.
Traceback (most recent call last):
File "demo.py", line 2, in <module>
import torchvision
File "/Users/QuinceyBee/env/lib/python3.7/site-packages/torchvision/__init__.py", line 2, in <module>
from torchvision import datasets
File "/Users/QuinceyBee/env/lib/python3.7/site-packages/torchvision/datasets/__init__.py", line 9, in <module>
from .fakedata import FakeData
File "/Users/QuinceyBee/env/lib/python3.7/site-packages/torchvision/datasets/fakedata.py", line 3, in <module>
from .. import transforms
File "/Users/QuinceyBee/env/lib/python3.7/site-packages/torchvision/transforms/__init__.py", line 1, in <module>
from .transforms import *
File "/Users/QuinceyBee/env/lib/python3.7/site-packages/torchvision/transforms/transforms.py", line 17, in <module>
from . import functional as F
File "/Users/QuinceyBee/env/lib/python3.7/site-packages/torchvision/transforms/functional.py", line 5, in <module>
from PIL import Image, ImageOps, ImageEnhance, PILLOW_VERSION
ImportError: cannot import name 'PILLOW_VERSION' from 'PIL' (/Users/QuinceyBee/env/lib/python3.7/site-packages/PIL/__init__.py)
I have tried creating new virtual environments to rebuild from scratch, tried to install via conda within a conda environment, however, neither of these resolved this issue.
I apologise for any format issues, this is the first time posting on here and also I'm relatively new to using python.
Any assistance would be greatly appreciated.
Pillow 7.0.0 removed PILLOW_VERSION, you should use version in your own code instead.
https://pillow.readthedocs.io/en/stable/deprecations.html#pillow-version-constant
If using Torchvision, there is a release planned this week (week 2, 2020) to fix it:
https://github.com/pytorch/vision/issues/1712#issuecomment-570286349
The options are:
wait for the new torchvision release
use the master version of torchvision as given below
pip install -U git+https://github.com/pytorch/vision)
install torchvision from a nightly, which also requires a pytorch from a nightly version
or install Pillow<7
pip install "pillow<7"

sklearn "numpy.dtype has the wrong size, try recompiling" in both pycharm and terminal

I got "numpy.dtype has the wrong size, try recompiling" in both pycharm and terminal when compiling Sci-kit learning. I've upgraded all packages(numpy, scikit to the latest), nothing works.Python version is 2.7. Please help. Appreciate!
checking for nltk
Traceback (most recent call last):
File "startup.py", line 6, in <module>
import nltk
File "/Library/Python/2.7/site-packages/nltk/__init__.py", line 128, in <module>
from nltk.chunk import *
File "/Library/Python/2.7/site-packages/nltk/chunk/__init__.py", line 157, in <module>
from nltk.chunk.api import ChunkParserI
File "/Library/Python/2.7/site-packages/nltk/chunk/api.py", line 13, in <module>
from nltk.parse import ParserI
File "/Library/Python/2.7/site-packages/nltk/parse/__init__.py", line 79, in <module>
from nltk.parse.transitionparser import TransitionParser
File "/Library/Python/2.7/site-packages/nltk/parse/transitionparser.py", line 21, in <module>
from sklearn.datasets import load_svmlight_file
File "/Library/Python/2.7/site-packages/sklearn/__init__.py", line 57, in <module>
from .base import clone
File "/Library/Python/2.7/site-packages/sklearn/base.py", line 11, in <module>
from .utils.fixes import signature
File "/Library/Python/2.7/site-packages/sklearn/utils/__init__.py", line 10, in <module>
from .murmurhash import murmurhash3_32
File "numpy.pxd", line 155, in init sklearn.utils.murmurhash (sklearn/utils/murmurhash.c:5029)
ValueError: numpy.dtype has the wrong size, try recompiling
The error "numpy.dtype has the wrong size, try recompiling" means that sklearn was compiled against a numpy more recent than the numpy version sklearn is now trying to import. To fix this, you need to make sure that sklearn is compiled against the version of numpy that it is now importing, or an earlier version. See ValueError: numpy.dtype has the wrong size, try recompiling for a detailed explanation.
I guess from your paths that you are using the OSX system Python (the one that ships with OSX, at /usr/bin/python). Apple has modified this Python in a way that makes it pick up its own version of numpy rather than any version that you install with pip etc - see https://github.com/MacPython/wiki/wiki/Which-Python#system-python-and-extra-python-packages . I strongly recommend you switch to Python.org or homebrew Python to make it easier to work with packages depending on numpy.
The problem occurs when you are using incompatible versions. Check the versions using:
pip freeze
or, for a specific module
pip freeze | grep Module_Name
I fix my problem by updating all packages:
pip install -U scikit-learn numpy scipy pandas matplotlib
As of Today(30/11/2016). These versions are compatible:
matplotlib==1.5.2
nltk==3.2.1
numpy==1.11.2
pandas==0.19.1
scikit-learn==0.18.1
scipy==0.18.1
textblob==0.11.1

Python matplotlib not importing due to failure to import unichr

I'm running Ubuntu 13.10 with Python 2.7.5+, and whenever I try to import the matplotlib package, I get an error. Specifically, my test script has only the following code:
#!/usr/bin/python
import matplotlib.pyplot as plt
When I run the test script, here is the error:
Traceback (most recent call last):
File "./test.py", line 2, in <module>
import matplotlib.pyplot as plt
File "/usr/local/lib/python2.7/dist-packages/matplotlib/pyplot.py", line 27, in <module>
import matplotlib.colorbar
File "/usr/local/lib/python2.7/dist-packages/matplotlib/colorbar.py", line 34, in <module>
import matplotlib.collections as collections
File "/usr/local/lib/python2.7/dist-packages/matplotlib/collections.py", line 27, in <module>
import matplotlib.backend_bases as backend_bases
File "/usr/local/lib/python2.7/dist-packages/matplotlib/backend_bases.py", line 56, in <module>
import matplotlib.textpath as textpath
File "/usr/local/lib/python2.7/dist-packages/matplotlib/textpath.py", line 22, in <module>
from matplotlib.mathtext import MathTextParser
File "/usr/local/lib/python2.7/dist-packages/matplotlib/mathtext.py", line 26, in <module>
from six import unichr
ImportError: cannot import name unichr
Any idea what I'm doing wrong?
You apparently have an outdated version of six.
The unichr wrapper was added in version 1.4.0, as seen in CHANGES. I'm not sure exactly when 1.4.0 was released, but the fix for issue #25 was committed on 2013-05-18, so… some time after that.
So, if you print(six.__version__), and it's anything less than '1.4.0', that's your problem.
Depending on whether you're installing packages with pip or with your system's package manager, the solution is going to be something like one of these:
$ pip install --upgrade six
$ apt-get install six
$ brew install --upgrade six
… etc.
But meanwhile, matplotlib shouldn't be requiring 1.3 but using features only available in 1.4. Your GitHub issue matplotlib#3538 should get this fixed.

Error importing numpy after upgrading with pip

This question is related to a question here: Unable to import numpy
I ran: sudo pip install --upgrade numpy
then when I ran python and tried to import numpy I got this strange error!!! I'm going crazy!
>>> import numpy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/__init__.py", line 153, in <module>
from . import add_newdocs
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/lib/__init__.py", line 18, in <module>
from .polynomial import *
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/lib/polynomial.py", line 19, in <module>
from numpy.linalg import eigvals, lstsq, inv
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/linalg/__init__.py", line 50, in <module>
from .linalg import *
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/linalg/linalg.py", line 29, in <module>
from numpy.linalg import lapack_lite, _umath_linalg
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/linalg/lapack_lite.so, 2): Symbol not found: __gfortran_compare_string
Referenced from: /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/linalg/lapack_lite.so
Expected in: flat namespace
in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/linalg/lapack_lite.so
>>>
EDIT:
I also ran this:
$ pip show numpy
---
Name: numpy
Version: 1.8.0
Location: /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
Requires:
The fix for me to was to manually install gcc via macports:
sudo port install gcc48
... which installs gfortran, but without the alias that numpy seems to be expecting (gfortran). Then we make a symlink:
sudo ln -s /opt/local/bin/gfortran-mp-4.8 /opt/local/bin/gfortran
After that, I uninstalled and reinstalled numpy via pip and it works like a charm.
This fixed the issue for me on mavericks last night. From what I've read, gfortran used to be part of the OS X command line tools, but isn't as of Lion or so. Installing gcc separately "fixes" that.

ATpy ImportError: No module named astropy.io

I tried to get atpy on python 2.7. I downloaded ATpy0.9.6 from
https://pypi.python.org/pypi/ATpy/0.9.6
then tar it, and run:
cd ATpy0.9.6
sudo python setup.py install
things seemed to work well.
But when I tried to import atpy on python, I got always this error message:
ImportError: No module named astropy.io
More precisely,
>>> import atpy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/atpy/__init__.py", line 1, in <module>
from .basetable import Table, TableSet, VectorException
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/atpy/basetable.py", line 15, in <module>
from . import registry
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/atpy/registry.py", line 164, in <module>
from . import fitstable
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/atpy/fitstable.py", line 8, in <module>
from astropy.io import fits
ImportError: No module named astropy.io
>>>
Could anyone help me to figure out the problem?
Perhaps the 'atpy' package depends on another package called 'astropy.io' that you are missing? Yes here it is https://astropy.readthedocs.org/en/v0.1/index.html
It happens that downloading the tar balls from pypi.python.org is the wrong way to install Python packages. The right way (though the Python docs explain poorly), is to run a command like
pip install atpy
This command will install your package and all its dependencies.
If the command pip is missing, you have to install it, which is ironically really complicated.
In my case the solution was to install astropy
pip install --no-deps astropy

Categories

Resources