4

How do I check in Ubuntu 16.04, which version of aiohttp is installed?

This works

 python -V
 Python 2.7.12    

but this doesn't

aiohttp -V
-bash: aiohttp: command not found
GoodtheBest
  • 57
  • 2
  • 6

3 Answers3

4

A general way that works for pretty much any module, regardless of how it was installed is the following:

$ python -c "import aiohttp; print(aiohttp.__version__)"
2.3.3

What this does is run a Python interpreter, import the module, and print the module's __version__ attribute. Pretty much all Python libraries define __version__, so this should be very general (especially since __version__ is recommended by PEP8).

This is analogous to:

$ python
>>> import aiohttp
>>> print(aiohttp.__version__)
2.3.3
>>> quit()
Alex Huszagh
  • 13,272
  • 3
  • 39
  • 67
  • Traceback (most recent call last): File "", line 1, in ImportError: No module named aiohttp Doest that mean aiohttp is not installed at all? – GoodtheBest Mar 19 '18 at 01:57
  • @GoodtheBest Yes that does. This requires that the module be installed. You must use the correct Python interpreter. If your default python installation is, for example, `python3`, substitute `python` with `python3`. – Alex Huszagh Mar 19 '18 at 01:58
  • I've this version of Python 2.7.12 , how should I substitute in the command line suggested by you? – GoodtheBest Mar 19 '18 at 02:01
  • @GoodtheBest aiohttp is only supported (at least for recent-ish versions) for Python 3.x, Python 3.5.x specifically. 2.7 won't work. You need a new Python installation. See [here](https://aiohttp.readthedocs.io/en/stable/#dependencies). – Alex Huszagh Mar 19 '18 at 02:02
  • Thanks Alexander Huszagh appreciate it. – GoodtheBest Mar 19 '18 at 02:03
  • aiohttp.__version__ works for me. – bbasaran Sep 11 '22 at 20:32
0

It is not a command line tool. That's why it says command not found. It is a pip package. So, you can do this:

pip freeze | grep aiohttp

to find the version.

Jahongir Rahmonov
  • 13,083
  • 10
  • 47
  • 91
0

If you installed it with pip (>= 1.3), use

$ pip show aiohttp

For older versions,

$ pip freeze | grep aiohttp

pip freeze has the advantage that it shows editable VCS checkout versions correctly, while pip show does not.

... or

$ pip list | grep aiohttp
$ pip list --outdated | grep aiohttp

(--outdated to see Current and Latest versions of the packages).

Credits: Find which version of package is installed with pip

Note: the property __version__ comes in handy, but it is not always available. This is an issue that evolved with time. YMMV.

  • I know that `__version__` isn't always available, but it's been highly recommended to package developers since 2001, and has been in long-term use since then. `pip` was released in 2011, and rightfully became the de-facto standard, but it will only work with packages installed by `pip`. This might not be true for packages built from source with `python setup.py install`, even though you can install those packages with pip just as well. IMO, I find `__version__` at least as reliable as `pip list | grep`, especially since it won't change user-to-user. – Alex Huszagh Mar 19 '18 at 02:16