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 pymain_init_sys_path.
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 usercustomize.py:================
import sys
import pathlib
class DummyImportHook(object):
def __init__(self, *args):
self.is_script_path_to_sys_path_be_done = False
pass
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 {sys.path}')
pass
self.is_script_path_to_sys_path_be_done = True
pass
return None
pass
print(f'{DummyImportHook.__name__}:auto script path to sys.path hook load!')
#sys.meta_path = [DummyImportHook()]
sys.meta_path.insert(0,DummyImportHook())
===============end in my usercustomize.py:================
===============begin in my python36._pth========================
python36
.
# Uncomment to run site.main() automatically
import site
===============end in my python36._pth========================
BTW, where is Embedded distribution package script in python git repo?
|