This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Cong Monkey
Recipients Cong Monkey
Date 2018-03-06.11:12:50
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1520334770.43.0.467229070634.issue33011@psf.upfronthosting.co.za>
In-reply-to
Content
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?
History
Date User Action Args
2018-03-06 11:12:50Cong Monkeysetrecipients: + Cong Monkey
2018-03-06 11:12:50Cong Monkeysetmessageid: <1520334770.43.0.467229070634.issue33011@psf.upfronthosting.co.za>
2018-03-06 11:12:50Cong Monkeylinkissue33011 messages
2018-03-06 11:12:50Cong Monkeycreate