如何修复:没有名为 NumPy 的模块
在本文中,我们将讨论如何使用Python修复名为 numpy 的 No 模块。
Numpy 是一个用于数组处理的模块。当您的环境中没有 NumPy 库时,将出现错误“No module named numpy”,即未安装 NumPy 模块或由于某些中断而导致安装的某些部分不完整。我们将讨论如何克服这个错误。
在Python中,我们将使用 pip函数来安装任何模块
句法:
pip install module_name
示例:如何安装 NumPy
pip install numpy
输出:
Collecting numpy
Downloading numpy-3.2.0.tar.gz (281.3 MB)
|████████████████████████████████| 281.3 MB 9.7 kB/s
Collecting py4j==0.10.9.2
Downloading py4j-0.10.9.2-py2.py3-none-any.whl (198 kB)
|████████████████████████████████| 198 kB 52.8 MB/s
Building wheels for collected packages: numpy
Building wheel for numpy (setup.py) … done
Created wheel for numpy: filename=numpy-3.2.0-py2.py3-none-any.whl size=281805912 sha256=c6c9edb963f9a25f31d11d88374ce3be6b3c73ac73ac467ef40b51b5f4eca737
Stored in directory: /root/.cache/pip/wheels/0b/de/d2/9be5d59d7331c6c2a7c1b6d1a4f463ce107332b1ecd4e80718
Successfully built numpy
Installing collected packages: py4j, numpy
Successfully installed py4j-0.10.9.2 numpy-3.2.0
我们可以通过再次输入相同的命令来验证,然后输出将是:
输出:
Requirement already satisfied: numpy in /usr/local/lib/python3.7/dist-packages (1.1.5)
要在我们的环境中获得像当前版本一样的 numpy 描述,我们可以使用 show 命令
示例:获取 NumPy 描述
pip show numpy
输出:
Name: numpy
Version: 1.19.5
Summary: NumPy is the fundamental package for array computing with Python.
Home-page: https://www.numpy.org
Author: Travis E. Oliphant et al.
Author-email: None
License: BSD
Location: /usr/local/lib/python3.7/dist-packages
Requires:
Required-by: yellowbrick, xgboost, xarray, wordcloud, torchvision, torchtext, tifffile, thinc, Theano-PyMC, tensorflow, tensorflow-probability, tensorflow-hub, tensorflow-datasets, tensorboard, tables, statsmodels, spacy, sklearn-pandas, seaborn, scs, scipy, scikit-learn, scikit-image, resampy, qdldl, PyWavelets, python-louvain, pystan, pysndfile, pymc3, pyerfa, pyemd, pyarrow, plotnine, patsy, pandas, osqp, opt-einsum, opencv-python, opencv-contrib-python, numexpr, numba, nibabel, netCDF4, moviepy, mlxtend, mizani, missingno, matplotlib, matplotlib-venn, lightgbm, librosa, Keras-Preprocessing, kapre, jpeg4py, jaxlib, jax, imgaug, imbalanced-learn, imageio, hyperopt, holoviews, h5py, gym, gensim, folium, fix-yahoo-finance, fbprophet, fastprogress, fastdtw, fastai, fa2, ecos, daft, cvxpy, cufflinks, cmdstanpy, cftime, Bottleneck, bokeh, blis, autograd, atari-py, astropy, arviz, altair, albumentations
所有其他操作系统和软件的安装保持不变,只是平台发生了变化。如果我们的安装成功,任何 NumPy 代码都可以正常工作
示例:创建 NumPy 数组并显示的程序
Python3
#import module
import numpy
# create an numpy array with 5 elements
data = numpy.array([1, 2, 3, 4, 5])
# display
data
输出:
array([1, 2, 3, 4, 5])