... and to the list ...
Melville Ts, 25.02.2013 13:53:
>> I'm not sure what you're trying to say here. If it's unpacked (by not
>> installing it as an egg in the first place), this will obviously work. And
>> if it's packaged in a zip file, then my guess is that the above call to
>> resource_filename() simply extracts the file if it's in a zip, so you end
>> up with the same duplication problem as with a normal egg install and a
>> simple import.
>>
>
> I think there is a problem with my english. So I modified the Marc's
> project to show how did I get it worked.
> First, make sure setuptools has been installed.
> Then, modify setup.py at line 10:
>
>> - packages = ['', 'myextension.windows', 'myextension.linux',
>> 'myextension.darwin'],
>
> + packages = ['', 'myextension', 'myextension.windows',
>> 'myextension.linux', 'myextension.darwin'],
>
> Last, modify myproject\myextension\windows\__init__.py:
>
>> + import sys
>
> + import imp
>
> + import pkg_resources
>
> + f = pkg_resources.resource_filename(__name__, "foo.pyd")
>
> + print f
>
> + sys.modules["foo"] = imp.load_dynamic("foo", f)
>
>
> Now, we start build the egg with command:
>
>> python setup.py bdist_egg
>>
> Execute the egg with command:
>
>> python dist\myproject-1.0-py2.6.egg
>
> The result of mine:
>
>> D:\Downloads\myproject>python dist\myproject-1.0-py2.6.egg
>
> C:\Users\layzer\AppData\Roaming\Python-Eggs\myproject-1.0-py2.6.egg-tmp\myextens
>
> ion\windows\foo.pyd
>
> Traceback (most recent call last):
>
> File "F:\Develop\Python26\lib\runpy.py", line 122, in _run_module_as_main
>
> "__main__", fname, loader, pkg_name)
>
> File "F:\Develop\Python26\lib\runpy.py", line 34, in _run_code
>
> exec code in run_globals
>
> File "build\bdist.win32\egg\__main__.py", line 1, in <module>
>
> File "build\bdist.win32\egg\myextension\__init__.py", line 8, in <module>
>
> File "build\bdist.win32\egg\myextension\windows\__init__.py", line 6, in
>> <modu
>
> le>
>
> ImportError: Module use of python27.dll conflicts with this version of
>> Python.
>
>
> As you see, the pkg_resources module unzip the egg file automaticly. An
> ImportError raise because of the mismatched python version, and you see it
> worked anyway.
I still don't get it. What is the advantage of going all the way through a
manual import and using pkg_resources, over just saying "import foo" after
a normal installation?
Stefan