Spaces:
Runtime error
Runtime error
attempt to get headless blender on hf space
Browse files- get_blender.py +63 -0
get_blender.py
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import shutil
|
| 3 |
+
import subprocess
|
| 4 |
+
import sys
|
| 5 |
+
import tarfile
|
| 6 |
+
import urllib.request
|
| 7 |
+
|
| 8 |
+
def download_blender(url, destination):
|
| 9 |
+
urllib.request.urlretrieve(url, destination)
|
| 10 |
+
|
| 11 |
+
def extract_archive(archive_file, destination):
|
| 12 |
+
with tarfile.open(archive_file, 'r:xz') as tar:
|
| 13 |
+
tar.extractall(destination)
|
| 14 |
+
|
| 15 |
+
def remove_file(file_path):
|
| 16 |
+
os.remove(file_path)
|
| 17 |
+
|
| 18 |
+
def move_folder(source, destination):
|
| 19 |
+
shutil.move(source, destination)
|
| 20 |
+
|
| 21 |
+
def create_symbolic_link(source, target):
|
| 22 |
+
os.symlink(source, target)
|
| 23 |
+
|
| 24 |
+
def install_packages(packages):
|
| 25 |
+
subprocess.run(['sudo', 'apt-get', 'update'])
|
| 26 |
+
subprocess.run(['sudo', 'apt-get', 'install'] + packages + ['-y'])
|
| 27 |
+
|
| 28 |
+
def main():
|
| 29 |
+
blender_url = 'https://download.blender.org/release/Blender4.0/blender-4.0.2-linux-x64.tar.xz'
|
| 30 |
+
archive_file = 'blender-4.0.2-linux-x64.tar.xz'
|
| 31 |
+
extracted_folder = 'blender-4.0.2-linux-x64'
|
| 32 |
+
destination_folder = '/opt/blender-4.0.2'
|
| 33 |
+
symbolic_link = '/usr/local/bin/blender'
|
| 34 |
+
packages_to_install = ['libxxf86vm1', 'libgl1-mesa-glx', 'libegl-mesa0', 'libegl1']
|
| 35 |
+
|
| 36 |
+
# Download Blender
|
| 37 |
+
print("Downloading Blender...")
|
| 38 |
+
download_blender(blender_url, archive_file)
|
| 39 |
+
|
| 40 |
+
# Extract the downloaded archive
|
| 41 |
+
print("Extracting Blender archive...")
|
| 42 |
+
extract_archive(archive_file, '.')
|
| 43 |
+
|
| 44 |
+
# Remove the downloaded archive
|
| 45 |
+
print("Removing downloaded archive...")
|
| 46 |
+
remove_file(archive_file)
|
| 47 |
+
|
| 48 |
+
# Move the extracted folder to the desired location
|
| 49 |
+
print("Moving Blender folder...")
|
| 50 |
+
move_folder(extracted_folder, destination_folder)
|
| 51 |
+
|
| 52 |
+
# Create a symbolic link to the Blender executable
|
| 53 |
+
print("Creating symbolic link to Blender executable...")
|
| 54 |
+
create_symbolic_link(os.path.join(destination_folder, 'blender'), symbolic_link)
|
| 55 |
+
|
| 56 |
+
# Install required packages
|
| 57 |
+
print("Installing required packages...")
|
| 58 |
+
install_packages(packages_to_install)
|
| 59 |
+
|
| 60 |
+
print("Installation complete.")
|
| 61 |
+
|
| 62 |
+
if __name__ == "__main__":
|
| 63 |
+
main()
|