长话短说,当我导入matplotlib时,numpy给了我一个错误,所以我想安装pip uninstall numpy
并重新安装它。但未能完全卸载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
我决定卸载和重新安装后,发现解决方案在网上不工作。(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)
假设第一个命令已经卸载了numpy,为什么需求已经满足了?我尝试了pip uninstall
和pip3 uninstall
。然后也进入python
和python3
导入模块,再次检查模块是否还安装。模块导入成功。同样在/usr/lib/python2.7/dist-packages
文件夹中,numpy
仍然在那里。有什么问题吗?如何成功卸载和重新安装numpy?
dist-packages
目录,rm
所有numpy相关文件。然后重新安装。
您可以使用以下命令删除文件
rm -rf f2py
rm -rf 2py2
rm -rf numpy-1.16.6.dist-info/*
rm -rf numpy/*
或只有:
rm f2py
rm 2py2
rm numpy-1.16.6.dist-info/*
rm numpy/*