Issues with importing pylab on Mac OS X 10.8.3 - python

I get the following error when I import pylab:
Python 2.7.2 (default, Oct 11 2012, 20:14:37)
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pylab
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Python/2.7/site-packages/matplotlib-1.3.x-py2.7-macosx-10.8-intel.egg/pylab.py", line 1, in <module>
from matplotlib.pylab import *
File "/Library/Python/2.7/site-packages/matplotlib-1.3.x-py2.7-macosx-10.8-intel.egg/matplotlib/pylab.py", line 225, in <module>
import matplotlib.finance
File "/Library/Python/2.7/site-packages/matplotlib-1.3.x-py2.7-macosx-10.8-intel.egg/matplotlib/finance.py", line 23, in <module>
from matplotlib.collections import LineCollection, PolyCollection
File "/Library/Python/2.7/site-packages/matplotlib-1.3.x-py2.7-macosx-10.8-intel.egg/matplotlib/collections.py", line 23, in <module>
import matplotlib.backend_bases as backend_bases
File "/Library/Python/2.7/site-packages/matplotlib-1.3.x-py2.7-macosx-10.8-intel.egg/matplotlib/backend_bases.py", line 50, in <module>
import matplotlib.textpath as textpath
File "/Library/Python/2.7/site-packages/matplotlib-1.3.x-py2.7-macosx-10.8-intel.egg/matplotlib/textpath.py", line 11, in <module>
import matplotlib.font_manager as font_manager
File "/Library/Python/2.7/site-packages/matplotlib-1.3.x-py2.7-macosx-10.8-intel.egg/matplotlib/font_manager.py", line 1297
_fc_match_regex = re.compile(rb'\sfile:\s+"([^"]*)"')
^
SyntaxError: invalid syntax
Installed dependancies using homebrew
brew install freetype
brew install libpng
Installed matplotlib and numpy by cloning the github repo and doing:
sudo python setup.py build
sudo python setup.py install
Any help in resolving this issues is greatly appreciated.

There is a syntax error in that file. I guess you're using the development sources? That rb shouldn't be there before the regular expression (it should be r in Python 2.x, maybe b in Python 3.x).
UPDATE: Yep. Here's the faulty commit:
https://github.com/matplotlib/matplotlib/commit/2415c6200ebdba75a0571d71a4569f18153fff57

It should be br. This will be fixed in matplotlib master momentarily.

Trinity:
sudo pip install numpy
sudo pip install matplotlib
sudo pip install scipy
If you are using master to compile it run sudo brew update and then:
sudo brew install freetype
sudo brew install libpng
and then build and install:
sudo python setup.py build
sudo python setup.py install

Related

Python 3: ModuleNotFoundError: No module named 'pandas.util' (raspberry pi)

Am having issues importing pandas on python3 on my raspberry pi. Whatever I try, I get the following error:
pi#raspberrypi:/ $ python3
Python 3.7.3 (default, Jul 25 2020, 13:03:44)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pandas
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.7/dist-packages/pandas/__init__.py", line 22, in <module>
from pandas.compat import (
File "/usr/local/lib/python3.7/dist-packages/pandas/compat/__init__.py", line 15, in <module>
from pandas.compat.numpy import (
File "/usr/local/lib/python3.7/dist-packages/pandas/compat/numpy/__init__.py", line 7, in <module>
from pandas.util.version import Version
ModuleNotFoundError: No module named 'pandas.util'
It works fine on Python 2.7. I am getting errors with Python 3.7.3.
I searched Google and tried everything in the following post:
ImportError: No module named pandas
Some of the things I’ve tried are below - none have helped - I still get the error.
pip3 install pandas-util
pip3 install pandas.util
sudo apt-get install python3-wheel
sudo python3 -m pip install pandas
pip3 install pandas --upgrade
I've also tried uninstalling and reinstalling numpy and pandas - still get this error just with a basic import statement.
Any help would be appreciated as this is driving me insane!!
Cheers!
Try with
python3 -m pip install --force-reinstall pandas
This will ensure two things:
it will use the pip executable that belongs to the used Python executable, so that there is no accidental installation by another pip.
it will properly re-install Pandas.
Note that it doesn't re-download the Pandas package (it will use a cached version) if the version on PyPI hasn't changed between now and the previous installation. If that is a potential problem (incorrect cached file, for example), add the option --no-cache-dir to pip install.

Error when importing igraph: ImportError:cannot import name community_to_membership

I'm not sure if this has been answered already, but I couldn't find anything related to my error, so I figured I would post a question.
I'm running on Linux and I've downloaded the igraph package using pip install python-igraph and made sure it is the python-igraph-0.7.1 package provided by Tamas Nepusz.
When I try to do import igraph, I get the following errors:
~$ python
Python 2.7.12 (default, Dec 4 2017, 14:50:18)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import igraph
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/lashen/.local/lib/python2.7/site-packages/igraph/__init__.py", line 34, in <module>
from igraph._igraph import *
File "/home/lashen/.local/lib/python2.7/site-packages/igraph/igraph/__init__.py", line 37, in <module>
from igraph.cut import *
File "/home/lashen/.local/lib/python2.7/site-packages/igraph/cut.py", line 5, in <module>
from igraph.clustering import VertexClustering
File "/home/lashen/.local/lib/python2.7/site-packages/igraph/igraph/clustering.py", line 32, in <module>
from igraph import community_to_membership
ImportError: cannot import name community_to_membership
I'm not sure how to fix this import error. Did I install igraph incorrectly?? Seems like I got the right package ...
~$ pip show python-igraph
Name: python-igraph
Version: 0.7.1.post6
Summary: High performance graph data structures and algorithms
Home-page: http://pypi.python.org/pypi/python-igraph
Author: Tamas Nepusz
Author-email: tamas#cs.rhul.ac.uk
License: GNU General Public License (GPL)
Location: /home/lashen/.local/lib/python2.7/site-packages
Requires:
I have tried importing individual submodules of igraph, but to no avail. All submodule imports (e.g. import igraph.cut, import igraph._igraph) all result in the same error.
Why is this import error appearing? Any help is appreciated, thanks!!
You need to install sudo apt-get install libigraph0-dev first and then you can install igraph via pip install python-igraph --user

No module found in my python

I tried to read all the issues concerning the python's error
ImportError: No module named
I reinstalled all the modules I need using
sudo apt-get install build-essential python-dev python-setuptools python-numpy python-scipy libatlas-dev libatlas3gf-base
I also upgraded using pip
sudo pip install --upgrade numpy
sudo pip install --upgrade scipy
When runing pip list I get
matplotlib (1.3.1)
scipy (0.17.0)
numpy (1.11.0)
But here is the execution result :
>>> import matplotlib
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named matplotlib
>>> import numpy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/numpy/__init__.py", line 153, in <module>
from . import add_newdocs
File "/usr/lib/python2.7/dist-packages/numpy/add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "/usr/lib/python2.7/dist-packages/numpy/lib/__init__.py", line 8, in <module>
from .type_check import *
File "/usr/lib/python2.7/dist-packages/numpy/lib/type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "/usr/lib/python2.7/dist-packages/numpy/core/__init__.py", line 6, in <module>
from . import multiarray
ImportError: /usr/lib/python2.7/dist-packages/numpy/core/multiarray.so: undefined symbol: PyUnicodeUCS4_AsUnicodeEscapeString
I don't know what's happening! please help!!
OS ubuntu14.04
NEW EDIT
So some news: I checked out the install of python and I found different versions in different places. In the python2.7 case I have :
/usr/bin/python2.7
/usr/local/bin/pyton2.7
While using which I get
which python
/usr/local/bin/python
But the /usr/bin/python2.7 works really fine
cd /usr/bin
./python2.7
Python 2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import scipy
>>> import numpy
>>> import matplotlib
>>>
Thanks
This happens when the package has C extensions and they were compiled for an interpreter which does not fit the Python version you're trying to run it with.
(assuming you're running on Linux/OS X)
You can try using a virtualenv to install the package for the current Python version you're running:
pip install virtualenv
virtualenv my_env
source my_env/bin/activate
pip install numpy
Or you can directly provide the explicit path to the Python version with which you installed numpy.
Note that /usr/lib/python2.7/dist-packages/numpy/core/multiarray.so is the C extension which failed to load which indicates the problem.
Also see Conflicting versions of python in ubuntu for how to compile Python for your needs.
Install matplotlib like this if pip3 install didn't work for you
sudo apt-get install python3-matplotlib
Note - before doing check inside site-packages are present or not locate python using
which python

Numpy install under Ubuntu (12.04) causes Python ImportError

Under Ubuntu (12.04), installed python (2.7.5) with numpy (1.8rc2) using openblas into own environment (/din). The numpy site.cfg file is configured to point to openblas, and compiled as:
$ python setup.py build
$ sudo python setup.py install --prefix=/home/Programs/din/local
$ python
Python 2.7.5 (default, Oct 24 2013, 15:33:08)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/Programs/din/local/lib/python2.7/site-packages/numpy/__init__.py", line 137, in <module>
import add_newdocs
File "/home/Programs/din/local/lib/python2.7/site-packages/numpy/add_newdocs.py", line 9, in <module>
from numpy.lib import add_newdoc
File "/home/Programs/din/local/lib/python2.7/site-packages/numpy/lib/__init__.py", line 4, in <module>
from type_check import *
File "/home/Programs/din/local/lib/python2.7/site-packages/numpy/lib/type_check.py", line 8, in <module>
import numpy.core.numeric as _nx
File "/home/Programs/din/local/lib/python2.7/site-packages/numpy/core/__init__.py", line 5, in <module>
import multiarray
ImportError:
"/home/Programs/din/local/lib/python2.7/site-packages/numpy/core/multiarray.so: undefined symbol: ERR_peek_last_error
Cython, gevent, and other python packages have all been installed successfully into /din but not numpy. The $PATH and python sys.path have been checked and all looks good.
Does anyone have ideas to try out?
This may not directly address your specific problem, but if you're on Ubuntu 12.04, you can just apt-get. Then, because the version will not be the latest, I then do pip install --upgrade. Doing apt-get before pip first magically seems to install the right dependencies as well; if I do pip install first, it doesn't work.
Specifically:
sudo apt-get install python-numpy python-scipy libblas-dev liblapack-dev gfortran python-dev
sudo pip install numpy --upgrade
sudo pip install scipy --upgrade

Installing numpy Lion with Python 2.7?

I am working on a OS X 10.7 with Python 2.7 from python.org and XCode 4.2.
Following these instructions, I tried changing the CC, CXX,
and FFLAGS variables and install with sudo pip install numpy.
However, the installation still looks for gcc-4.2.
I tried
installing gcc-4.2 through MacPorts but get that Error: gcc42
does not build on Snow Leopard or later.
When I install numpy from the precompiled binary on sourceforge, I get the following error:
import numpy
Traceback (most recent call last):
File "", line 1, in
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/init.py", line 137, in
import add_newdocs
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/add_newdocs.py", line 9, in
from numpy.lib import add_newdoc
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/lib/init.py", line 4, in
from type_check import *
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/lib/type_check.py", line 8, in
import numpy.core.numeric as _nx
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/init.py", line 5, in
import multiarray
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/multiarray.so, 2): no suitable image found. Did find: /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/multiarray.so: no matching architecture in universal wrapper
Any help?
If I recall correctly the precompiled binary on source forge is 32-bit. It took me ages to get Numpy, Scipy, and Matplotlib set up on my macbook, it's definitely much harder than it should be.
I believe that your best option is the Scipy superpack. Before using the superpack you need to update to Xcode 4.3.2
So I just installed python 2.7.2 from python.org, grabbed the superpack, and now have numpy working on my machine. After installing python 2.7.2, I did sudo pip uninstall numpy, which didn't remove enough. So I cd'd into /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/ and moved both the numpy directory and the numpy egg to "old" versions of themselves. Then I ran sh install_superpack.sh and answered no to the "are you installing from a repository cloned to this machine(pretty important lol, hit yes without thinking the first time).
However, now I'm able to do this:
$ python
Python 2.7.2 (v2.7.2:8527427914a2, Jun 11 2011, 15:22:34)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> import scipy
>>> import matplotlib
With no problems :)
SuperPack worked for me (thanks, #Nolen) on OS X 10.8 (Mountain Lion) w/ XCode 4.5.1 installed.
Numpy worked for me using pip install numpy after step #1 below. But scipy would not install using pip. SuperPack fixed this.
The only thing I did differently was to use HomeBrew to install Python as step #1, rather than download it manually.
Install Python (separate from version that comes with OS X 10.8)
brew install python --framework --universal
pushd /System/Library/Frameworks/Python.framework/Versions
sudo rm Current
sudo ln -s /usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/Current
popd
Install SuperPack:
curl -o install_superpack.sh https://raw.github.com/fonnesbeck/ScipySuperpack/master/install_superpack.sh
sh install_superpack.sh
(type your admin password several times during the installation...)

Categories