简体   繁体   English

如何检查我使用的是哪个版本的 NumPy?

[英]How do I check which version of NumPy I'm using?

如何检查我使用的是哪个版本的 NumPy?

import numpy
numpy.version.version
>> 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__)"

Run:跑步:

pip list

Should generate a list of packages.应该生成一个包列表。 Scroll through to numpy.滚动到 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)
....

You can also check if your version is using MKL with:您还可以通过以下方式检查您的版本是否使用 MKL:

import numpy
numpy.show_config()

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

pip freeze | grep 'numpy'

You can try this:你可以试试这个:

pip show numpy pip 显示 numpy

If you're using NumPy from the Anaconda distribution , then you can just do:如果您使用Anaconda 发行版中的 NumPy ,那么您可以这样做:

$ conda list | grep numpy
numpy     1.11.3     py35_0

This gives the Python version as well.这也给出了Python版本。


If you want something fancy, then use numexpr如果你想要一些花哨的东西,那么使用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)
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

You can get numpy version using Terminal or a Python code.您可以使用终端或 Python 代码获取 numpy 版本。

In a Terminal (bash) using Ubuntu:在使用 Ubuntu 的终端 (bash) 中:

pip list | grep numpy

In python 3.6.7, this code shows the numpy version:在 python 3.6.7 中,此代码显示了 numpy 版本:

import numpy
print (numpy.version.version)

If you insert this code in the file shownumpy.py, you can compile it:如果你在showumpy.py文件中插入这段代码,你可以编译它:

python shownumpy.py

or要么

python3 shownumpy.py

I've got this output:我有这个输出:

1.16.1

For Python 3.X print syntax:对于 Python 3.X 打印语法:

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

Or要么

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

In a Python shell:在 Python 外壳中:

>>> help()
help> numpy

Just a slight solution change for checking the version of numpy with Python,使用 Python 检查 numpy 的版本只是一个轻微的解决方案更改,

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我在 PyCharm 中的项目目前正在运行版本

1.17.4

Simply简单地

pip show numpy

and for pip3和 pip3

pip3 show numpy

Works on both windows and linux.适用于 windows 和 linux。 Should work on mac too if you are using pip.如果您使用 pip,也应该在 mac 上工作。

Pure Python line that can be executed from the terminal (both 2.X and 3.X versions):可以从终端执行的纯 Python 行(2.X 和 3.X 版本):

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

If you are already inside Python, then:如果您已经在 Python 中,那么:

import numpy
print(numpy.version.version)

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:知道你运行的numpy版本是很好的,但严格来说,如果你只需要在你的系统上有特定的版本,你可以这样写:

pip install numpy==1.14.3 and this will install the version you need and uninstall other versions of numpy . pip install numpy==1.14.3这将安装您需要的版本并卸载其他版本的numpy

For Windows对于 Windows

pip list | FINDSTR numpy

For Linux对于 Linux

pip list | grep numpy

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM