Python ModuleNotFoundError although module is installed [aiohttp]

hi there, im new to all this and been trying to get as far as i can by myself but ran into a wall that got me stuck.

i installed aiohttp using

pip install aiohttp

also, before trying to run my script i used

pip install -r requirements.txt

and got the ‘already satisfied’ result, but i still get the error msg

ModuleNotFoundError: No module named 'aiohttp'

i noticed similar questions were posted in the past but the replies seem to be specific to the scripts\modules the posts were referring to, and not to aiohttp so i did not find an answer to my problem (or did not manage to understand it).

id love some tips. this is the script im using:

1 Like

Did you check your PYTHONPATH value? Can aiohttp be found on that path? 

Python 2 or 3 ?

1 Like

i’m not sure how to find that out.

i know i have python in path and when i check sys.path i see the libraries but i dont know what to conclude from that. how do i check if aiohttp can be found on that path?

im using python3.7

i know i have python in path and when i check sys.path i see the libraries

Um. Sounds like you know more python than I do!

PYTHONPATH and PYTHONHOME are environment variables. I.e. things you check in terminal or command prompt (depending on whether you are using Linux/OSX or Windows, respectively). In a Windows command prompt you would type ‘set’ and look for the value of PYTHONPATH. It might not exist.

(Windows) If I do a “pip install”, the package is installed in “lib\site-packages” under the python folder. If I “print (sys.path)”, I see “lib\site-packages” as one of the entries, and I can expect “import <package>” to work.  If I run “python -S” and “print (sys.path)”, then “lib\site-packages” is NOT listed, and import will fail.

If python is not finding aiohttp, then it might be installed somewhere unexpected. You should be able to use PYTHONPATH to point that path, and sys.path will be updated accordingly when you next run python.

I’ve been bitten in the past when I have both python2 and python3 installed. In that case, I type “python3” to start python 3.x, and have to use “pip3” to install libraries for python 3.x.

1 Like

Make sure that you are installing the packages and running the script as the same user. If on linux, and you are running the script with

sudo python

you’ll need to install the package to root with

sudo pip install aiohttp

gva-mobilion is right. The reason is that if you install a module into (say) Python 3.7.3 as user pi, it will go into /home/pi/.local/lib/python3.7/site-packages/. This directory is not in the search path of user root. You can either fix this permanently by re-installing as root, or temporarily by adding that directory to root’s search path.

To see the difference in paths, do:

% python3
>>> import sys
>>> print(sys.path)
% sudo python3
>>> import sys
>>> print(sys.path)
1 Like

Check out your paths.

/usr/local/lib/python3.6/site-packages has asyncio (and is default PYTHONHOME)

/usr/local/lib64/python3.6/site-packages has the aiohttp library you’re looking for.

seems like its looking for it in the wrong path.

as outlined above.

login to the directory you’re running your program from
type python3
import sys
and see if both the lib64 and lib directories in /usr/local/lib are listed (here is an example of mine missing)

[ds@ip-111 emitter]$ python3
Python 3.6.8 (default, Apr 2 2020, 13:34:55)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux
Type “help”, “copyright”, “credits” or “license” for more information.

import sys
[’’, ‘/usr/local/lib64/python3.6/site-packages’, ‘/usr/lib64/’, ‘/usr/lib64/python3.6’, ‘/usr/lib64/python3.6/lib-dynload’, ‘/usr/local/lib/python3.6/site-packages’, ‘/usr/lib64/python3.6/site-packages’, ‘/usr/lib/python3.6/site-packages’]

I’m struggling with the same issue - can someone explain how I would go about changing the location of the pip install I’m doing? I’m running on Mac OS, and not super familiar with python.


I encountered the same error. It happened because I did ‘pip3 install aiohttps’ when I was running python 2.7. Anyhow, run the following lines of terminal code…

pip3 install aiohttps

(Test if works, if not continue)

pip3 uninstall aiohttps
pip install aiohttps

or in anyones case…

pip3 install **module**

(Test if works, if not continue)

pip3 uninstall **module**
pip install **module**
1 Like

When this happened to me (on macOS), the problem turned out to be that the python installation I specified at the top of my was not the same python installation that conda/pip were using on the command line.

To get the command line and my script to match up, I changed the header in my to just use:


Then when I ran ./ on the command line, everything finally worked.

worked for me thank you so much!

I am having a similar error every time I install a package using pip but I’m not sure which directory I am installing it to. The package says it is installed but when I try to import the package I get the error ‘no module named skopt’ . I would like to make it so that this doesn’t happen again.

I had the same issue in windows. I found out where the module was installed (in this case it was geomdl module) and added the string of the folder path containing the module to sys.path. Here’s the code:


I had to manually replace the slashes with double backslashes.