如何修复:No module named NumPy

如何修复:No module named NumPy

在这篇文章中,我们将讨论如何使用Python修复名为numpy的模块。

Numpy是一个用于数组处理的模块。当你的环境中没有NumPy库,即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数组并显示

#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])

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程