How to Check Which Version of Nltk, Scikit Learn Installed

how to check which version of nltk, scikit learn installed?

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

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.

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.

Installing scikit-learn with pip: are there multiple python versions installed on my computer?

First, use python -v to check default python installation. If it is the version you are using, continue with python instead of python3.

Now run python3 -m pip install scikit-learn
If you are on a Mac, DO NOT DELETE PYTHON 2.7. It is needed for your system to run properly.

How do I check the versions of Python modules?

Use pip instead of easy_install.

With pip, list all installed packages and their versions via:

pip freeze

On most Linux systems, you can pipe this to grep (or findstr on Windows) to find the row for the particular package you're interested in.



Linux:

pip freeze | grep lxml

lxml==2.3

Windows:

pip freeze | findstr lxml

lxml==2.3


For an individual module, you can try the __version__ attribute. However, there are modules without it:

python -c "import requests; print(requests.__version__)"
2.14.2

python -c "import lxml; print(lxml.__version__)"

Traceback (most recent call last):

File "<string>", line 1, in <module>

AttributeError: 'module' object has no attribute 'version'

Lastly, as the commands in your question are prefixed with sudo, it appears you're installing to the global python environment. I strongly advise to take look into Python virtual environment managers, for example virtualenvwrapper.

Difference between scikit-learn and sklearn

You might need to reinstall numpy. It doesn't seem to have installed correctly.

sklearn is how you type the scikit-learn name in python.

Also, try running the standard tests in scikit-learn and check the output. You will have detailed error information there.

Do you have nosetests installed? Try: nosetests -v sklearn. You type this in bash, not in the python interpreter.

Scikit-Learn Version Not Updating

By prepending sudo in the pip call, you are referring to the system's python instead of a virtualenv one.

If you are within a virtualenv, simply do pip install -U scikit-learn (i.e. drop the sudo).

EDIT:
OP installed sklearn with apt, sudo apt remove --purge python-sklearn and reinstall sklearn with pip solved it.



Related Topics



Leave a reply



Submit