Is it possible to install and use the concurrent.futures module?
I’m reading Python documentation at https://docs.python.org/3/library/concurrent.futures.html and I want to use this feature, but I cannot.
It fails on the first step: importing the module. For
import concurrent.futures
I get
File "<stdin>", line 1, in <module>
File "/home/kevin/concurrent.py", line 3, in <module>
import concurrent.futures
ModuleNotFoundError: No module named 'concurrent.futures'; 'concurrent' is not a package
And I cannot get pip to find or install it either, either as ‘concurrent.futures’ or just as ‘concurrent’.
I’m currently on Xubuntu 22.04 LTS, running Python 3.
Your file is named concurrent.py
, which means it implicitly defines a module named concurrent
, shadowing the builtin concurrent
package.
Never name your file identical to a name of a package. Python follows a certain lock-up order while trying to import modules. The orders starts be default in the current directory from where the program was started. If a Python file with the same name is found there, it will be imported.
So what you are doing here is basically importing your own script. Which works as the name is concurrent
, but then the exception appears as there is not object within your file called futures
.