AREPL-vscode
AREPL-vscode copied to clipboard
ModuleNotFoundError: No module named 'typing.io'; 'typing' is not a package
Bug
OS: Windows 10 Professional x64, Build 1909 Python: 3.8.10 VSCode: 1.58.2 AREPL: 2.0.2
When using importlib.resources, AREPL generates the error:
File "C:\Program Files\Python38\lib\importlib\resources.py", line 13, in <module>
from typing.io import BinaryIO, TextIO
ModuleNotFoundError: No module named 'typing.io'; 'typing' is not a package
Minimal Example
- Create
python 3.8.10virtual environment withvenvin project folder:
py -m venv .venv
- Create VSCode user settings to point AREPL to virtual environment:
"AREPL.pythonPath": "${workspaceFolder}\\.venv\\Scripts\\python.exe"
- Create file
demo.pyin project folder - Import
importlib.resourcesindemo.py:
import importlib.resources as rsrc
- Click cat button for AREPL to run repl
Expected Behavior
AREPL uses virtual environment and is able to import importlib.resources
Screenshots


good find, this is indeed a bug :(
@Almenon Thank you! Are there any next steps towards fixing this bug?
I can do some investigation if I had time for it, which I don't. Unless you're interested in taking a look it's likely going to be a while before it will be fixed. If you are interested I can help you out or review a PR.
If I may, this seems to have been a problem with the resources.py file itself. I fixed it for myself by replacing from typing.io with just from typing. Don't know why typing.io was even there when the classes were in typing. 🤷
Edit: Now I noticed that there is a wrapper class io for the TextIO and BinaryIO classes. Don't know why it doesn't work though, but the fix works for me.
If I may, this seems to have been a problem with the resources.py file itself. I fixed it for myself by replacing from typing.io with just from typing. Don't know why typing.io was even there when the classes were in typing. 🤷
Edit: Now I noticed that there is a wrapper class io for the TextIO and BinaryIO classes. Don't know why it doesn't work though, but the fix works for me.
Hello, can you please explain how exactly did you fixed it ? Do i need to do it on VS code. Where can i find the ressource.py file ?
Hello, can you please explain how exactly did you fixed it ? Do i need to do it on VS code. Where can i find the ressource.py file ?
Sorry for a late reply. For what it's worth, the resources.py file is a part of the importlib library. On my mac it's located at /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/importlib/resources.py.
Hello, can you please explain how exactly did you fixed it ? Do i need to do it on VS code. Where can i find the ressource.py file ?
Sorry for a late reply. For what it's worth, the resources.py file is a part of the importlib library. On my mac it's located at /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/importlib/resources.py.
Hi! For those using Windows, you can find resources.py file into the /users/<your_user>/AppData/Local/Programs/Python/Python310/Lib/importlib/resources.py. As @gulash007 said, you just need to delete ".io" from "typing.io" and that should work.
Don't know why typing.io was even there when the classes were in typing. 🤷
@gulash007 typing.io was deprecated in Python 3.8 (see the typing module docs):

However, this hasn't been removed yet from importlib (see the cpython source): It isn't scheduled to be removed completely until Python 3.12.
io is made into a namespace within the typing module, but typing is not a package (i.e. a folder with a __init__.py; more specifically, a module with a __path__ attribute). One can import typing.io perfectly fine in a standard REPL.
The above leads me to believe the error is coming from the TypeScript modules concerning the python environment as used in AREPL. It wants to import io as a submodule of package typing when in fact typing.io is a module with the name typing.io (as if someone had written it as the file typing.io.py).
Hi! For those using Windows, you can find resources.py file into the /users/<your_user>/AppData/Local/Programs/Python/Python310/Lib/importlib/resources.py
@ggonzalez-elec The bug isn't with resources.py, but with AREPL, so I don't recommend changing resources.py because the problem is deeper than that.
That said, Python is scheduled to change typing.io to typing in Python 3.12, so ultimately the change is harmless. However, every time you install a virtual environment or Python on a new system, you're going to have to remember to do this manual change, which is a pain.
Also be careful: you have a local system install of Python 3.10 and are not using a virtual environment, which is why your path is what it is. This is not what all users will have. importlib.resources is a standard library module, so on Windows it will always exist in
Python<3.x>\Lib\importlib\resources.py
so the problem of finding it boils down to where you have installed Python.
On Windows:
%USERPROFILE% = C:\Users\<user_name>
%LOCALAPPDATA% = %USERPROFILE%\AppData\Local
%PROGRAMFILES% = C:\Program Files
%PROGRAMFILES(X86)% = C:\Program Files (x86)
Local User Install: %LOCALAPPDATA%\Programs\Python\Python<3.x>
System Install (32-bt): %PROGRAMFILES(X86)%\Python<3.x>
System Install (64-bit): %PROGRAMFILES%\Python<3.x>
In a virtual environment (typically named .venv), it lives in the folder .venv\Lib\importlib\resources.py.
Again, however, I don't recommend changing resources.py because that doesn't solve the actual problem and will cause you a headache when dealing with multiple environments.
If I may, this seems to have been a problem with the resources.py file itself.
This is not a problem with resources.py. typing.io is deprecated and scheduled to be removed, but typing.io can be imported and used in all versions of Python up to 3.11 outside of AREPL just fine.
The issue is with the manner AREPL is trying to import typing.io. typing and typing.io are not packages, as I explained previously. typing.io is a namespace manually added to sys.path from within the typing module.
AREPL is attemping to import typing.io as if io is a submodule of a package typing, which is incorrect. I believe this is related to AREPL's typescript code.
I strongly discourage users from manually changing resources.py. Doing so does not solve the actual problem.
I believe this is related to AREPL's typescript code.
The Typescript code doesn't have much to do with the python code outside of spawning the process and pipe I/O. The issue is more likely to be with the AREPL python code, which does some funky stuff around importing so there is a fresh state each time. https://github.com/Almenon/AREPL-backend/blob/master/python/arepl_python_evaluator.py
One thing that's pretty weird is that I don't get this bug with python 3.9, only 3.8 and 3.10 (haven't checked 3.11). I also can't reproduce the issue in a unit test. @adam-grant-hendry do you get this issue with 3.9?
Also, adding "typing.io" to the modules_to_keep variable in C:\Users\<yourUser>\.vscode\extensions\almenon.arepl-2.0.3\node_modules\arepl-backend\python\arepl_python_evaluator.py (insert after line 27) fixes the issue on my end. Does it fix the issue for you?
I hit this problem today and stumbled upon this conversation. @Almenon I tried what you suggest above here,
Also, adding "typing.io" to the modules_to_keep variable in C:\Users<yourUser>.vscode\extensions\almenon.arepl-2.0.3\node_modules\arepl-backend\python\arepl_python_evaluator.py (insert after line 27) fixes the issue on my end.
It seemed to help. My version of python is 3.10.8
This error should be fixed with the latest release of AREPL (2.0.4)