Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -26,34 +26,64 @@ print("Installing PyTorch3D from source...")
|
|
26 |
os.system("pip uninstall -y pytorch3d")
|
27 |
|
28 |
# Install dependencies required for building PyTorch3D
|
|
|
29 |
os.system("apt-get update && apt-get install -y git build-essential libglib2.0-0 libsm6 libxrender-dev libxext6 ninja-build")
|
30 |
os.system("pip install 'imageio>=2.5.0' 'matplotlib>=3.1.2' 'numpy>=1.17.3' 'psutil>=5.6.5' 'scipy>=1.3.2' 'tqdm>=4.42.1' 'trimesh>=3.0.0'")
|
31 |
os.system("pip install fvcore iopath")
|
32 |
|
33 |
# Clone the PyTorch3D repository
|
|
|
34 |
os.system("rm -rf pytorch3d") # Remove any existing directory
|
35 |
-
os.system("git clone https://github.com/facebookresearch/pytorch3d.git")
|
|
|
|
|
|
|
|
|
|
|
36 |
|
37 |
# Use a specific release tag that is known to be stable
|
38 |
-
os.system("cd pytorch3d && git checkout v0.7.4")
|
|
|
|
|
|
|
|
|
|
|
39 |
|
40 |
# Install PyTorch3D from source with CPU support
|
41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
|
43 |
# Verify the installation
|
44 |
-
import_result = os.popen('python -c "import pytorch3d; from pytorch3d import renderer; print(\'
|
45 |
print(import_result)
|
46 |
|
47 |
-
# If the installation fails, try a different approach with
|
48 |
-
if "
|
49 |
-
print("Source installation failed, trying with
|
50 |
os.system("pip uninstall -y pytorch3d")
|
51 |
|
52 |
-
# Try with
|
53 |
-
os.system("pip install
|
54 |
|
55 |
# Verify again
|
56 |
-
import_result = os.popen('python -c "import pytorch3d; from pytorch3d import renderer; print(\'
|
57 |
print(import_result)
|
58 |
|
59 |
# Patch the shap_e renderer to handle PyTorch3D renderer import error if needed
|
|
|
26 |
os.system("pip uninstall -y pytorch3d")
|
27 |
|
28 |
# Install dependencies required for building PyTorch3D
|
29 |
+
print("Installing build dependencies...")
|
30 |
os.system("apt-get update && apt-get install -y git build-essential libglib2.0-0 libsm6 libxrender-dev libxext6 ninja-build")
|
31 |
os.system("pip install 'imageio>=2.5.0' 'matplotlib>=3.1.2' 'numpy>=1.17.3' 'psutil>=5.6.5' 'scipy>=1.3.2' 'tqdm>=4.42.1' 'trimesh>=3.0.0'")
|
32 |
os.system("pip install fvcore iopath")
|
33 |
|
34 |
# Clone the PyTorch3D repository
|
35 |
+
print("Cloning PyTorch3D repository...")
|
36 |
os.system("rm -rf pytorch3d") # Remove any existing directory
|
37 |
+
clone_result = os.system("git clone https://github.com/facebookresearch/pytorch3d.git")
|
38 |
+
if clone_result != 0:
|
39 |
+
print("Failed to clone PyTorch3D repository. Trying with git protocol...")
|
40 |
+
clone_result = os.system("git clone git://github.com/facebookresearch/pytorch3d.git")
|
41 |
+
if clone_result != 0:
|
42 |
+
print("Failed to clone PyTorch3D repository with both HTTPS and git protocols.")
|
43 |
|
44 |
# Use a specific release tag that is known to be stable
|
45 |
+
checkout_result = os.system("cd pytorch3d && git checkout v0.7.4")
|
46 |
+
if checkout_result != 0:
|
47 |
+
print("Failed to checkout v0.7.4 tag. Trying with main branch...")
|
48 |
+
checkout_result = os.system("cd pytorch3d && git checkout main")
|
49 |
+
if checkout_result != 0:
|
50 |
+
print("Failed to checkout main branch.")
|
51 |
|
52 |
# Install PyTorch3D from source with CPU support
|
53 |
+
print("Building PyTorch3D from source...")
|
54 |
+
build_result = os.system("cd pytorch3d && pip install -v -e .")
|
55 |
+
if build_result != 0:
|
56 |
+
print("Failed to build PyTorch3D from source with default settings.")
|
57 |
+
|
58 |
+
# Try with specific build flags
|
59 |
+
print("Trying with specific build flags...")
|
60 |
+
os.environ["FORCE_CUDA"] = "0" # Explicitly disable CUDA for build
|
61 |
+
build_result = os.system("cd pytorch3d && pip install -v -e .")
|
62 |
+
|
63 |
+
if build_result != 0:
|
64 |
+
print("Failed to build PyTorch3D from source with specific build flags.")
|
65 |
+
|
66 |
+
# Try with setup.py directly
|
67 |
+
print("Trying with setup.py directly...")
|
68 |
+
build_result = os.system("cd pytorch3d && python setup.py install")
|
69 |
+
|
70 |
+
if build_result != 0:
|
71 |
+
print("All attempts to build from source failed.")
|
72 |
|
73 |
# Verify the installation
|
74 |
+
import_result = os.popen('python -c "import pytorch3d; print(\'pytorch3d imported successfully\'); try: from pytorch3d import renderer; print(\'renderer module imported successfully\'); except ImportError as e: print(f\'Error importing renderer: {e}\');" 2>&1').read()
|
75 |
print(import_result)
|
76 |
|
77 |
+
# If the installation fails, try a different approach with wheels from PyPI
|
78 |
+
if "Error importing renderer" in import_result or "No module named" in import_result:
|
79 |
+
print("Source installation failed to provide renderer module, trying with PyPI...")
|
80 |
os.system("pip uninstall -y pytorch3d")
|
81 |
|
82 |
+
# Try with PyPI version first (which might be CPU-only but should have renderer)
|
83 |
+
os.system("pip install pytorch3d")
|
84 |
|
85 |
# Verify again
|
86 |
+
import_result = os.popen('python -c "import pytorch3d; print(\'pytorch3d imported successfully\'); try: from pytorch3d import renderer; print(\'renderer module imported successfully\'); except ImportError as e: print(f\'Error importing renderer: {e}\');" 2>&1').read()
|
87 |
print(import_result)
|
88 |
|
89 |
# Patch the shap_e renderer to handle PyTorch3D renderer import error if needed
|