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

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

问题描述

在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

在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.

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

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