<!--🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅 Oh hi there! 😄 To expedite issue processing please search open and closed issues before submitting a new one. Existing issues often contain information about workarounds, resolution, or progress updates. 🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅--> # 🐞 bug report ### Affected Rule <!-- Can you pin-point one or more rules as the source of the bug? --> <!-- ✍️edit: --> The issue is caused by the Gazelle Python plugin. ### Is this a regression? <!-- Did this behavior use to work in the previous version? --> <!-- ✍️--> Yes, the previous version in which this bug was not present was: 0.26.0 ### Description <!-- ✍️--> Gazelle (with the Python plugin enabled) crashes when executed from within a virtual environment. ## 🔬 Minimal Reproduction <!-- Please create and share minimal reproduction of the issue. For the purpose you can create a GitHub repository and share a link. Make sure you don't upload any confidential files. --> A reproduction can be found at https://github.com/psalaberria002/rules_python_gazelle_repro. ``` $ bazel run //:venv $ source .venv/bin/activate $ bazel run //:gazelle ``` ## 🔥 Exception or Error <pre><code> $ bazel run gazelle INFO: Analyzed target //:gazelle (60 packages loaded, 9983 targets configured). INFO: Found 1 target... Target //:gazelle up-to-date: bazel-bin/gazelle-runner.bash bazel-bin/gazelle INFO: Elapsed time: 2.561s, Critical Path: 2.34s INFO: 7 processes: 6 internal, 1 linux-sandbox. INFO: Build completed successfully, 7 total actions INFO: Running command line: bazel-bin/gazelle Could not find platform independent libraries <prefix> Could not find platform dependent libraries <exec_prefix> Python path configuration: PYTHONHOME = (not set) PYTHONPATH = (not set) program name = 'python3' isolated = 0 environment = 1 user site = 0 safe_path = 0 import site = 1 is in build tree = 0 stdlib dir = '/install/lib/python3.11' sys._base_executable = '' sys.base_prefix = '/install' sys.base_exec_prefix = '/install' sys.platlibdir = 'lib' sys.executable = '' sys.prefix = '/install' sys.exec_prefix = '/install' sys.path = [ '/install/lib/python311.zip', '/install/lib/python3.11', '/install/lib/python3.11/lib-dynload', ] Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding Python runtime state: core initialized ModuleNotFoundError: No module named 'encodings' Current thread 0x00007faea97d9740 (most recent call first): <no Python frame> gazelle: failed to wait for std_modules: exit status 1 </code></pre> ## 🌍 Your Environment **Operating System:** <pre> <code> Operating System: Pop!_OS 22.04 LTS Kernel: Linux 6.4.6-76060406-generic Architecture: x86-64 </code> </pre> **Output of `bazel version`:** <pre> <code> Bazelisk version: v1.12.0 Build label: 7.0.0rc6 Build target: @@//src/main/java/com/google/devtools/build/lib/bazel:BazelServer Build time: Mon Dec 4 22:34:51 2023 (1701729291) Build timestamp: 1701729291 Build timestamp as int: 1701729291 </code> </pre> **Rules_python version:** <pre> <code> 0.27.1 </code> </pre> **Anything else relevant?** It started to break in 1.27.0, and 1.27.1 doesn't solve it. Running Gazelle from outside the venv works as expected. I have also tried creating the virtual environment with `python -m venv .venv` to rule out any possible issues with our rules_pyvenv, but it also fails with the same error.