问题描述
在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.
要测试nltk
和scikit_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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!