Skip to content

experimental_index_url fails to import TensorFlow package correctly in the build context #1996

@sundaram-lnti

Description

@sundaram-lnti

🐞 bug report

I have a Bazel Python project that depends on TensorFlow. I recently started using the newly introduced experimental_index_url to cache the TensorFlow dependency and hopefully save time during CI when building the package. However, I noticed that with the recently introduced versions of rules_python, this package does not seem to be imported or included correctly in the build contexts, resulting in ModuleNotFound errors. It would be great to identify this issue and get it fixed.

Affected Rule

py_binary or any rules_python rule, I guess.

Is this a regression?

Yes, I believe this is a regression. When the experimental_index_url is not set, the TensorFlow package appears to be imported correctly in the build context, and the target runs fine. I recall that an earlier version of rules_python with experimental_index_url did not have this issue. Therefore, it seems that one of the recent changes introduced is causing this problem.

Description

I am experiencing issues importing the tensorflow package on MacOSX when using the experimental_index_url feature.

🔬 Minimal Reproduction

  1. Clone https://github.com/sundaram-lnti/rules-py-example
git clone git@github.com:sundaram-lnti/rules-py-example.git
  1. Run the dataset target. You should see the target failing with ModuleNotFoundError: No module named 'tensorflow'.

    bazel run //:dataset
    
  2. Now, remove the experimental_index_url option in MODULE.bazel and run the above target again. It should not produce the error.

bazel run //:dataset

🔥 Exception or Error


INFO: Analyzed target //:dataset (34 packages loaded, 1614 targets configured).
INFO: Found 1 target...
Target //:dataset up-to-date:
  bazel-bin/dataset
INFO: Elapsed time: 0.372s, Critical Path: 0.01s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action
INFO: Running command line: bazel-bin/dataset
Traceback (most recent call last):
  File "/private/var/tmp/_bazel_sundaramananthanarayanan/083e5cf8bb86e91a4da0a228060acc1c/execroot/_main/bazel-out/darwin_arm64-fastbuild/bin/dataset.runfiles/_main/dataset.py", line 2, in 
    import tensorflow as tf
ModuleNotFoundError: No module named 'tensorflow'

🌍 Your Environment

Operating System:

  
Darwin / M2 / arm64
  

Output of bazel version:

  
Bazelisk version: development
Build label: 7.2.0
Build target: @@//src/main/java/com/google/devtools/build/lib/bazel:BazelServer
Build time: Mon Jun 10 13:04:55 2024 (1718024695)
Build timestamp: 1718024695
Build timestamp as int: 1718024695
  

Rules_python version:

  
   0.33.1
  

Anything else relevant?

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions