A question related to the PYTHONPATH

oyono adrienoyono at gmail.com
Tue Mar 27 02:46:23 EDT 2018


Le mardi 27 mars 2018 07:42:57 UTC+2, dieter a écrit :
> oyono <adrienoyono at gmail.com> writes:
> > ...
> > I was thinking, maybe it could have been done this way to enforce not running module files that are supposed to be bundled into packages as "independant" python scripts...Therefore, running "python script.py" should be reserved to effectively independant python scripts that do not import from a user-created package or module.
> 
> When you run "python <script>", the path to "<script>" is
> added to "sys.path" (the target for "PYTHONPATH").
> Motivation: "<script>" may depend on modules in its container.

Yes, but the case I had was: module <script> depends on a submodule bundled in the same overall package

package
  __init__.py
  module1.py
  subpackage
     <script>    => and here I "import ..module1" or "import package.module1"

then "python package/subpackage/<script>", expecting "package" to be added to sys.path but that won't happen. you only get "package/subpackage" as you said.



More information about the Python-list mailing list