1

Long story short, numpy gave me error when I was importing matplotlib, so I wanted to pip uninstall numpy and reinstall it. but failed to fully uninstall numpy.

RuntimeError                              Traceback (most recent call last)
RuntimeError: module compiled against API version 0xe but this version of numpy is 0xd

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
/tmp/ipykernel_26902/2971697587.py in <module>
----> 1 import matplotlib

~/.local/lib/python3.7/site-packages/matplotlib/__init__.py in <module>
    105 # cbook must import matplotlib only within function
    106 # definitions, so it is safe to import from it here.
--> 107 from . import _api, cbook, docstring, rcsetup
    108 from matplotlib.cbook import MatplotlibDeprecationWarning, sanitize_sequence
    109 from matplotlib.cbook import mplDeprecation  # deprecated

~/.local/lib/python3.7/site-packages/matplotlib/rcsetup.py in <module>
     24 from matplotlib import _api, animation, cbook
     25 from matplotlib.cbook import ls_mapper
---> 26 from matplotlib.colors import Colormap, is_color_like
     27 from matplotlib.fontconfig_pattern import parse_fontconfig_pattern
     28 from matplotlib._enums import JoinStyle, CapStyle

~/.local/lib/python3.7/site-packages/matplotlib/colors.py in <module>
     80 import matplotlib as mpl
     81 import numpy as np
---> 82 from matplotlib import _api, cbook, scale
     83 from ._color_data import BASE_COLORS, TABLEAU_COLORS, CSS4_COLORS, XKCD_COLORS
     84 

~/.local/lib/python3.7/site-packages/matplotlib/scale.py in <module>
     16 import matplotlib as mpl
     17 from matplotlib import _api, docstring
---> 18 from matplotlib.ticker import (
     19     NullFormatter, ScalarFormatter, LogFormatterSciNotation, LogitFormatter,
     20     NullLocator, LogLocator, AutoLocator, AutoMinorLocator,

~/.local/lib/python3.7/site-packages/matplotlib/ticker.py in <module>
    177 import matplotlib as mpl
    178 from matplotlib import _api, cbook
--> 179 from matplotlib import transforms as mtransforms
    180 
    181 _log = logging.getLogger(__name__)

~/.local/lib/python3.7/site-packages/matplotlib/transforms.py in <module>
     44 
     45 from matplotlib import _api
---> 46 from matplotlib._path import (
     47     affine_transform, count_bboxes_overlapping_bbox, update_path_extents)
     48 from .path import Path

ImportError: numpy.core.multiarray failed to import

I decided to uninstall and reinstall after the solutions found online doesn't work. (ImportError: numpy.core.multiarray failed to import)

pi@raspberrypi:~ $ pip uninstall numpy
Uninstalling numpy-1.16.6:
  Would remove:
    /home/pi/.local/bin/f2py
    /home/pi/.local/bin/f2py2
    /home/pi/.local/bin/f2py2.7
    /home/pi/.local/lib/python2.7/site-packages/numpy-1.16.6.dist-info/*
    /home/pi/.local/lib/python2.7/site-packages/numpy/*
Proceed (y/n)? y
  Successfully uninstalled numpy-1.16.6
pi@raspberrypi:~ $ pip install numpy
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Requirement already satisfied: numpy in /usr/lib/python2.7/dist-packages (1.16.2)

supposing the first command already uninstalled numpy, why was requirement already satisfied? I tried both pip uninstall and pip3 uninstall. then also went into python and python3 to import the module as double check to see if the module is still installed. and the module was imported successfully. also in the /usr/lib/python2.7/dist-packages folder, numpy was still there. what is the problem? how can I successfully uninstall and reinstall numpy?

Edit: I manually went into the dist-packages directory of all versions of python, and rm all the numpy related files. then reinstallation works.

  • Could you mention which version of python you are using? Also, where are you running your programs on (i saw raspberry pi, but any software running the code?) – Alireza Ghaffarian Oct 22 '21 at 01:06
  • It appears you're mixing Python 2 and 3, as the error message clearly mentions numpy being installed for Python 2, even though you appear to want to install it for 3? – Grismar Oct 22 '21 at 01:08
  • @AlirezaGhaffarian I did first python 2 then python3. ran both version of the uninstall/install commands, and checked both versions' folders. sorry for the confusion. I am running it on a raspberrypi4, it currently has no python code running in the background when I'm doing this. –  Oct 22 '21 at 02:16
  • @Grismar I ran the pip command for both python 2 and python 3. and tested/verified with both version. sorry for the confusion in the initial post. –  Oct 22 '21 at 02:18
  • "supposing the first command already uninstalled numpy, why was requirement already satisfied?" Notice how the version you uninstalled is `numpy-1.16.6`, but the one satisfying the requirement is `numpy in /usr/lib/python2.7/dist-packages (1.16.2)`? – Karl Knechtel Oct 22 '21 at 03:26

1 Answers1

0

You can delete the files with this commands

rm -rf f2py
rm -rf 2py2
rm -rf numpy-1.16.6.dist-info/*
rm -rf numpy/*

or only:

  rm  f2py
    rm  2py2
    rm  numpy-1.16.6.dist-info/*
    rm  numpy/*
User1738
  • 18
  • 7