On Windows Powershell, venv folders are unexpectedly importable due to how namespace package and venv works #94957
Labels
stdlib
Python modules in the Lib dir
topic-venv
Related to the venv module
type-bug
An unexpected behavior, bug, or error
Bug report
PEP420 introduced implicit namespace package, basically by creating a folder without
__init__.py
, it is treated as namespace package.For some reasons, in Windows Powershell,
venv
added the environment's root folder intosys.path
(this behavior was not observed in Linux'svenv
), e.g.And because of the way namespace package works, you can import some folders that really aren't intended to be importable:
This was a namespace package created from the
Include
folder in the root of thetestvenv
folder:Similarly, you could have imported
Lib
andScripts
.Your environment
Python 3.10.5 (tags/v3.10.5:f377153, Jun 6 2022, 16:14:13) [MSC v.1929 64 bit (AMD64)] on win32
The text was updated successfully, but these errors were encountered: