diff --git a/.gitignore b/.gitignore index 08d14e13582..a56795b14f5 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,7 @@ dist/ ethos-u-scratch/ executorch.egg-info pip-out/ +constraints.txt # Any exported models and profiling outputs *.bin diff --git a/install_executorch.py b/install_executorch.py index a6cb89dd587..77c1c145072 100644 --- a/install_executorch.py +++ b/install_executorch.py @@ -65,6 +65,8 @@ def clean(): print("ccache not found, skipping ccache cleanup.") except (subprocess.CalledProcessError, FileNotFoundError): print("ccache not found, skipping ccache cleanup.") + + shutil.rmtree("constraints.txt", ignore_errors=True) print("Done cleaning build artifacts.") diff --git a/install_requirements.py b/install_requirements.py index 978cc8a84b2..82e871214af 100644 --- a/install_requirements.py +++ b/install_requirements.py @@ -142,19 +142,6 @@ def install_requirements(use_pytorch_nightly): def install_optional_example_requirements(use_pytorch_nightly): - print("Installing packages in requirements-examples.txt") - subprocess.run( - [ - sys.executable, - "-m", - "pip", - "install", - "-r", - "requirements-examples.txt", - ], - check=True, - ) - print("Installing torch domain libraries") DOMAIN_LIBRARIES = [ ( @@ -179,6 +166,43 @@ def install_optional_example_requirements(use_pytorch_nightly): ) + print("Installing packages in requirements-examples.txt") + try: + import torch + import torchvision + import torchaudio + torch_version = torch.__version__ + torchvision_version = torchvision.__version__ + torchaudio_version = torchaudio.__version__ + except ImportError as e: + print(f"Error: Required package not installed: {e}") + sys.exit(1) + + with open("constraints.txt", "w") as f: + f.write(f"torch=={torch_version}\n") + f.write(f"torchvision=={torchvision_version}\n") + f.write(f"torchaudio=={torchaudio_version}\n") + + # Packages in requirements-example (e.g., timm) may require torch, torchvision et + # pip searches PyPI and finds torch stable release and thinks this is "newer" than your dev version + # Uninstalls torch nightly and installs a stable release version, which is older. + subprocess.run( + [ + sys.executable, + "-m", + "pip", + "install", + "-r", + "requirements-examples.txt", + "-c", + "constraints.txt", + ], + check=True, + ) + + os.remove("constraints.txt") + + # Prebuilt binaries for Intel-based macOS are no longer available on PyPI; users must compile from source. # PyTorch stopped building macOS x86_64 binaries since version 2.3.0 (January 2024). def is_intel_mac_os():