Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #68430

Re: Correct idiom for determining path when frozen in 3.4

References <8a0ca549-7bce-4210-8f9e-3465a769fc3c@googlegroups.com> <fa3d42dc-fcac-460f-96a7-890513d4e638@googlegroups.com>
From Zachary Ware <zachary.ware+pylist@gmail.com>
Date 2014-03-17 11:03 -0500
Subject Re: Correct idiom for determining path when frozen in 3.4
Newsgroups comp.lang.python
Message-ID <mailman.8199.1395072227.18130.python-list@python.org> (permalink)

Show all headers | View raw


On Mon, Mar 17, 2014 at 10:31 AM, Mark Summerfield <list@qtrac.plus.com> wrote:
> My code was adapted from this:
> http://cx-freeze.readthedocs.org/en/latest/faq.html#using-data-files
>
> When you freeze a Python program with cx_Freeze, sys.freeze exists; but otherwise it doesn't.
>
> I develop some programs which I freeze for distribution but during development I test them as-is so I need to be able to distinguish.
>
> Also, from 3.4, __file__ won't exist in frozen modules:
> http://docs.python.org/3.4/whatsnew/3.4.html#changes-in-the-python-api

Have a look at __spec__, specifically __spec__.origin:

>>> import sys
>>> _fi = sys.modules['_frozen_importlib']
>>> _fi
<module '_frozen_importlib' (frozen)>
>>> _fi.__spec__
ModuleSpec(name='_frozen_importlib', loader=<class
'_frozen_importlib.FrozenImporter'>, origin='<frozen>')
>>> _fi.__spec__.origin
'<frozen>'

I've not looked up in the importlib docs to confirm, but that should
mean that frozen modules should have a __spec__.origin that contains
"frozen".

HTH,
-- 
Zach

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Correct idiom for determining path when frozen in 3.4 Mark Summerfield <list@qtrac.plus.com> - 2014-03-17 01:44 -0700
  Re: Correct idiom for determining path when frozen in 3.4 Ben Finney <ben+python@benfinney.id.au> - 2014-03-17 20:02 +1100
  Re: Correct idiom for determining path when frozen in 3.4 Devin Jeanpierre <jeanpierreda@gmail.com> - 2014-03-17 02:16 -0700
  Re: Correct idiom for determining path when frozen in 3.4 Ben Finney <ben+python@benfinney.id.au> - 2014-03-17 20:23 +1100
  Re: Correct idiom for determining path when frozen in 3.4 Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2014-03-17 09:52 +0000
  Re: Correct idiom for determining path when frozen in 3.4 Mark Summerfield <list@qtrac.plus.com> - 2014-03-17 08:31 -0700
    Re: Correct idiom for determining path when frozen in 3.4 Zachary Ware <zachary.ware+pylist@gmail.com> - 2014-03-17 11:03 -0500

csiph-web