如何检查电脑是否安装了python-python-如何检查安装了scikit的nltk版本?

python-如何检查安装了scikit的nltk版本?

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

import nltk

echo nltk.__version__

但它在import行处停止了shell脚本

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

which nltk

没有任何东西以为已安装。

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

7个解决方案

102 votes

__version__是Python语法,因此无法在Shell脚本中使用。

要测试__version__和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.

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

Ffisegydd answered 2019-10-05T23:19:43Z

25 votes

试试这个:

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

Aaron answered 2019-10-05T23:20:02Z

7 votes

你可以简单地尝试

pip3 list

那会给你这样的清单

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)

.......

您可以直观地扫描列表以查找所有已安装软件包的版本...该列表按字母顺序排列,因此易于扫描。

agcala answered 2019-10-05T23:20:40Z

4 votes

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

pip freeze | grep scikit-learn

scikit-learn==0.17.1

希望能帮助到你!

prabhat answered 2019-10-05T23:21:05Z

4 votes

您只需执行以下操作即可找到NLTK版本:

In [1]: import nltk

In [2]: nltk.__version__

Out[2]: '3.2.5'

对于scikit-learn,

In [3]: import sklearn

In [4]: sklearn.__version__

Out[4]: '0.19.0'

我在这里使用python3。

kmario23 answered 2019-10-05T23:21:43Z

0 votes

您可以按照以下方式从python笔记本单元格中进行检查

!pip install --upgrade nltk # needed if nltk is not already installed

import nltk

print('The nltk version is {}.'.format(nltk.__version__))

print('The nltk version is '+ str(nltk.__version__))

#!pip install --upgrade sklearn # needed if sklearn is not already installed

import sklearn

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

print('The scikit-learn version is '+ str(nltk.__version__))

Orhan Celik answered 2019-10-05T23:22:08Z

-1 votes

在我的安装了python 2.7的ubuntu 14.04机器中,如果我去这里,

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

有一个名为

cat VERSION。

如果我执行cat VERSION,它会打印3.1,这是已安装的NLTK版本。

samsamara answered 2019-10-05T23:22:52Z

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值