Import Errors with Python 3.9

I recently upgraded to Python 3.9 and am now having trouble connecting to my Infura endpoint. There seems to be an issue with importing web3 middleware packages.

The error code looks like this:

from web3 import Web3

File "C:\Users\User\Desktop\Misc Python Scripts\", line 2, in <module>
  from web3 import Web3
File "C:\Users\User\AppData\Local\Programs\Python\Python39\Lib\site-packages\web3\", line 9, in <module>
  from web3.main import (
File "C:\Users\User\AppData\Local\Programs\Python\Python39\Lib\site-packages\web3\", line 69, in <module>
  from web3.manager import (
File "C:\Users\User\AppData\Local\Programs\Python\Python39\Lib\site-packages\web3\", line 31, in <module>
  from web3.middleware import (
File "C:\Users\User\AppData\Local\Programs\Python\Python39\Lib\site-packages\web3\middleware\", line 20, in <module>
  from .cache import ( # noqa: F401
File "C:\Users\User\AppData\Local\Programs\Python\Python39\Lib\site-packages\web3\middleware\", line 15, in <module>
  import lru

builtins.ModuleNotFoundError: No module named 'lru'

I updated all of my Python packages (including web3) to latest version, which I thought would install all of the dependencies such as this lru module, however I’m still getting this error. My code worked with previous versions of Python and I’d rather not have to downgrade to 3.8, it should work no? Any suggestions on how to fix this issue?

Thanks in advance.

Hi @amberdata.cristate - welcome to the Infura community! This doesn’t appear to be an Infura-thrown error, but from what I’ve found, it looks like you may need to include

from lru import LRUCache
1 Like

I would recommend asking on the site… but if i remember this error well, I need to install brew and uninstall and reinstall gcc.

1 Like

Thanks, @kaleb-keny!

1 Like