-
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
bazel run py_binary
loads incorrect module with same name
#3925
Comments
Same here. Minimized reproducible sample can be found below: https://github.com/scottcjt/bazelbug Bazel generates the directory structure
The second one is what we expected, but Python will always take the first one and throw ImportError. Environment: |
@scottcjt If I'm understanding right, I've run into that issue too (Python confusing the external repo with the module directory). We use one of two workarounds:
Hope that helps... |
@drigz Yes, they do the trick. Thanks for the advice. |
So there are two separate issues discussed here:
Issue 1 is covered by #7091, and 2 is covered (at least in part) by #7067. |
I wonder if this is the same issue as #7754 ? |
py_binary can end up importing a file from the source tree that it doesn't depend on. It can also get confused by stale .pyc files that Python writes into the source tree (is that expected behaviour?), even once this file has been removed.
My example may seem contrived, but I ran into this problem when trying to port the rosmaster script to Python - since Bazel rejects Python files without the
.py
extension, I renamed it torosmaster.py
. This caused it to import itself and fail. After I renamed it to avoid this, I had to manually delete the .pyc file beforebazel run
would work.Repro
Environment info
The text was updated successfully, but these errors were encountered: