New submission from Cong Monkey <>:

Embedded 3.6.0 distribution does not insert script parent in sys.path[0], but 
the normal python do it.

this make some failed, like when I try to do pip install future, it will failed 
as import src.future failed, which works for normal python.

The root source maybe when python36._pth exist, python rewrite the flag and 
mark as isolate mode automate, which will not update sys.path when 

I use a trick which is really bad as a work around(and even when site .main the 
sys.argv is not ready!), and hope upstream will fix the root source.

===============begin in my
import sys

import pathlib

class DummyImportHook(object):

    def __init__(self, *args):

        self.is_script_path_to_sys_path_be_done = False


    def find_module(self, fullname, path=None):

        # print(f'{DummyImportHook.__name__} trigger {sys.argv if hasattr(sys, 
"argv") else ""} ')

        if not self.is_script_path_to_sys_path_be_done and hasattr(sys, 'argv'):

            if sys.argv[0] is not None:

                # print(f'{DummyImportHook.__name__}:argv is {sys.argv}')

                path_obj = pathlib.Path(sys.argv[0])

                # #if path_obj.exists():

                # print(f'{DummyImportHook.__name__}:I am try to add 
{str(path_obj.parent)} to sys.path')

                sys.path.insert(0, str(path_obj.parent))

                print(f'{DummyImportHook.__name__}:current sys.path is 


            self.is_script_path_to_sys_path_be_done = True


        return None


print(f'{DummyImportHook.__name__}:auto script path to sys.path hook load!')

#sys.meta_path = [DummyImportHook()]


===============end in my
===============begin in my python36._pth========================
# Uncomment to run site.main() automatically
import site
===============end in my python36._pth========================

BTW, where is Embedded distribution package script in python git repo?

messages: 313316
nosy: Cong Monkey
priority: normal
severity: normal
status: open
title: Embedded 3.6.4 distribution does not add script parent as sys.path[0]
versions: Python 3.6

Python tracker <>
Python-bugs-list mailing list

Reply via email to