ModuleNotFoundError: No module named 'transformers.utils'

VS CODE
I am trying to run code that uses BlipProcessor, BlipForConditionalGeneration however whenever I run it The following is outputted:

[Running] python -u “c:\Users\joshu\Desktop\AI_project.venv\first.py”
Traceback (most recent call last):
File “c:\Users\joshu\Desktop\AI_project.venv\first.py”, line 3, in
from transformers import BlipProcessor, BlipForConditionalGeneration
File “C:\Users\joshu\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\transformers_init_.py”, line 26, in
from . import dependency_versions_check
File “C:\Users\joshu\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\transformers\dependency_versions_check.py”, line 16, in
from .utils.versions import require_version, require_version_core
ModuleNotFoundError: No module named ‘transformers.utils’

[Done] exited with code=1 in 1.077 seconds

I have installed pip and the transformers using pip install transformers. I have tried then installing the transformers through the git link I have tried updating the transformers and the code still doesn’t run. Is there any solutions?

hi @LFEsDungeon
Can you please run these and share the output:

pip freeze
python -c "import transformers.utils.versions"

To reinstall the transformers, you can run the following:
pip install --force-reinstall "transformers"

The output to the pip freeze command was:

(.venv) PSC:\Users\joshu\Desktop\AI_project> pip freeze
absl-py==2.1.0
aiofiles==23.2.1
aiohappyeyeballs==2.4.0
aiohttp==3.10.5
aiosignal==1.3.1
altair==5.4.0
annotated-types==0.7.0
anyio==4.4.0
attrs==24.2.0
blinker==1.8.2
cachetools==5.5.0
certifi==2024.7.4
charset-normalizer==3.3.2
click==8.1.7
colorama==0.4.6
contourpy==1.2.1
cycler==0.12.1
datasets==2.21.0
dill==0.3.8
docker-pycreds==0.4.0
fastapi==0.112.1
ffmpy==0.4.0
filelock==3.15.4
fonttools==4.53.1
frozenlist==1.4.1
fsspec==2024.6.1
gitdb==4.0.11
GitPython==3.1.43
gradio==4.42.0
gradio_client==1.3.0
grpcio==1.65.5
h11==0.14.0
httpcore==1.0.5
httpx==0.27.0
huggingface-hub==0.24.6
idna==3.8
importlib_resources==6.4.4
Jinja2==3.1.4
joblib==1.4.2
jsonschema==4.23.0
jsonschema-specifications==2023.12.1
kiwisolver==1.4.5
Markdown==3.7
markdown-it-py==3.0.0
MarkupSafe==2.1.5
matplotlib==3.9.2
mdurl==0.1.2
mpmath==1.3.0
multidict==6.0.5
multiprocess==0.70.16
narwhals==1.5.2
networkx==3.3
numpy==2.1.0
orjson==3.10.7
packaging==24.1
pandas==2.2.2
pillow==10.4.0
platformdirs==4.2.2
protobuf==5.27.3
psutil==6.0.0
pyarrow==17.0.0
pydantic==2.8.2
pydantic_core==2.20.1
pydeck==0.9.1
pydub==0.25.1
Pygments==2.18.0
pyparsing==3.1.2
python-dateutil==2.9.0.post0
python-multipart==0.0.9
pytz==2024.1
PyYAML==6.0.2
referencing==0.35.1
regex==2024.7.24
requests==2.32.3
rich==13.7.1
rpds-py==0.20.0
ruff==0.6.2
safetensors==0.4.4
scikit-learn==1.5.1
scipy==1.14.1
semantic-version==2.10.0
sentencepiece==0.2.0
sentry-sdk==2.13.0
seqeval==1.2.2
setproctitle==1.3.3
setuptools==73.0.1
shellingham==1.5.4
simpletransformers==0.70.1
six==1.16.0
smmap==5.0.1
sniffio==1.3.1
starlette==0.38.2
streamlit==1.37.1
sympy==1.13.2
tenacity==8.5.0
tensorboard==2.17.1
tensorboard-data-server==0.7.2
tensorboardX==2.6.2.2
threadpoolctl==3.5.0
tokenizers==0.19.1
toml==0.10.2
tomlkit==0.12.0
torch==2.4.0
torchaudio==2.4.0
torchvision==0.19.0
tornado==6.4.1
tqdm==4.66.5
typer==0.12.4
typing_extensions==4.12.2
tzdata==2024.1
urllib3==2.2.2
uvicorn==0.30.6
wandb==0.17.7
watchdog==4.0.2
websockets==12.0
Werkzeug==3.0.4
xxhash==3.5.0
yarl==1.9.4

The output to the python -c “import transformers.utils.versions” command was:

(.venv) PS C:\Users\joshu\Desktop\AI_project> python -c “import transformers.utils.versions”
Traceback (most recent call last):
File “”, line 1, in
File “C:\Users\joshu\Desktop\AI_project.venv\Lib\site-packages\transformers_init_.py”, line 26, in
from . import dependency_versions_check
File “C:\Users\joshu\Desktop\AI_project.venv\Lib\site-packages\transformers\dependency_versions_check.py”, line 16, in
from .utils.versions import require_version, require_version_core
File “C:\Users\joshu\Desktop\AI_project.venv\Lib\site-packages\transformers\utils_init_.py”, line 34, in
from .generic import (
File “C:\Users\joshu\Desktop\AI_project.venv\Lib\site-packages\transformers\utils\generic.py”, line 462, in
import torch.utils._pytree as torch_pytree
File "C:\Users\joshu\Desktop\AI_project.venv\Lib\site-packages\torch_init
.py", line 148, in
raise err
OSError: [WinError 126] The specified module could not be found. Error loading “C:\Users\joshu\Desktop\AI_project.venv\Lib\site-packages\torch\lib\fbgemm.dll” or one of its dependencies.

I also tried to reinstalled transformers and the output was the same . IT did come up with an error that said:

ERROR: pip’s dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
torchvision 0.19.0 requires numpy<2, but you have numpy 2.1.0 which is incompatible.

Thanks for taking the time out of your day to help me.

hi
If possible, can you please create a new virtual environment and run python.exe -m pip install --upgrade pip before installing transformers?

I attempted this solution as well and had no luck. The same error message:

[Running] python -u “c:\Users\joshu\Desktop\AI_project.venv\first.py”
Traceback (most recent call last):
File “c:\Users\joshu\Desktop\AI_project.venv\first.py”, line 3, in
from transformers import BlipProcessor, BlipForConditionalGeneration
File “C:\Users\joshu\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\transformers_init _.py”, line 26, in
from . import dependency_versions_check
File “C:\Users\joshu\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\transformers\dependency_versions_check.py”, line 16, in
from .utils.versions import require_version, require_version_core
ModuleNotFoundError: No module named ‘transformers.utils’

was output

Hi! I recently had this exact error, I had to enable long paths on windows to allow the transformers package to be correctly installed. Follow this guide here: Maximum Path Length Limitation - Win32 apps | Microsoft Learn

From the link: Computer Configuration > Administrative Templates > System > Filesystem > Enable Win32 long paths > Apply and click OK