Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pkg_resources.resource_stream fails on python3

I am trying to load a resource which is present in my project using pkg_resources but it just throws me an exception saying that it quote "Can't perform this operation for loaders without 'get_data()'". I am not sure if I am doing something wrong here, or if pkg_resources is somehow broken on python 3.3. I am using python 3.3.3 to be exact. Here is the code I am trying to execute

>>> import pkg_resources
>>> data = pkg_resources.resource_stream('configgenerator', 'schema_rules.yml')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/users/frank/workspace/configgenerator/env/lib/python3.3/site-packages/distribute-0.6.31-py3.3.egg/pkg_resources.py", line 931, in resource_stream
    self, resource_name
  File "/home/users/frank/workspace/configgenerator/env/lib/python3.3/site-packages/distribute-0.6.31-py3.3.egg/pkg_resources.py", line 1207, in get_resource_stream
    return StringIO(self.get_resource_string(manager, resource_name))
  File "/home/users/frank/workspace/configgenerator/env/lib/python3.3/site-packages/distribute-0.6.31-py3.3.egg/pkg_resources.py", line 1210, in get_resource_string
    return self._get(self._fn(self.module_path, resource_name))
  File "/home/users/frank/workspace/configgenerator/env/lib/python3.3/site-packages/distribute-0.6.31-py3.3.egg/pkg_resources.py", line 1289, in _get
    "Can't perform this operation for loaders without 'get_data()'"
NotImplementedError: Can't perform this operation for loaders without 'get_data()'
>>> 

Does anyone has an idea on how to fix this?

like image 515
flazzarini Avatar asked Apr 17 '15 14:04

flazzarini


1 Answers

This can happen for a number of reasons, but the the most common is that the package is not an importable module because there is no __init__.py

like image 197
Gary van der Merwe Avatar answered Oct 05 '22 13:10

Gary van der Merwe