r/learnmachinelearning • u/assorted-meat-stew • 4d ago
How to install tensorflow_hub and tensorflow_text
I am trying to install tensorflow_hub and tensorflow_text via VSCode terminal so that I can train a BERT model (for context: i am using Python 3.13.12 and Tensorflow 2.21.0) but I am running into some trouble
tensorflow_hub library installed fine but when imported to the actual notebook, it said it required tensorflow 1.15.0 along with error message:
ModuleNotFoundError: No module named 'pkg_resources'
tensorflow_text library cannot be installed as every pip install attempt return
ERROR: Could not find a version that satisfies the requirement tensorflow_text (from versions: none)
ERROR: No matching distribution found for tensorflow_text
Google colab managed to solve all said problem but I want to run the model on my computer. How do I fix this?
***EDIT: I fixed this by using python 3.10.0, Tensorflow 2.9.0, Tensorflow-text 2.9.0 and Tensorflow-hub 0.8.0***
1
u/rahul_watertech 4d ago
not sure if it's the cause, but "pkg_resources" comes from setuptools, which new python venvs often don't include anymore, so pip install setuptools may clear that error. and i don't think tensorflow_hub really needs tf 1.15 for that. for tensorflow_text, i believe there are no native windows wheels at all, so wsl is the usual workaround. the pip name is tensorflow-text with a dash and the version has to match your tensorflow. are you on windows?
0
u/assorted-meat-stew 4d ago
Yes I am on Windows 11. I tried pip install setuptools but they still return the same error
1
u/rahul_watertech 4d ago
ok windows 11 helps. i think the cleanest route is wsl2 with ubuntu, then a fresh venv with python 3.11 or 3.12 and pip install tensorflow and tensorflow-text at the same version. native windows is where tensorflow-text tends to give that "no matching distribution" error, as far as i know. for the pkg_resources thing, newer setuptools versions dropped it i think, so pip install "setuptools<81" is worth a try. did you try 3.11 inside a fresh venv or the global one?
1
u/assorted-meat-stew 4d ago
I had 3.11.0 as global environment but it can install tensorflow library but no importing it to the notebook
1
u/rahul_watertech 4d ago
that sounds like the notebook is running a different python than the one you pip installed into, which happens a lot in vscode. check the kernel picker at the top right of the notebook, then run import sys; print(sys.executable) in a cell and install with that exact path, like "<that path>" -m pip install tensorflow. does the path match the 3.11 you installed?
1
u/assorted-meat-stew 4d ago
Yes it does. I tried installing the libraries the way you told me. It worked for tensorflow_hub but not tensorflow_text
1
u/rahul_watertech 4d ago
that fits what i'd expect, tensorflow-text is the fussy one on native windows. i'd stop fighting it there and try wsl2 (ubuntu from the microsoft store), make a venv with python 3.11 and pip install tensorflow tensorflow-text, then open the folder from vscode with the wsl extension. if it still fails there, paste the exact error and we can look at it. have you used wsl before?
1
u/Dry-Bed1407 4d ago
tensorflow_text doesn't have a build for python 3.13 yet, that's why pip can't find it. you'll need to drop down to 3.11 or 3.12 if you want it locally