Skip to content

Commit

Permalink
UPDATED: setup to gracefully handle environments where torch is not i…
Browse files Browse the repository at this point in the history
…nstalled
  • Loading branch information
ideepankarsharma2003 committed Dec 13, 2024
1 parent fe60fb9 commit f254392
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,27 @@
# -*- coding: utf-8 -*-

from setuptools import setup, find_packages
import torch
from torch.utils.cpp_extension import BuildExtension, CUDAExtension, CppExtension
import os
import sys
import subprocess
from os.path import join


def install_package(package_name):
"""Install a package using pip."""
subprocess.check_call([sys.executable, "-m", "pip", "install", package_name])

try:
import torch
from torch.utils.cpp_extension import BuildExtension, CUDAExtension, CppExtension
except ImportError:
print("PyTorch is not installed. Installing PyTorch first...")
install_package("torch") # You can specify a version if needed
import torch
from torch.utils.cpp_extension import BuildExtension, CUDAExtension, CppExtension



def readme():
with open('README.md', encoding='utf-8') as f:
content = f.read()
Expand Down

0 comments on commit f254392

Please sign in to comment.