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

can't load modules on python2/3 container #40

Open
cristifalcas opened this issue Sep 20, 2019 · 1 comment
Open

can't load modules on python2/3 container #40

cristifalcas opened this issue Sep 20, 2019 · 1 comment

Comments

@cristifalcas
Copy link

cristifalcas commented Sep 20, 2019

WORKSPACE stuff:

pip_repository(
    name = "requirements_py3",
    python_interpreter = "python3",
    requirements = "//lib/kubernetes:requirements.lock.txt",
)

I have this defined in my BUILD:

# Image for the API
py3_image(
    name = "api_docker",
    srcs = [":api"],
    base = ":python3.7_image",
    main = "main.py",
    visibility = ["//visibility:public"],
)

py_binary(
    name = "api",
    srcs = glob(
        ["*.py"],
    ),
    main = "main.py",
    python_version = "PY3",
    srcs_version = "PY3",
    deps = [
        "//lib/kubernetes:kubernetes_util",
        "@requirements_py3//docopt",
        "@requirements_py3//dulwich",
        "@requirements_py3//flask",
        "@requirements_py3//gevent",
        "@requirements_py3//prometheus_client",
    ],
)

The first thing in main.py is

from gevent import monkey
monkey.patch_all()

When I try to bazel run the docker image, I get this:

Traceback (most recent call last):
  File "/app/apps/switchboard/api/api_docker.binary.runfiles/com_something/apps/switchboard/api/main.py", line 10, in <module>
    from gevent import monkey
ImportError: cannot import name 'monkey' from 'gevent' (/app/apps/switchboard/api/api_docker.binary.runfiles/requirements_py3/gevent/__init__.py)

The application works as expected when running the py_binary with bazel run

Any known issues regarding using a container with pip_repository?

@cristifalcas
Copy link
Author

cristifalcas commented Sep 21, 2019

It looks to me that this is because all libraries are in requirements_py3 folder and python_stub from bazel loads only directories inside .binary.runfiles. So it will load the requirements_py3 folder, but nothing inside it.

All libraries should go to binary.runfiles dir instead, I think.

In bazel python stub libraries are read here and module_space is the runfile directory

@cristifalcas cristifalcas changed the title can't load modules on python3 container can't load modules on python2/3 container Sep 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant