#1266 Python 3.x: `NameError: Unknown C global variable'

python (259)

How to reproduce

With the following files, run:
$ swig -python test.i # You may add `-py3' and still get the same error.
$ gcc -c -fPIC test.c test_wrap.c -I/usr/include/python3.2
$ gcc -shared test.o test_wrap.o -o _test.so
$ python3 -c 'import test; help(test)'
You may get:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/lib64/python3.2/site.py", line 458, in __call__
return pydoc.help(*args, **kwds)
File "/usr/lib64/python3.2/pydoc.py", line 1774, in __call__
File "/usr/lib64/python3.2/pydoc.py", line 1824, in help
else: doc(request, 'Help on %s:', output=self._output)
File "/usr/lib64/python3.2/pydoc.py", line 1560, in doc
pager(render_doc(thing, title, forceload))
File "/usr/lib64/python3.2/pydoc.py", line 1553, in render_doc
return title % desc + '\n\n' + renderer.document(object, name)
File "/usr/lib64/python3.2/pydoc.py", line 338, in document
if inspect.ismodule(object): return self.docmodule(*args)
File "/usr/lib64/python3.2/pydoc.py", line 1070, in docmodule
for key, value in inspect.getmembers(object, inspect.isclass):
File "/usr/lib64/python3.2/inspect.py", line 278, in getmembers
if not predicate or predicate(value):
File "/usr/lib64/python3.2/inspect.py", line 77, in isclass
return isinstance(object, type)
NameError: Unknown C global variable


extern int pia;


#include "test.h"
int pia = 0;


%module test
#include "test.h"
%include "test.h"


  • William Fulton

    William Fulton - 2012-12-09

    I think the choice of 'test' might be your problem. If you change all 'test' to 'example' it all works for me. If I use your example as is, I get the help for http://docs.python.org/library/test (Python 2.6 and Python 3.1). Please try again with a different module name and reopen if you still have problems.

  • William Fulton

    William Fulton - 2012-12-09
    • assigned_to: nobody --> wsfulton
    • status: open --> closed-works-for-me

Log in to post a comment.