2015-04-17 150 views
4

我正在嘗試使用pkg_resources加載我的項目中存在的一個資源,但它只是拋出一個異常,說它報價爲「無法在沒有'get_data() '「。我不確定是否在這裏做錯了什麼,或者如果pkg_resources在python 3.3上不知何故被破壞。我正在使用python 3.3.3。這裏是我試圖執行的代碼pkg_resources.resource_stream在python3上失敗

>>> 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()' 
>>> 

有沒有人有關於如何解決這個問題的想法?

+2

該死的我實際上在我的項目文件夾中沒有'__init __。py'!所以問題解決了!對於那個很抱歉。 – flazzarini

回答

7

發生這種情況的原因很多,但最常見的是該包不是可導入的模塊,因爲沒有__init__.py