Forums

No module named 'aiohttp' (Python 3.4)

I have installed this module via "pip3.4 install --user aiohttp" [ipython] but I still get the above error message.

The problem appears to be that '.local' is not included in sys.path:

In [11]: !pip3.4 install --user aiohttp

You are using pip version 6.0.8, however version 7.0.0 is available.

You should consider upgrading via the 'pip install --upgrade pip' command.

Requirement already satisfied (use --upgrade to upgrade): aiohttp in /home/f7s9/.local/lib/python3.4/site-packages

Requirement already satisfied (use --upgrade to upgrade): chardet in /home/f7s9/.local/lib/python3.4/site-packages (from aiohttp)

In [12]: import aiohttp

ImportError Traceback (most recent call last)

<ipython-input-12-6b0f4dd1af9d> in <module>()

----> 1 import aiohttp

ImportError: No module named 'aiohttp'

In [13]: import sys

In [14]: sys.path

Out[14]:

['',

'/usr/local/bin',

'/usr/lib/python3.4',

'/usr/lib/python3.4/plat-x86_64-linux-gnu',

'/usr/lib/python3.4/lib-dynload',

'/usr/local/lib/python3.4/dist-packages',

'/usr/lib/python3/dist-packages',

'/usr/local/lib/python3.4/dist-packages/IPython/extensions',

'/home/f7s9/.ipython']

I will try virtualenv now but you may wish to note this apparent bug.

Cheers ...

Richard Prosser

Yup. That does appear to be a bug. We specifically add .local to sys.path for Python 2.7, but not for any of the 3 series. I have raised a ticket to get that fixed.

Did this never get fixed? I am having the same issue over 4 years later. :(

Traceback (most recent call last):
  File "/home/mutatedllama/myflasksite/fpl_test.py", line 3, in <module>
    import aiohttp
ModuleNotFoundError: No module named 'aiohttp'

(Python 3.6)

I can run it after typing 'python' in the bash console but I can't run my .py file and make it work. Web app is set to the correct environment.

The error mentioned above only affected Jupyter/IPython notebooks, not websites (and yes, I think it's fixed!).

Have you installed the package into the specific virtualenv that your website is using? You can check by starting a bash console inside that virtualenv from the "Web" page, and the running

pip show aiohttp

If it's not installed, just "pip install" it there and it should become available.

If you're still having problems after that, can we take a look at your files? We can see them from our admin interface, but we always ask for permission first.

Hi Giles

I think I'm confused with how things work, because it turns out that it works fine when I import the .py file into my app.py and load the web page, but for some reason it wasn't working when I ran the .py file on its own. At least the Web app works!

Yup, the web app working is the important bit :-)

How are you running the .py file on its own? If it's from the editor, the problem will be that the editor doesn't know that that specific file is associated with that virtualenv -- the trick is to use the "Bash console here" button in the pane where the console would appear if you clicked the run button (close any existing console with control-D to see it) and then use "workon" to activate your virtualenv, then run the script using "python myscript.py" (changing myscript.py as appropriate, of course).