如何查看我使用的NumPy版本?

问题:如何查看我使用的NumPy版本?

如何查看我使用的NumPy版本?

(仅供参考,此问题已被编辑,因为问题和答案都不是特定于平台的。)

How can I check which version of NumPy I’m using?

(FYI this question has been edited because both the question and answer are not platform specific.)


回答 0

import numpy
numpy.version.version
import numpy
numpy.version.version

回答 1

>> import numpy
>> print numpy.__version__
>> import numpy
>> print numpy.__version__

回答 2

从命令行,您可以简单地发出:

python -c "import numpy; print(numpy.version.version)"

要么:

python -c "import numpy; print(numpy.__version__)"

From the command line, you can simply issue:

python -c "import numpy; print(numpy.version.version)"

Or:

python -c "import numpy; print(numpy.__version__)"

回答 3

跑:

pip list

应生成软件包列表。滚动到numpy。

...
nbpresent (3.0.2)
networkx (1.11)
nltk (3.2.2)
nose (1.3.7)
notebook (5.0.0)
numba (0.32.0+0.g139e4c6.dirty)
numexpr (2.6.2)
numpy (1.11.3) <--
numpydoc (0.6.0)
odo (0.5.0)
openpyxl (2.4.1)
pandas (0.20.1)
pandocfilters (1.4.1)
....

Run:

pip list

Should generate a list of packages. Scroll through to numpy.

...
nbpresent (3.0.2)
networkx (1.11)
nltk (3.2.2)
nose (1.3.7)
notebook (5.0.0)
numba (0.32.0+0.g139e4c6.dirty)
numexpr (2.6.2)
numpy (1.11.3) <--
numpydoc (0.6.0)
odo (0.5.0)
openpyxl (2.4.1)
pandas (0.20.1)
pandocfilters (1.4.1)
....

回答 4

您还可以通过以下方式检查您的版本是否在使用MKL:

import numpy
numpy.show_config()

You can also check if your version is using MKL with:

import numpy
numpy.show_config()

回答 5

我们可以pip freeze用来获取任何Python软件包版本,而无需打开Python shell。

pip freeze | grep 'numpy'

We can use pip freeze to get any Python package version without opening the Python shell.

pip freeze | grep 'numpy'

回答 6

如果您正在使用Anaconda发行版中的NumPy,则可以执行以下操作:

$ conda list | grep numpy
numpy     1.11.3     py35_0

这也给出了Python版本。


如果您想要一些花哨的东西,请使用 numexpr

它提供了很多信息,如下所示:

In [692]: import numexpr

In [693]: numexpr.print_versions()
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Numexpr version:   2.6.2
NumPy version:     1.13.3
Python version:    3.6.3 |Anaconda custom (64-bit)|
                   (default, Oct 13 2017, 12:02:49)
[GCC 7.2.0]
Platform:          linux-x86_64
AMD/Intel CPU?     True
VML available?     False
Number of threads used by default: 8 (out of 48 detected cores)
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

If you’re using NumPy from the Anaconda distribution, then you can just do:

$ conda list | grep numpy
numpy     1.11.3     py35_0

This gives the Python version as well.


If you want something fancy, then use numexpr

It gives lot of information as you can see below:

In [692]: import numexpr

In [693]: numexpr.print_versions()
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Numexpr version:   2.6.2
NumPy version:     1.13.3
Python version:    3.6.3 |Anaconda custom (64-bit)|
                   (default, Oct 13 2017, 12:02:49)
[GCC 7.2.0]
Platform:          linux-x86_64
AMD/Intel CPU?     True
VML available?     False
Number of threads used by default: 8 (out of 48 detected cores)
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

回答 7

您可以尝试以下方法:

点显示numpy

You can try this:

pip show numpy


回答 8

您可以使用Terminal或Python代码获取numpy版本。

在使用Ubuntu的终端机(bash)中:

pip list | grep numpy

在python 3.6.7中,此代码显示了numpy版本:

import numpy
print (numpy.version.version)

如果将此代码插入到showumpy.py文件中,则可以对其进行编译:

python shownumpy.py

要么

python3 shownumpy.py

我有以下输出:

1.16.1

You can get numpy version using Terminal or a Python code.

In a Terminal (bash) using Ubuntu:

pip list | grep numpy

In python 3.6.7, this code shows the numpy version:

import numpy
print (numpy.version.version)

If you insert this code in the file shownumpy.py, you can compile it:

python shownumpy.py

or

python3 shownumpy.py

I’ve got this output:

1.16.1

回答 9

import numpy
print numpy.__version__
import numpy
print numpy.__version__

回答 10

对于Python 3.X打印语法:

python -c "import numpy; print (numpy.version.version)"

要么

python -c "import numpy; print(numpy.__version__)"

For Python 3.X print syntax:

python -c "import numpy; print (numpy.version.version)"

Or

python -c "import numpy; print(numpy.__version__)"

回答 11

只需对解决方案进行一点更改,即可使用Python检查numpy的版本,

import numpy as np 
print("Numpy Version:",np.__version__)

要么,

import numpy as np
print("Numpy Version:",np.version.version)

我在PyCharm中的项目当前正在运行版本

1.17.4

Just a slight solution change for checking the version of numpy with Python,

import numpy as np 
print("Numpy Version:",np.__version__)

Or,

import numpy as np
print("Numpy Version:",np.version.version)

My projects in PyCharm are currently running version

1.17.4

回答 12

在Python Shell中:

>>> help()
help> numpy

In a Python shell:

>>> help()
help> numpy

回答 13

可以从终端执行的纯Python行(2.X和3.X版本):

python -c "import numpy; print(numpy.version.version)"

如果您已经在Python中,则:

import numpy
print(numpy.version.version)

Pure Python line that can be executed from the terminal (both 2.X and 3.X versions):

python -c "import numpy; print(numpy.version.version)"

If you are already inside Python, then:

import numpy
print(numpy.version.version)

回答 14

很高兴知道numpy您运行的版本,但是严格来说,如果您只需要在系统上具有特定版本,则可以这样编写:

pip install numpy==1.14.3 这将安装您需要的版本,并卸载其他版本的numpy

It is good to know the version of numpy you run, but strictly speaking if you just need to have specific version on your system you can write like this:

pip install numpy==1.14.3 and this will install the version you need and uninstall other versions of numpy.