如何检查scikit学习安装了哪个版本的nltk? [英] how to check which version of nltk, scikit learn installed?

查看:92
本文介绍了如何检查scikit学习安装了哪个版本的nltk?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在shell脚本中,我正在检查是否已安装此软件包,如果未安装,请先安装它.因此,使用shell脚本:

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

import nltk
echo nltk.__version__

但是它会在import行停止shell脚本

but it stops shell script at import line

在linux终端中尝试以这种方式查看:

in linux terminal tried to see in this manner:

which nltk

这并没有说明已安装.

是否还有其他方法可以在shell脚本中验证此软件包的安装,如果未安装,请同时安装.

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

推荐答案

import nltk是Python语法,因此无法在Shell脚本中使用.

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

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

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

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.

请注意,并非所有Python软件包都保证具有__version__属性,因此对于某些其他软件包可能会失败,但是对于nltk和scikit-learn而言,至少它会起作用.

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.

这篇关于如何检查scikit学习安装了哪个版本的nltk?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆