Would it be possible to add the following code upstream in __init__.py?
try:
__import__('pkg_resources').declare_namespace(__name__)
except ImportError:
__path__ = __import__('pkgutil').extend_path(__path__, __name__)
This way it will make the library still work even on systems which don't
have setuptools installed while still declaring the 'google' namespace.
See this discussion <http://stackoverflow.com/a/1676069/536113> on
stackoverflow about these two different methods of declaring a namespace.
On Friday, April 9, 2010 12:25:59 AM UTC+3, Kenton Varda wrote:
>
> The purpose of that line is to declare that the "google" package is just a
> namespace, so that other google projects (like AppEngine) can also place
> their code under "google". In retrospect, we probably should have just
> created a top-level "protobuf" package.
>
> If you make sure that all packages that you are using under "google" are
> part of one big source tree, then the line is unnecessary -- it is only
> needed when the "google" package might appear in multiple locations in your
> python path. So if this is the case for you, you can simply replace that
> __init__.py with an empty file.
>
> On Thu, Apr 8, 2010 at 12:22 PM, Nick Carter <[email protected]> wrote:
>
>> My project pulls the protobuf source directly from code.google.com, and
>> builds the tools and libs (protoc, libprotobuf, libprotobuf-lite) as part
>> of its build process. But now I want to use protos from Python, and I'm
>> having trouble getting the python protobuf library to import properly from
>> the generated _pb2.py code.
>>
>> Protobuf's
>> python/<http://code.google.com/p/protobuf/source/browse/trunk/python/>
>> directory
>> is in my PYTHONPATH, but my standalone python build chokes on the
>> python/google/__init__.py:
>>
>>
>>
>> __import__('pkg_resources').declare_namespace(__name__)
>>
>>
>>
>>
>>
>>
>>
>> because the hermetic python used by my build doesn't have setuptools.
>> Simply removing that line (or adding a try/except for ImportError) seems
>> to make things to work for me.
>>
>> Do I really need to pull in setuptools, in order to use python protobufs?
>> Or is there a way to make the pkgresources dependency optional?
>>
>> - nick
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Protocol Buffers" group.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to
>> [email protected].
>> For more options, visit this group at
>> http://groups.google.com/group/protobuf?hl=en.
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Protocol Buffers" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/protobuf?hl=en.
>
--
You received this message because you are subscribed to the Google Groups
"Protocol Buffers" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/protobuf/-/nsniwl4fnl0J.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/protobuf?hl=en.