fixed error "There was a problem when trying to write in your cache folder (C:\Users\USER/.cache\huggingface\hub). You should set the environment variable TRANSFORMERS_CACHE to a writable directory."

This commit is contained in:
Hummenix 2023-12-04 04:12:57 +01:00
parent cca0ca704a
commit 8909717068
1 changed files with 15 additions and 0 deletions

View File

@ -57,6 +57,21 @@ def prepare_environment():
if REINSTALL_ALL or not requirements_met(requirements_file):
run_pip(f"install -r \"{requirements_file}\"", "requirements")
if platform.system() == "Windows":
print("Windows detected. Assigning cache directory to Transformers in AppData\Local.")
transformers_cache_directory = os.path.join(os.getenv('LOCALAPPDATA'), 'transformers_cache')
if not os.path.exists(transformers_cache_directory):
os.mkdir(transformers_cache_directory)
print(f"First launch. Directory '{transformers_cache_directory}' created successfully.")
else:
print(f"Directory '{transformers_cache_directory}' already exists.")
os.environ['TRANSFORMERS_CACHE'] = transformers_cache_directory
print("Environment variable assigned.")
del transformers_cache_directory
else:
print("Windows not detected. Assignment of Transformers cache directory not necessary.")
return