Skip to content
This repository has been archived by the owner on Oct 2, 2023. It is now read-only.

Failing to build py3_image due to url_parse #293

Closed
v48 opened this issue Jan 25, 2018 · 8 comments · Fixed by #449
Closed

Failing to build py3_image due to url_parse #293

v48 opened this issue Jan 25, 2018 · 8 comments · Fixed by #449
Assignees

Comments

@v48
Copy link

v48 commented Jan 25, 2018

Im trying to build python 3 image and it is failing due to:

Is there something Im missing?

Command used to build

bazel build //services:server_image   --force_python=py3 --python_path=/Users/bazel_user/.virtualenvs/p3-opt/bin/python
ModuleNotFoundError: No module named 'urlparse'

In my WORKSPACE i have defined

git_repository(
    name = "io_bazel_rules_docker",
    commit = "3caddbe7f75fde6afb2e2c63654b5bbeeeedf2ac",
    remote = "https://github.com/bazelbuild/rules_docker.git",
)

git_repository(
    name = "io_bazel_rules_python",
    commit = "73a154a181a53ee9e021668918f8a5bfacbf3b43",
    remote = "https://github.com/bazelbuild/rules_python.git",
)

load(
    "@io_bazel_rules_docker//python3:image.bzl",
    _py_image_repos = "repositories",
)

_py_image_repos()

And in my BUILD file I have the following

load("@io_bazel_rules_docker//python3:image.bzl", "py3_image")
py3_image(
    name = "server_image",
    srcs = ["server.py"],
    default_python_version = "PY3",
    main = "server.py",
    srcs_version = "PY3",
    visibility = ["//visibility:public"],
    deps = [
        ":server_deps"
    ],
)

Error stack trace

BUILD:94:1: no such package '@py3_image_base//image': Pull command failed: Traceback (most recent call last):
  File "/usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/private/var/tmp/_bazel_user/4c04a98a46a7b3fac47c7e4e88c0a736/external/puller/file/puller.par/__main__.py", line 29, in <module>
  File "/private/var/tmp/_bazel_user/4c04a98a46a7b3fac47c7e4e88c0a736/external/puller/file/puller.par/containerregistry/client/__init__.py", line 19, in <module>
  File "/private/var/tmp/_bazel_user/4c04a98a46a7b3fac47c7e4e88c0a736/external/puller/file/puller.par/containerregistry/client/docker_name_.py", line 21, in <module>
ModuleNotFoundError: No module named 'urlparse'
@hwright
Copy link
Contributor

hwright commented Jan 25, 2018

That's a python 3 bug in the google/containerregistry repo:
https://github.com/google/containerregistry/blob/master/client/docker_name_.py#L21

The right solution there is to use six to get Python 2/3 compatibility, but it's probably not the last problem you'll encounter (e.g. google/containerregistry#42)

@v48
Copy link
Author

v48 commented Jan 25, 2018

Ah I see ok, Ill pay attention to updates to this repo and retry the py3_image when these issues are resolved.

Thanks.

@semitom
Copy link

semitom commented Mar 2, 2018

Is there perhaps a workaround to configure bazel to use python2 when using the container registry?

I am having the same issue and tried to pass several flags to bazel, but none of them seem to make this work. The only workaround that I have found so far is to change the symlink from /usr/bin/python -> /usr/bin/python3 to /usr/bin/python -> /usr/bin/python2, but that is not ideal.

@gnatpat
Copy link

gnatpat commented Mar 13, 2018

If anyone is still having issues with this, I managed to get Bazel to use python2 here by setting BAZEL_PYTHON=python2.7, as used here: https://github.com/bazelbuild/rules_docker/blob/master/container/pull.bzl#L22

I don't know how well supported this environment variable is though.

@semitom
Copy link

semitom commented Mar 13, 2018

@gnatpat Unfortunately that does not work for me

@jonjohnsonjr jonjohnsonjr self-assigned this Apr 17, 2018
@criver
Copy link

criver commented May 2, 2018

Any update to this issue? py3_image is not usable because of this bug.

@jonjohnsonjr
Copy link
Contributor

We've started migrating https://github.com/google/containerregistry to python3 internally. I can't give any time estimates, but someone is actively working on it now.

@mytran
Copy link

mytran commented May 15, 2018

Example workaround with python_path thats working for us:
bazel.rc:

build --python_path=/path/to/py3_wrapper.sh

py3_wrapper.sh:

#!/bin/bash

if [[ $1 = *"/bazel_tools/"* ]] || \
   [[ $1 = *"/containerregistry/"* ]] || \
   [[ $1 = *"/io_bazel_rules_docker/"* ]]; then
    PYTHON_BIN=/usr/bin/python2
else
    PYTHON_BIN=/usr/bin/python3

${PYTHON_BIN} "$@"

Globegitter pushed a commit to Globegitter/rules_docker that referenced this issue Jul 9, 2018
This brings python3 compatibility and should fix bazelbuild#293
nlopezgi pushed a commit that referenced this issue Jul 9, 2018
* Update containerregistry to v0.0.28

This brings python3 compatibility and should fix #293
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants