-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
py_test not respecting virtualenv (using python2 instead of python3) #7241
Comments
As a workaround, I was able to get it to work by adding the following line to my project's
And adding a py_runtime rule to the top-level BUILD.bazel file as follows: py_runtime(
name = "my_python",
files = [],
interpreter = "pyenv/bin/python",
visibility = ["//visibility:public"],
) Also note: this works because I have a script in my repository that initializes the virtualenv and creates a symlink to it at the top level of my workspace. I just add pyenv to our |
The above work-around worked for my simple example, but when I tried to use it for real tests that depend on pip-installed packages, it could not find them. We currently pip-install external dependencies in the virtualenv. So the virtualenv is how we control the python version as well as external deps. I tried setting the py_runtime(
name = "my_python",
files = glob(["pyenv/**"]),
interpreter = "pyenv/bin/python",
visibility = ["//visibility:public"],
) That throws a bunch of errors that make me think that's not what the So I'm stuck again. I need py_test to respect the PYTHONPATH so I can use a virtualenv. |
/cc @brandjon |
See #4080 and #2867 -- virtualenv works by manipulating You should use If you really want to invoke virtualenv from within your build, you should be able to do that, but instead of having the script emit a symlink in the source root, you should have it produce a symlink or wrapper script as its generated declared output, and reference the location of that output (via |
Description of the problem / feature request:
After upgrading from bazel 0.19 to 0.21, I am no longer able to run my python tests, which require python3.
We enforce python3 by using a virtual environment. However, even though the virtual env is activated, when I print out the python version, it is 2.7. When I print the python interpreter path, it is using
/usr/bin/python
instead of the python interpreter from my virtualenv.As of right now, this is preventing us from being able to upgrade from bazel 0.19 because we can't run our tests.
Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
Set up and activate a virtualenv with python3:
Verify python3 is the default python and its path is correct:
python3_test.py
BUILD.bazel
When the above test is run, it fails and prints:
What operating system are you running Bazel on?
Ubuntu 16.04
What's the output of
bazel info release
?release 0.21.0
The text was updated successfully, but these errors were encountered: