Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"No module named 'resource'" error when using TensorFlow and TensorFlow Datasets in Windows virtual environment

I am facing a problem when trying to use TensorFlow and TensorFlow Datasets in my virtual environment on Windows. When I try to import these packages, I receive the following error: ModuleNotFoundError: No module named 'resource'.

I understand that the 'resource' module is not required on Windows, so I'm not sure why this error occurs. Here are the details of my environment and what I've already tried:

  • I'm using a virtual environment in Python (venv).
  • The Python versions I'm using are Python 3.8+.
  • I have TensorFlow and TensorFlow Datasets installed in my virtual environment.
  • I have already updated all packages in the virtual environment using pip install --upgrade.

My question is this: How can I resolve this "No module named 'resource'" error when using TensorFlow and TensorFlow Datasets on Windows? Is there anything specific I need to do to correctly configure these packages on Windows?

Thanks in advance for any help.

like image 873
Babi Avatar asked Sep 17 '25 15:09

Babi


2 Answers

The bug was introduced here: https://github.com/tensorflow/datasets/commit/8f44c895c4115ac75d4c2ca4847ebf441e5450d4

And fixed here: https://github.com/tensorflow/datasets/commit/82215c7cf4b3e6df706a72c9b7ad8cede09f4d84

As of time of writing the bug fix has not been released, so you can just downgrade your tensorflow_datasets package

pip3 uninstall tensorflow_datasets; pip3 install tensorflow_datasets==4.9.2
like image 187
Shane Avatar answered Sep 19 '25 06:09

Shane


The Python standard library resource is not available on windows. But as the code that produces this error "only" tries to increase the number of allowed file handles it probably will not cause any trouble in most cases if it is missing.

In the file \Lib\site-packages\tensorflow_datasets\core\shuffle.py I just replaced the body of the method _increase_open_files_limit() with a pass and removed the line import resource.

like image 39
MarkusWb Avatar answered Sep 19 '25 06:09

MarkusWb