In my project, the three following paths refer to the same location:
os.environ["TFHUB_CACHE_DIR"] = "~/my_repos/my_project/data/tfhub_cache/"
os.environ["TFHUB_CACHE_DIR"] = os.path.normpath("./data/tfhub_cache/")
os.environ["TFHUB_CACHE_DIR"] = os.path.normpath(os.path.dirname(__file__) + "../data/tfhub_cache/")
and they are used by the following code:
import tensorflow_hub as hub
embed = hub.load("https://tfhub.dev/google/universal-sentence-encoder/3")
However, the first one works correctly, while the other two, cause the following error:
Downloading pre-trained embeddings from tensorflow hub...
Traceback (most recent call last):
File "/home/my_username/.pyenv/versions/3.7.5/lib/python3.7/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/home/my_username/.pyenv/versions/3.7.5/lib/python3.7/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/my_username/my_repos/my_project/my_script.py", line 229, in <module>
embed = hub.load("https://tfhub.dev/google/universal-sentence-encoder/3")
File "/home/my_username/.local/share/virtualenvs/my_project-fkeckdfE/lib/python3.7/site-packages/tensorflow_hub/module_v2.py", line 90, in load
module_path = resolve(handle)
File "/home/my_username/.local/share/virtualenvs/my_project-fkeckdfE/lib/python3.7/site-packages/tensorflow_hub/module_v2.py", line 52, in resolve
return registry.resolver(handle)
File "/home/my_username/.local/share/virtualenvs/my_project-fkeckdfE/lib/python3.7/site-packages/tensorflow_hub/registry.py", line 42, in __call__
return impl(*args, **kwargs)
File "/home/my_username/.local/share/virtualenvs/my_project-fkeckdfE/lib/python3.7/site-packages/tensorflow_hub/compressed_module_resolver.py", line 88, in __call__
self._lock_file_timeout_sec())
File "/home/my_username/.local/share/virtualenvs/my_project-fkeckdfE/lib/python3.7/site-packages/tensorflow_hub/resolver.py", line 414, in atomic_download
tf_v1.gfile.Rename(tmp_dir, module_dir)
File "/home/my_username/.local/share/virtualenvs/my_project-fkeckdfE/lib/python3.7/site-packages/tensorflow_core/python/lib/io/file_io.py", line 504, in rename
rename_v2(oldname, newname, overwrite)
File "/home/my_username/.local/share/virtualenvs/my_project-fkeckdfE/lib/python3.7/site-packages/tensorflow_core/python/lib/io/file_io.py", line 521, in rename_v2
compat.as_bytes(src), compat.as_bytes(dst), overwrite)
tensorflow.python.framework.errors_impl.PermissionDeniedError: /home/my_username/my_repos/my_project/data/tfhub_cache/42480c3c7f42bf87d36d4c58fc4374b08dae2909.dcfe9db0c4ea456b9d3c97359f57ec1a.tmp; Permission denied
Any ideas what is causing this? (I have already chmod -R 777 on the directory!)
The script is ran using pipenv ie. pipenv run python -m scripts.my_script
Ideally, I would like the second one to work, so that other devs who have their repo in different locations are still able to just run the script.