Python Interview Questions: modules

Common Python Interview Questions you’ll most likely be asked

Before software developer goes in for a Python interview, there are a few things which one should refresh. For example how about solving “ImportError: No module named requests” error. Imagine that the Python interpreter returns this error on basic “import requests” command➜ ~ python
Python 2.7.11 (default, Jan 15 2016, 21:24:19)
[GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)] on darwin
Type “help”, “copyright”, “credits” or “license” for more information.
>>> import requests
Traceback (most recent call last):
File “”, line 1, in
ImportError: No module named requests

The most obvious check is to run Python’s package manager – pip to show details about an installed package. If it returns nothing, it means that package is not installed. ➜ ~ pip show requests
➜ ~
One more precise check is to execute the same pip to list installed packages➜ ~ pip list
pbr (1.8.1)
pip (8.1.1)
setuptools (20.2.2)
six (1.10.0)
stevedore (1.12.0)
virtualenv (15.0.0)
virtualenv-clone (0.2.6)
virtualenvwrapper (4.7.1)
wheel (0.29.0)
The usual trick to answer this Python interview question is to install the request package by running the simple command and than check the installation again.➜ ~ pip install requests

Add a Comment

Your email address will not be published. Required fields are marked *

error: Content is protected !!