ImportError: No module named matplotlib even using pip install matplotlib - python

I am importing matplotlib from Jupyter Notebook but get the following error.
ImportError: No module named matplotlib
Settings:
Python 2
MacBook
conda: 4.3.30
After run
conda list
it got:
ipykernel 4.6.1
ipython 5.3.0
matplotlib 2.0.2 np112py36_0
matplotlib 2.1.1
Some commends I tried but failed
1.
sudo apt-get install python-matplotlib
and shows
sudo: apt-get: command not found
2.
sudo apt-get install python3-matplotlib
and shows
sudo: apt-get: command not found
commends 1 and 2 are from this site
ImportError: No module named matplotlib with matplotlib installed
3.
pip install matplotlib
and shows
Requirement already satisfied: matplotlib in ./anaconda/lib/python3.6/site-packages
Requirement already satisfied: pytz in ./anaconda/lib/python3.6/site-packages (from matplotlib)
Requirement already satisfied: cycler>=0.10 in ./anaconda/lib/python3.6/site-packages (from matplotlib)
Requirement already satisfied: numpy>=1.7.1 in ./anaconda/lib/python3.6/site-packages (from matplotlib)
Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in ./anaconda/lib/python3.6/site-packages (from matplotlib)
Requirement already satisfied: six>=1.10 in ./anaconda/lib/python3.6/site-packages (from matplotlib)
Requirement already satisfied: python-dateutil>=2.0 in ./anaconda/lib/python3.6/site-packages (from matplotlib)
commend 3 from this website
ImportError: No module named matplotlib.pyplot
Update:
run this
pip2 install matplotlib
it was successfully installed like this
Collecting matplotlib
Downloading matplotlib-2.1.1-cp27-cp27m...
...
Successfully built subprocess32
Installing collected packages: subprocess32, six, python-dateutil, backports.functools-lru-cache, pyparsing, cycler, numpy, pytz, matplotlib
Successfully installed backports.functools-lru-cache-1.4 cycler-0.10.0 matplotlib-2.1.1 numpy-1.13.3 pyparsing-2.2.0 python-dateutil-2.6.1 pytz-2017.3 six-1.11.0 subprocess32-3.2.7
then restart Anaconda and Jupyter, and it was not imported.

By the looks of it you already have matplot lib installed for python3.6, just run with python3.6 instead of python, which ends up running python2.
pip will also normally install packages for python2 so if you want to install them for python3 use pip3 install <package>
since apt-get can not be found you are probably running CentOS which uses yum instead as the default package manager. To install you'd normally use the following command:
yum install <packagename>

Related

Spyder (pip installed) doesn't start anymore with the error: undefined symbol: _ZdaPvm, version QT_5

On Ubuntu 22.04 (5.15.0-43-generic) I freshly updated spyder using pip as follow:
$ sudo -H pip3 install --upgrade spyder
everything went fine, but it throws this error when I start spyder now:
$ spyder
Traceback (most recent call last):
File "/usr/local/bin/spyder", line 8, in <module>
sys.exit(main())
File "/usr/local/lib/python3.10/dist-packages/spyder/app/start.py", line 248, in main
from spyder.app import mainwindow
File "/usr/local/lib/python3.10/dist-packages/spyder/app/mainwindow.py", line 57, in <module>
from qtpy import QtWebEngineWidgets # analysis:ignore
File "/usr/local/lib/python3.10/dist-packages/qtpy/QtWebEngineWidgets.py", line 29, in <module>
from PyQt5.QtWebEngineWidgets import QWebEnginePage
ImportError: /usr/local/lib/python3.10/dist-packages/PyQt5/Qt5/lib/libQt5Network.so.5: undefined symbol: _ZdaPvm, version Qt_5
Some more info:
$ python3 --version
Python 3.10.4
$ pip list | grep -i pyqt
PyQt5 5.15.6
PyQt5-Qt5 5.15.2
PyQt5-sip 12.11.0
PyQtWebEngine 5.15.5
PyQtWebEngine-Qt5 5.15.2
$ pip list | grep -i spyder
pyls-spyder 0.4.0
spyder 5.3.2
spyder-kernels 2.3.2
And I'm not able to uninstall PyQt5:
$ sudo -H pip uninstall pyqt5
Found existing installation: PyQt5 5.15.6
ERROR: Cannot uninstall PyQt5 5.15.6, RECORD file not found. Hint: The package was installed by sip-build.
The last line being printed in red in the terminal.
From that point, I'm not able to find relevant information on how to debug this in order to make spyder work again.
What could I do to fix this error?
Have you looked at this? This is exactly why you shouldn't use sudo pip install. Library versions get borked, inconsistencies arise, and stuff doesn't work.
Use sudo pip (for the last time) to uninstall Spyder and PyQT5, then reinstall the relevant packages using apt. Finally, upgrade Spyder using pip install --user (no sudo!). Everything should work okay after that.
Okay, this fixed it for me:
$ sudo -H pip3 install --force-reinstall spyder
it will probably throw some errors such as:
Attempting uninstall: PyQtWebEngine
Found existing installation: PyQtWebEngine 5.15.5
ERROR: Cannot uninstall PyQtWebEngine 5.15.5, RECORD file not found. Hint: The package was installed by sip-build.
which, if you try to update it individually will show:
$ sudo -H pip3 install -U PyQtWebEngine
Requirement already satisfied: PyQtWebEngine in /usr/lib/python3/dist-packages (5.15.5)
Collecting PyQtWebEngine
Using cached PyQtWebEngine-5.15.6-cp37-abi3-manylinux1_x86_64.whl (230 kB)
Requirement already satisfied: PyQt5>=5.15.4 in /usr/local/lib/python3.10/dist-packages (from PyQtWebEngine) (5.15.7)
Requirement already satisfied: PyQtWebEngine-Qt5>=5.15.0 in /usr/local/lib/python3.10/dist-packages (from PyQtWebEngine) (5.15.2)
Requirement already satisfied: PyQt5-sip<13,>=12.11 in /usr/local/lib/python3.10/dist-packages (from PyQtWebEngine) (12.11.0)
Requirement already satisfied: PyQt5-Qt5>=5.15.0 in /usr/local/lib/python3.10/dist-packages (from PyQt5>=5.15.4->PyQtWebEngine) (5.15.2)
Installing collected packages: PyQtWebEngine
Attempting uninstall: PyQtWebEngine
Found existing installation: PyQtWebEngine 5.15.5
ERROR: Cannot uninstall PyQtWebEngine 5.15.5, RECORD file not found. Hint: The package was installed by sip-build.
Therefore, in that case, run the installation using the --ignore-installed flag on the incriminated package, which should install it without any trouble:
$ sudo -H pip3 install --ignore-installed PyQtWebEngine
Collecting PyQtWebEngine
Using cached PyQtWebEngine-5.15.6-cp37-abi3-manylinux1_x86_64.whl (230 kB)
Collecting PyQtWebEngine-Qt5>=5.15.0
Using cached PyQtWebEngine_Qt5-5.15.2-py3-none-manylinux2014_x86_64.whl (67.5 MB)
Collecting PyQt5>=5.15.4
Using cached PyQt5-5.15.7-cp37-abi3-manylinux1_x86_64.whl (8.4 MB)
Collecting PyQt5-sip<13,>=12.11
Using cached PyQt5_sip-12.11.0-cp310-cp310-manylinux1_x86_64.whl (359 kB)
Collecting PyQt5-Qt5>=5.15.0
Using cached PyQt5_Qt5-5.15.2-py3-none-manylinux2014_x86_64.whl (59.9 MB)
Installing collected packages: PyQtWebEngine-Qt5, PyQt5-Qt5, PyQt5-sip, PyQt5, PyQtWebEngine
Successfully installed PyQt5-5.15.7 PyQt5-Qt5-5.15.2 PyQt5-sip-12.11.0 PyQtWebEngine-5.15.6 PyQtWebEngine-Qt5-5.15.2
After what the above-mentioned error will never show up again. Here as an example:
$ sudo -H pip3 install -U PyQtWebEngine
Requirement already satisfied: PyQtWebEngine in /usr/local/lib/python3.10/dist-packages (5.15.6)
Requirement already satisfied: PyQtWebEngine-Qt5>=5.15.0 in /usr/local/lib/python3.10/dist-packages (from PyQtWebEngine) (5.15.2)
Requirement already satisfied: PyQt5-sip<13,>=12.11 in /usr/local/lib/python3.10/dist-packages (from PyQtWebEngine) (12.11.0)
Requirement already satisfied: PyQt5>=5.15.4 in /usr/local/lib/python3.10/dist-packages (from PyQtWebEngine) (5.15.7)
Requirement already satisfied: PyQt5-Qt5>=5.15.0 in /usr/local/lib/python3.10/dist-packages (from PyQt5>=5.15.4->PyQtWebEngine) (5.15.2)
Repeat the same procedure for all offending packages.
Finally update spyder:
$ sudo -H pip3 install --force-reinstall spyder
And voila. A working spyder should be available.
As an aside: please note the -H option after sudo. This install packages under /usr/local/lib/python3.xx/dist-packages which will normally not conflict with apt system wide installed packages (which are under /usr/lib/python3/dist-packages) and which you definitely don't want to touch another what than with apt actually!
I'm using this to avoid installing the same packages on a user-basis by invoking pip without sudo, which will install them under ~/.local/lib/python3.10/site-packages/ for every user on the machine.

what is the best way to solve some Python packages that could not installed by conda

Recently I am facing a embrassing problem is that some Python packages must install using pip. I have read the pip and conda difference:
What is the difference between pip and conda?
I think many people facing the same problem that when you choose conda, then some package could not using conda install, when you use pip install the pacakge, it could not imported into the local project because the project only could import pakcage installed by conda install command. For example I want to use eyeD3 to read the mp3 meta data, but the package could not installed by conda, I installed the package using pip but could not import in the PyCharm IDE. What is the best way to solve this conflict? Am I missing something? Or I have to switch to pip? is it possible to make conda could install package from pip? Any suggestion is welcome, I want to fetch a guidline. I have tried install package like this in the macOS Big Sur:
/usr/local/anaconda3/envs/pydolphin ⌚ 22:20:21
$ ./bin/python -m pip install eyed3 ‹ruby-2.7.2›
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Requirement already satisfied: eyed3 in ./lib/python3.9/site-packages (0.9.6)
Requirement already satisfied: filetype<2.0.0,>=1.0.7 in ./lib/python3.9/site-packages (from eyed3) (1.0.8)
Requirement already satisfied: coverage[toml]<6.0.0,>=5.3.1 in ./lib/python3.9/site-packages (from eyed3) (5.5)
Requirement already satisfied: deprecation<3.0.0,>=2.1.0 in ./lib/python3.9/site-packages (from eyed3) (2.1.0)
Requirement already satisfied: toml in ./lib/python3.9/site-packages (from coverage[toml]<6.0.0,>=5.3.1->eyed3) (0.10.2)
Requirement already satisfied: packaging in ./lib/python3.9/site-packages (from deprecation<3.0.0,>=2.1.0->eyed3) (21.3)
Requirement already satisfied: pyparsing!=3.0.5,>=2.0.2 in ./lib/python3.9/site-packages (from packaging->deprecation<3.0.0,>=2.1.0->eyed3) (3.0.6)
(base)
still could not import this pakacage in the PyCharm IDE. I could found the package from the env:
/usr/local/anaconda3/envs/pydolphin/lib/python3.9/site-packages/eyed3

Importing matplotlib gives error even though installed

I was hoping someone could help me out.
System is MacOS Catalina.
Python 3.8
IDE: VS
I installed matplotlib using pip install matplotlib which I saw stuck in under python2.7. I uninstalled matplotlib and reinstalled it using pip3 install matplotlib and received the following message:
Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.7/site-packages (from matplotlib) (0.10.0)
Requirement already satisfied: numpy>=1.11 in /usr/local/lib/python3.7/site-packages (from matplotlib) (1.18.1)
Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in /usr/local/lib/python3.7/site-packages (from matplotlib) (2.4.6)
Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.7/site-packages (from matplotlib) (1.1.0)
Requirement already satisfied: python-dateutil>=2.1 in /usr/local/lib/python3.7/site-packages (from matplotlib) (2.8.1)
Requirement already satisfied: six in /Users/apple/Library/Python/3.7/lib/python/site-packages (from cycler>=0.10->matplotlib) (1.13.0)
Requirement already satisfied: setuptools in /usr/local/lib/python3.7/site-packages (from kiwisolver>=1.0.1->matplotlib) (46.0.0)
However, when I try to run my .py file with 'import matplotlib' it gives this error:
import matplotlib as mpl
ModuleNotFoundError: No module named 'matplotlib'
I've tried searching different sources for the solution but I am now stuck.
You are mostly running your python script with the command python your_file.py, try running as python3 your_file.py in your terminal. pip3 installs packages under python3, not the default python2.
This is because I believe your mac terminal uses python 2.x by default, therefore the command python uses python 2.x version and python3 uses 3.x version that is available to execute the files. So if you want to install any packages under python 2.x you use pip as the command and to install packages under python 3.x you use pip3 as the command

How to fix "conda: not found" error in Ubuntu

I was trying to download the graphviz library via conda in Jupyter Notebook (later I checked in terminal it goes in the same way). Unfortunately, I see the warning conda not found.
Firstly, I wrote this (in Jupyter):
!pip install conda --user
and got:
Requirement already satisfied: conda in /home/user_name/.local/lib/python3.6/site-packages (4.3.16)
Requirement already satisfied: pycosat>=0.6.1 in /home/user_name/.local/lib/python3.6/site-packages (from conda) (0.6.3)
Requirement already satisfied: ruamel.yaml>=0.11.14 in /home/user_name/.local/lib/python3.6/site-packages (from conda) (0.16.1)
Requirement already satisfied: requests>=2.12.4 in /usr/lib/python3/dist-packages (from conda) (2.18.4)
Requirement already satisfied: ruamel.yaml.clib>=0.1.2; platform_python_implementation == "CPython" and python_version < "3.8" in /home/user_name/.local/lib/python3.6/site-packages (from ruamel.yaml>=0.11.14->conda) (0.1.2)
After, I wrote next:
!conda install python-graphviz --yes
but it showed:
/bin/sh: 1: conda: not found
How can I fix this error to use conda?
conda is not a pip package. I think some backlevel version once got released on PyPI, but I wouldn't try to use that nowadays.
Install the Miniconda package to use conda:
https://docs.conda.io/en/latest/miniconda.html
And tell pip to remove that conda package it installed.

In Amazon Linux, unable to install pandas and numpy in virtualenv

I have been trying to install pandas and numpy in my virtualenv. The box is an Amazon Linux AMI instance. This is my command log:
Activate venv and check packages
[ec2-user#ip-0-0-0-0 www]$ source datasci_venv/bin/activate
(datasci_venv) [ec2-user#ip-0-0-0-0 www]$ pip freeze
Django==1.11
requests==2.20.1
Then using pip install to install pandas and numpy. Note that when installing Django and requests, they were successfully installed:
(datasci_venv) [ec2-user#ip-0-0-0-0 www]$ pip install pandas && pip install numpy
Collecting pandas
Using cached https://files.pythonhosted.org/packages/e1/d8/feeb346d41f181e83fba45224ab14a8d8af019b48af742e047f3845d8cff/pandas-0.23.4-cp36-cp36m-manylinux1_x86_64.whl
Requirement already satisfied: pytz>=2011k in ./datasci_venv/lib/python3.6/dist-packages (from pandas) (2018.7)
Collecting numpy>=1.9.0 (from pandas)
Using cached https://files.pythonhosted.org/packages/ff/7f/9d804d2348471c67a7d8b5f84f9bc59fd1cefa148986f2b74552f8573555/numpy-1.15.4-cp36-cp36m-manylinux1_x86_64.whl
Requirement already satisfied: python-dateutil>=2.5.0 in ./datasci_venv/lib/python3.6/dist-packages (from pandas) (2.7.5)
Requirement already satisfied: six>=1.5 in ./datasci_venv/lib/python3.6/dist-packages (from python-dateutil>=2.5.0->pandas) (1.11.0)
Installing collected packages: numpy, pandas
Successfully installed numpy-1.15.4 pandas-0.23.4
Collecting numpy
Using cached https://files.pythonhosted.org/packages/ff/7f/9d804d2348471c67a7d8b5f84f9bc59fd1cefa148986f2b74552f8573555/numpy-1.15.4-cp36-cp36m-manylinux1_x86_64.whl
tabula-py 1.3.0 requires pandas, which is not installed.
Installing collected packages: numpy
Successfully installed numpy-1.15.4
So it seems that they are correctly installed, since there are no error messages. However, when I check my packages again, they are not there:
(datasci_venv) [ec2-user#ip-0-0-0-0 www]$ pip freeze
Django==1.11
requests==2.20.1
And hence I decided to check which command I am using but it says I'm using the programs in the venv:
(datasci_venv) [ec2-user#ip-0-0-0-0 www]$ which pip
/var/www/datasci_venv/bin/pip
(datasci_venv) [ec2-user#ip-0-0-0-0 www]$ which python
/var/www/datasci_venv/bin/python
(datasci_venv) [ec2-user#ip-0-0-0-0 www]$
Hence, I'm kinda lost on what to do and check. Any help or solution is appreciated.
I had the same issue, it appears that pip is installing the package in the lib64 folder of your virtualenv rather than on the lib folder. You need to force the target folder by doing this:
pip install --target datasci_venv/lib/python3.6/dist-packages/ numpy
Hope this help!

Categories

Resources