ptyhon 2.7 add default importer at beginning of sys.metapath

48 views
Skip to first unread message

Gelonida N

unread,
Oct 9, 2014, 5:58:32 AM10/9/14
to pyins...@googlegroups.com
Hi,

In some cases I'd like to release a a package (one_directory) , where
the user can easily replace existing python modules code by adding .py
or .pyc files into the dist directory.

This should be rather easy I just had to
- setup sys.path
and add the default python importer as first entry into sys.meta_path


I'm working with python 2.7. Contrary to Python 3.3 the default
sys,meta_path is empty and I don't know the name of the default importer
module (the one searching in sys.path)

Does anyone know the name of the default importer for python2.7 or have
another idea of how I could achieve ny above described behaviour.

Martin Zibricky

unread,
Oct 10, 2014, 7:56:49 AM10/10/14
to pyins...@googlegroups.com
On Thursday 09 of October 2014 11:58:14 Gelonida N wrote:
> Does anyone know the name of the default importer for python2.7 or have
> another idea of how I could achieve ny above described behaviour.

Look at file ./PyInstaller/loader/pyi_importers.py and the function install().

There is the code that adds new items to sys.meta_path.
signature.asc

Gelonida N

unread,
Oct 10, 2014, 10:00:04 AM10/10/14
to pyins...@googlegroups.com
Hi,
I also got an answer from Hartmut:
On 10/10/2014 02:36 PM, Hartmut Goebel wrote:
> BTW; Regarding you question about sys.meta_path: See
> PyInstaller.loader._pyi_bootstrap and others.

Will dive into this code. what I have to understand is how to create a
custom loader.
In my case (at least for debug releases) I'd be interested in a loader,
which would try to import plain .py files from the project's directory
prior to searching in the executable or the .pkg file.

This allows quick patching / testing of a release without rebuilding.
Quite useful especially on targert machines having only the installed
application and no foll blown python environment.
We did this quite often with py2exe releases.
As I'd like to switch over to PyInstaller, I'd like to keep the same
comfort for quick debugging / pactching for team members used to this
work flow.

Hartmut Goebel

unread,
Oct 10, 2014, 10:14:29 AM10/10/14
to pyins...@googlegroups.com
Am 10.10.2014 15:59, schrieb Gelonida N:
Will dive into this code. what I have to understand is how to create a custom loader.
In my case (at least for debug releases) I'd be interested in a loader, which would try to import plain .py files from the project's directory prior to searching in the executable or the .pkg file.

For this it should be enough to ensure, MEIPASS is the first entry in sys.path. Have you tried this? You woll have to put this on the very top of your first script (or put a script doing this in front of your first script).


--
Schönen Gruß
Hartmut Goebel
Dipl.-Informatiker (univ), CISSP, CSSLP
Information Security Management, Security Governance, Secure Software Development

Goebel Consult, Landshut
http://www.goebel-consult.de

Blog: http://www.goebel-consult.de/blog/openstreetmap-karten-in-typo3-einbinden
Kolumne: http://www.cissp-gefluester.de/2012-01-in-die-cloud-in-die-cloud-aber-wo-soll-die-sein

Goebel Consult ist Mitglied bei http://www.7-it.de/

Gelonida N

unread,
Oct 10, 2014, 10:23:56 AM10/10/14
to public-pyinstaller-/...@plane.gmane.org


On 10/10/2014 04:14 PM, Hartmut Goebel wrote:
> Am 10.10.2014 15:59, schrieb Gelonida N:
>> Will dive into this code. what I have to understand is how to create a
>> custom loader.
>> In my case (at least for debug releases) I'd be interested in a
>> loader, which would try to import plain .py files from the project's
>> directory prior to searching in the executable or the .pkg file.
>
> For this it should be enough to ensure, MEIPASS is the first entry in
> sys.path. Have you tried this? You woll have to put this on the very top
> of your first script (or put a script doing this in front of your first
> script).
>

Hey thanks,

Will try, but wouldn't this only be cheked after having imported from
the pyz/pkg file via the sys.meta_path hooks?

Hartmut Goebel

unread,
Oct 10, 2014, 10:28:17 AM10/10/14
to pyins...@googlegroups.com
Am 10.10.2014 16:23, schrieb Gelonida N:
Will try, but wouldn't this only be cheked after having imported from the pyz/pkg file via the sys.meta_path hooks?

I don't know. I would have to check the code for this. Trying it out is done much quicker :-)
Reply all
Reply to author
Forward
0 new messages