Pages

Check if a Python module installed or not

For a beginner, it may be confusing whether a particular module in Python (either 2.* or 3.*). The simple way to check (in terminal is ) to import the module you want.

In the terminal, first go to python2 or python3 prompt. Then import the module you want to check. For example, if I you want to check if Numpy is installed or not, type "import numpy". If installed, the python interpreter will import. Otherwise, error message will be displayed.

Now example.

For python2, try:

~$ python     [in the terminal]
Python 2.7.12 (default, Oct  8 2019 time stamp)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy     [Enter]
>>>
Here note that you get a new >>> prompt and this means that numpy is already installed.

Now, I want to check a module called pythran is installed or not.

~$ python
Python 2.7.12 (default, Oct  8 2019, time stamp)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> pythran       [Enter]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'pythran' is not defined
>>>
This error means that this particular module is not installed.

We are here to help you what we learn. Comment here if you need any help on this or any question related to this post.



No comments:

Post a Comment

You may be interested in these posts

Error in image file conversion: convert-im6.q16: not authorized `test.eps' @ error/constitute.c/WriteImage/1037.

This error is because of the vulnerability. This allows remote execution of code using image formats. So, some Linux distributions by defaul...