如何检查哪个版本的nltk, scikit学习安装?

时间:2022-07-02 07:01:34

In shell script I am checking whether this packages are installed or not, if not installed then install it. So withing shell script:

在shell脚本中,我正在检查这个包是否已经安装,如果没有安装,那么请安装它。所以在shell脚本:

import nltk
echo nltk.__version__

but it stops shell script at import line

但是它在导入行停止shell脚本

in linux terminal tried to see in this manner:

在linux终端尝试这样看:

which nltk

which gives nothing thought it is installed.

没有任何想法,它被安装。

Is there any other way to verify this package installation in shell script, if not installed, also install it.

是否有其他方法来验证这个包安装在shell脚本中,如果没有安装,也要安装它。

6 个解决方案

#1


74  

import nltk is Python syntax, and as such won't work in a shell script.

导入nltk是Python语法,因此在shell脚本中无法工作。

To test the version of nltk and scikit_learn, you can write a Python script and run it. Such a script may look like

要测试nltk和scikit_learn的版本,您可以编写一个Python脚本并运行它。这样的脚本可能看起来像

import nltk
import sklearn

print('The nltk version is {}.'.format(nltk.__version__))
print('The scikit-learn version is {}.'.format(sklearn.__version__))

# The nltk version is 3.0.0.
# The scikit-learn version is 0.15.2.

Note that not all Python packages are guaranteed to have a __version__ attribute, so for some others it may fail, but for nltk and scikit-learn at least it will work.

注意,并不是所有的Python包都保证具有__version__属性,所以对于其他一些包,它可能会失败,但是对于nltk和scikit-learn,它至少可以工作。

#2


23  

Try this:

试试这个:

$ python -c "import nltk; print nltk.__version__"

#3


3  

For checking the version of scikit-learn in shell script, if you have pip installed, you can try this command

要检查shell脚本中的scikit-learn版本,如果已经安装了pip,可以尝试这个命令

pip freeze | grep scikit-learn
scikit-learn==0.17.1

Hope it helps!

希望它可以帮助!

#4


2  

You can find NLTK version simply by doing:

您可以通过以下操作找到NLTK版本:

In [1]: import nltk

In [2]: nltk.__version__
Out[2]: '3.2.5'

And similarly for scikit-learn,

同样对于scikit-learn,

In [3]: import sklearn

In [4]: sklearn.__version__
Out[4]: '0.19.0'

I'm using python3 here.

我在这里使用python3。

#5


2  

You can simply try

你可以试试

pip3 list

and that would give you a list like this

它会给你一个这样的列表

bleach (2.0.0)
colorama (0.3.9)
cycler (0.10.0)
decorator (4.1.2)
entrypoints (0.2.3)
enum34 (1.1.6)
graphviz (0.8)
html5lib (0.999999999)
ipykernel (4.6.1)
ipython (6.1.0)
ipython-genutils (0.2.0)
ipywidgets (7.0.0)
jedi (0.10.2)
Jinja2 (2.9.6)
  ..........
PyYAML (3.12)
pyzmq (16.0.2)
qtconsole (4.3.1)
scikit-learn (0.19.0)   <------
scipy (0.19.1)
setuptools (36.4.0)
simplegeneric (0.8.1)
   .......

You can visually scan the list to find the version of all installed packages... the list is in alphabetical order, so it is easy to scan.

您可以可视化地扫描列表,找到所有已安装包的版本……这个列表是按字母顺序排列的,所以很容易扫描。

#6


-1  

In my machine which is ubuntu 14.04 with python 2.7 installed, if I go here,

我的机器是ubuntu 14。04安装了python 2。7,如果我到这里,

/usr/local/lib/python2.7/dist-packages/nltk/

there is a file called

有一个文件叫做

VERSION.

的版本。

If I do a cat VERSION it prints 3.1, which is the NLTK version installed.

如果我做一个cat版本,它会打印3.1,也就是安装的NLTK版本。

#1


74  

import nltk is Python syntax, and as such won't work in a shell script.

导入nltk是Python语法,因此在shell脚本中无法工作。

To test the version of nltk and scikit_learn, you can write a Python script and run it. Such a script may look like

要测试nltk和scikit_learn的版本,您可以编写一个Python脚本并运行它。这样的脚本可能看起来像

import nltk
import sklearn

print('The nltk version is {}.'.format(nltk.__version__))
print('The scikit-learn version is {}.'.format(sklearn.__version__))

# The nltk version is 3.0.0.
# The scikit-learn version is 0.15.2.

Note that not all Python packages are guaranteed to have a __version__ attribute, so for some others it may fail, but for nltk and scikit-learn at least it will work.

注意,并不是所有的Python包都保证具有__version__属性,所以对于其他一些包,它可能会失败,但是对于nltk和scikit-learn,它至少可以工作。

#2


23  

Try this:

试试这个:

$ python -c "import nltk; print nltk.__version__"

#3


3  

For checking the version of scikit-learn in shell script, if you have pip installed, you can try this command

要检查shell脚本中的scikit-learn版本,如果已经安装了pip,可以尝试这个命令

pip freeze | grep scikit-learn
scikit-learn==0.17.1

Hope it helps!

希望它可以帮助!

#4


2  

You can find NLTK version simply by doing:

您可以通过以下操作找到NLTK版本:

In [1]: import nltk

In [2]: nltk.__version__
Out[2]: '3.2.5'

And similarly for scikit-learn,

同样对于scikit-learn,

In [3]: import sklearn

In [4]: sklearn.__version__
Out[4]: '0.19.0'

I'm using python3 here.

我在这里使用python3。

#5


2  

You can simply try

你可以试试

pip3 list

and that would give you a list like this

它会给你一个这样的列表

bleach (2.0.0)
colorama (0.3.9)
cycler (0.10.0)
decorator (4.1.2)
entrypoints (0.2.3)
enum34 (1.1.6)
graphviz (0.8)
html5lib (0.999999999)
ipykernel (4.6.1)
ipython (6.1.0)
ipython-genutils (0.2.0)
ipywidgets (7.0.0)
jedi (0.10.2)
Jinja2 (2.9.6)
  ..........
PyYAML (3.12)
pyzmq (16.0.2)
qtconsole (4.3.1)
scikit-learn (0.19.0)   <------
scipy (0.19.1)
setuptools (36.4.0)
simplegeneric (0.8.1)
   .......

You can visually scan the list to find the version of all installed packages... the list is in alphabetical order, so it is easy to scan.

您可以可视化地扫描列表,找到所有已安装包的版本……这个列表是按字母顺序排列的,所以很容易扫描。

#6


-1  

In my machine which is ubuntu 14.04 with python 2.7 installed, if I go here,

我的机器是ubuntu 14。04安装了python 2。7,如果我到这里,

/usr/local/lib/python2.7/dist-packages/nltk/

there is a file called

有一个文件叫做

VERSION.

的版本。

If I do a cat VERSION it prints 3.1, which is the NLTK version installed.

如果我做一个cat版本,它会打印3.1,也就是安装的NLTK版本。