Pylons/pyramid — Issue #328: Instantiation of pyramid.config.Configurator from an interactive interpreter raises AttributeError
Author: xaba
Created: 2011-10-27 15:40:52+00:00
State: open

While running the hello world example found in the documentation, I changed the example to make it work without saving it in a file.
Doing so I encountered an issue.
To reproduce it, it is enough to type the following:
>>> from pyramid.config import Configurator
>>> config = Configurator()
Traceback (most recent call last):
File "", line 1, in
File "/usr/lib/python2.7/dist-packages/pyramid/config/__init__.py", line 232, in __init__
name_resolver = DottedNameResolver(package)
File "/usr/lib/python2.7/dist-packages/pyramid/util.py", line 79, in __init__
self.package = package_of(package)
File "/usr/lib/python2.7/dist-packages/pyramid/path.py", line 41, in package_of
pkg_name = package_name(pkg_or_module)
File "/usr/lib/python2.7/dist-packages/pyramid/path.py", line 31, in package_name
pkg_filename = pkg_or_module.__file__
AttributeError: 'module' object has no attribute '__file__'

So the problem seems to lie in the fact that in function package_name (from path.py), it is (wrongly) assumed that pkg_or_module always has the attribute __file__, which is not the case when run from an interactive interpreter.