No module found in my python - 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

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.

numpy suddenly stopped working on Raspberry

Week before perfectly working numpy stopped working under Python 3.7 on Raspbian GNU/Linux 10 (buster). Still works with Python 2.7.
~ $ python3
Python 3.7.3 (default, Apr 3 2019, 05:39:12)
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
Traceback (most recent call last):
File "/usr/local/lib/python3.7/dist-packages/numpy/core/__init__.py", line 24, in <module>
from . import multiarray
File "/usr/local/lib/python3.7/dist-packages/numpy/core/multiarray.py", line 14, in <module>
from . import overrides
File "/usr/local/lib/python3.7/dist-packages/numpy/core/overrides.py", line 7, in <module>
from numpy.core._multiarray_umath import (
ImportError: libf77blas.so.3: cannot open shared object file: No such file or directory
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.7/dist-packages/numpy/__init__.py", line 142, in <module>
from . import core
File "/usr/local/lib/python3.7/dist-packages/numpy/core/__init__.py", line 54, in <module>
raise ImportError(msg)
ImportError:
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the numpy c-extensions failed.
- Try uninstalling and reinstalling numpy.
- If you have already done that, then:
1. Check that you expected to use Python3.7 from "/usr/bin/python3",
and that you have no directories in your PATH or PYTHONPATH that can
interfere with the Python and numpy version "1.18.1" you're trying to use.
2. If (1) looks fine, you can open a new issue at
https://github.com/numpy/numpy/issues. Please include details on:
- how you installed Python
- how you installed numpy
- your operating system
- whether or not you have multiple versions of Python installed
- if you built from source, your compiler versions and ideally a build log
- If you're working with a numpy git repository, try `git clean -xdf`
(removes all files not under version control) and rebuild numpy.
Note: this error has many possible causes, so please don't comment on
an existing issue about this - open a new one instead.
Original error was: libf77blas.so.3: cannot open shared object file: No such file or directory
Tried to reinstall:
~ $ sudo pip3 uninstall -y numpy
Uninstalling numpy-1.18.1:
Successfully uninstalled numpy-1.18.1
~ $ sudo pip3 install numpy
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting numpy
Using cached https://www.piwheels.org/simple/numpy/numpy-1.18.1-cp37-cp37m-linux_armv7l.whl
Installing collected packages: numpy
Successfully installed numpy-1.18.1
Did not work.
Tried first reinstalling setuptools using sudo pip3 uninstall -y setuptools, returns:
Not uninstalling setuptools at /usr/lib/python3/dist-packages, outside environment /usr
Can't uninstall 'setuptools'. No files were found to uninstall.
But when I try to install it using sudo pip3 install setuptools, returns:
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Requirement already satisfied: setuptools in /usr/lib/python3/dist-packages (40.8.0)
I am confused, do not know what to do.

how to install lxml with pypy in virtualenv

I am trying to use pypy in a virtualenv for better performance in running my python program. I was able to install all the required modules, except for lxml
So far, I tried
pip install lxml
Also tried
pip install --upgrade lxml
It shows the following message at the end:
Successfully installed lxml-3.4.4
However, when I start pypy prompt and try to import lxml, I get the error:
(venv)➜ pypy pypy
Python 2.7.3 (2.2.1+dfsg-1ubuntu0.2, Dec 02 2014, 23:00:55)
[PyPy 2.2.1 with GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
And now for something completely different: ``denial is rarely a good debugging
technique''
>>>> import lxml
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named lxml
>>>> from lxml import html
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named lxml
Update:
I am using ubuntu 14.04
Also, I have tried
sudo apt-get install pypy-dev
I had a similar problem. I got it working by running sudo apt-get install python-dev libxml2 libxml2-dev libxslt-dev and then pip install --upgrade lxml

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

Issues with importing pylab on Mac OS X 10.8.3

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

Categories