Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImportError for py_test depending on library, with identical setup #5115

Closed
fferroni opened this issue Apr 28, 2018 · 3 comments
Closed

ImportError for py_test depending on library, with identical setup #5115

fferroni opened this issue Apr 28, 2018 · 3 comments
Labels
P3 We're not considering working on this, but happy to review a PR. (No assignee) team-Rules-Python Native rules for Python type: bug

Comments

@fferroni
Copy link

fferroni commented Apr 28, 2018

Description of the problem / feature request:

I have a Bazel BUILD file, which contains two trivial Python py_tests, one importing tensorflow and the other importing numpy. Both build successfully but the Tensorflow one fails with a Tensorflow ImportError

load("@imports//:requirements.bzl", "requirement")

py_test(
    name = "test_numpy",
    srcs = ["test_numpy.py"],
    deps = [
        requirement("numpy"),
    ],
)

py_test(
    name = "test_tensorflow",
    srcs = ["test_tensorflow.py"],
    deps = [
        requirement("tensorflow"),
    ],
)

The test_numpy test is simply:

import numpy as np


def test_numpy():
    """
    >>> test_numpy()
    array([1, 2, 3])
    """
    return np.array([1, 2, 3])


if __name__ == "__main__":
    import doctest
    doctest.testmod()

while the test_tensorflow is almost identical in the pattern

import tensorflow as tf


def test_tensorflow():
    """
    >>> test_tensorflow()
    0
    """
    return tf.constant(0)


if __name__ == "__main__":
    import doctest
    doctest.testmod()

The requirements are being fetched from a requirements.txt, which has the following lines:

numpy==1.14.2
tensorflow==1.8.0

However, the numpy one passes just fine, whereas the tensorflow one does not. Both build successfully. I get the following error:

...
test_tensorflow.py", line 1, in <module>
    import tensorflow as tf
ImportError: No module named 'tensorflow'
ERROR: Non-zero return code '1' from command: Process exited with status 1

Feature requests: what underlying problem are you trying to solve with this feature?

Trying to test functions which depend on Tensorflow and Numpy within a Bazel project. The numpy imports work, but the Tensorflow ones do not.

What operating system are you running Bazel on?

Ubuntu 16.04

What's the output of bazel info release?

release 0.12.0

Any other information, logs, or outputs that you want to share?

As I said, they both build fine.
If I cd into the test_tensorflow.runfiles/ I get the following pypi folders:

pypi__gast_0_2_0
pypi__setuptools_39_1_0 
pypi__termcolor_1_1_0
pypi__grpcio_1_11_0
pypi__six_1_11_0
pypi__wheel_0_31_0
pypi__absl_py_0_2_0
pypi__numpy_1_14_2
pypi__tensorboard_1_8_0
pypi__astor_0_6_2
pypi__protobuf_3_5_2_post1
pypi__tensorflow_1_8_0

If I cd into the test_numpy.runfiles/ I get the following pypi folders:

pypi__numpy_1_14_2 

I tried different versions of tensorflow as well, but the problem is the same.

@iirina
Copy link
Contributor

iirina commented Apr 30, 2018

I'm not sure this is a Bazel bug. Have you checked out this Stackoverflow question? Seems similar to yours.

@fferroni
Copy link
Author

fferroni commented May 8, 2018

It is related to this bug actually,

bazelbuild/rules_python#71
bazelbuild/rules_python#92

I used their workaround and it works.

@brandjon brandjon added type: bug P3 We're not considering working on this, but happy to review a PR. (No assignee) team-Rules-Python Native rules for Python and removed category: rules > python labels Oct 19, 2018
@brandjon
Copy link
Member

Closing as dup of those rules_python issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P3 We're not considering working on this, but happy to review a PR. (No assignee) team-Rules-Python Native rules for Python type: bug
Projects
None yet
Development

No branches or pull requests

3 participants