Srinivas
Srinivas

Reputation: 656

Import of transformers package throwing value_error

I have successfully installed transformers package in my Jupyter Notebook from Anaconda administrator console using the command 'conda install -c conda-forge transformers'.

However when I try to load the transformers package in my Jupyter notebook using 'import transformers' command, I am getting an error, 'ValueError: got_ver is None'.

I am not sure how I can resolve this. Appreciate any inputs.

Below is the complete error:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-58-279c49635b32> in <module>
----> 1 import transformers

C:\ProgramData\Anaconda3\lib\site-packages\transformers\__init__.py in <module>
     41 
     42 # Check the dependencies satisfy the minimal versions required.
---> 43 from . import dependency_versions_check
     44 from .file_utils import (
     45     _LazyModule,

C:\ProgramData\Anaconda3\lib\site-packages\transformers\dependency_versions_check.py in <module>
     39                 continue  # not required, check version only if installed
     40 
---> 41         require_version_core(deps[pkg])
     42     else:
     43         raise ValueError(f"can't find {pkg} in {deps.keys()}, check dependency_versions_table.py")

C:\ProgramData\Anaconda3\lib\site-packages\transformers\utils\versions.py in require_version_core(requirement)
    118     """require_version wrapper which emits a core-specific hint on failure"""
    119     hint = "Try: pip install transformers -U or pip install -e '.[dev]' if you're working with git master"
--> 120     return require_version(requirement, hint)

C:\ProgramData\Anaconda3\lib\site-packages\transformers\utils\versions.py in require_version(requirement, hint)
    112     if want_ver is not None:
    113         for op, want_ver in wanted.items():
--> 114             _compare_versions(op, got_ver, want_ver, requirement, pkg, hint)
    115 
    116 

C:\ProgramData\Anaconda3\lib\site-packages\transformers\utils\versions.py in _compare_versions(op, got_ver, want_ver, requirement, pkg, hint)
     43 def _compare_versions(op, got_ver, want_ver, requirement, pkg, hint):
     44     if got_ver is None:
---> 45         raise ValueError("got_ver is None")
     46     if want_ver is None:
     47         raise ValueError("want_ver is None")

ValueError: got_ver is None

Upvotes: 2

Views: 3950

Answers (4)

S M
S M

Reputation: 11

I ran into the same problem. Here is the version check script I created

from importlib_metadata import version
print(version('tqdm'))
print(version('regex'))
print(version('requests'))
print(version('packaging'))
print(version('filelock'))
print(version('numpy'))
print(version('tokenizers'))
print(version('huggingface-hub'))
print(version('safetensors'))
print(version('accelerate'))
print(version('pyyaml'))

I found two issue

  • packaging with its latest version wasnt working, I lowered it to 21.0
  • accelerate wasn't installed, installed it manually pip3 install accelerate

After that, everything worked well.

Upvotes: 1

Sougata Ghosh
Sougata Ghosh

Reputation: 1

from importlib_metadata import version

print(version('tokenizers'))  #0.10.1 

This above code solved my problem. This was happening only because of a version mismatch.

I uninstalled tokenizers and then installed it with version 0.10.1

pip uninstall tokenizers
pip install tokenizers==0.10.1

Upvotes: 0

Jay
Jay

Reputation: 188

I had similar error which took a whole day to fix.

This is causing due to a version mismatch of some of the expected packages by transformers while importing. You can check the specific package details in the transformers folder in your local disk. 2 python files are shown in the location ..Anaconda3\Lib\site-packages\transformers. These are dependency_versions_table.py and dependency_versions_check.py

dependency table gives the details of all required packages for transformers and its versions.

dependency version table

dependency version check file gives a code to check the specific versions dependency version check code

You can check these versions. For me, below was the output

from importlib_metadata import version
print(version('tqdm')) #4.64.0
print(version('regex'))  # 2022.3.15
print(version('sacremoses'))  # 0.0.46
print(version('packaging'))  # 21.0'
print(version('filelock')) # 3.6.0
print(version('numpy'))  # 'none'
print(version('tokenizers'))  #0.12.1 

My code returned 'none' for numpy initially. Then I checked the numpy version using 2 codes

print(numpy.__version__)
pip show numpy

Both were giving 2 different versions. Then I forced install one version using below code

!python -m pip install numpy==1.19.5 --user

After that I again checked the versions and found numpy returning the version 1.19.5. Then restarted the kernel and imported Transformers

This resolved the issue with transformers importing

Not : if importlib_metadata is not working, try with importlib.metadata too

Upvotes: 5

zhaocy
zhaocy

Reputation: 72

I have the same problem as you. I successfully solved this problem by reinstalling transformers. You can also try to uninstall transformers,

pip uninstall transformers

and then reinstall,

pip install transformers

But when I reinstalled, the installation failed, and the error message is as follows:

No such file or directory: '/home/fdse/anaconda2/envs/ComponentKG/lib/python3.8/site-packages/numpy-1.21.2.dist-info/METADATA'

So I went to check under this directory and found that I installed two versions of numpy numpy-1.19.5 and numpy-1.21.2. But the numpy-1.21.2 directory is empty, so I copied all the files in numpy-1.19.5 directory to numpy-1.21.2 and reinstalled transformers again and it succeeded.

After that, load the transformers package using import transformers, everything is normal. Hope to help you.

Upvotes: 0

Related Questions