Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NameError: global name 'templatePrefix' is not defined #35

Closed
ChameleonRed opened this issue Oct 24, 2015 · 11 comments
Closed

NameError: global name 'templatePrefix' is not defined #35

ChameleonRed opened this issue Oct 24, 2015 · 11 comments

Comments

@ChameleonRed
Copy link

What does mean this bug and why it occurs?

N File "C:\Users\Crezary Wagner\Documents\GitHub\wikipedia-extractor\WikiExtractor.py", line 1896, in clean
ameError: global name 'templatePrefix' is not defined

@kloppjp
Copy link

kloppjp commented Oct 24, 2015

Could you state your python version (type "python" into your command line), your OS and if any, which python environment you are using, e.g. Anaconda, Canopy etc.
It may also be helpful if you could post the entire bug report and check if your version is up to date as the line you are referring to does not contain any reference to the variable "templatePrefix".

@attardi
Copy link
Owner

attardi commented Oct 25, 2015

This problem was reported before by someone using Python on Windows.
The variable templatePrefix is a global variable initialized from a value in the site info XML element.
It turned out to be a bug in the Python implementation of Windows, that does not handle globals as specified by the language.
The suggested patch was to add:
templatePrefix = ''
at the beginning of the script.

@SangdongWyverns
Copy link

@attardi
I faced same problem with @ChameleonRed and applied your solution but I show another bug like this.
File "C:\Python27\lib\multiprocessing\procss.py", line 258, in _bootstrap
self.run()
File "C:\Python27\lib\multiprocessing\procss.py", line 114, in run
self._target(self._args, *self._kwargs)
File D:\Download\WikiExtractor.py", line 2447, in reduce_process
output.write(ordering_buffer.pop(next_ordinal))
File D:\Download\WikiExtractor.py", line 2447, in write
self.reserve(len(data))
File D:\Download\WikiExtractor.py", line 2447, in reserve
if self.file.tell() + size > self.max_file_size:
ValueError: I/O operation on closed file.

@attardi
Copy link
Owner

attardi commented Oct 25, 2015

That also happened before with Windows. Python implementation does not support properly StringIO.
I will put a notice that WikiExtractor might not run on Windows, due to bugs in the Python implementation.

@ChameleonRed
Copy link
Author

$python --version
Python 2.7.9

Windows + Python 32.

@ChameleonRed
Copy link
Author

$python
Python 2.7.9 (default, Dec 10 2014, 12:24:55) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.

@ChameleonRed
Copy link
Author

I have not problems with StringIO on Windows - so I think it is not StringIO myth.

Problem with variables is not StringIO I think - tell why do you think that StringIO explain it in details?

@attardi
Copy link
Owner

attardi commented Oct 26, 2015

The problem with StringIO arises only when using it in a multiprocessing configuration. The error message is weird, saying the file has been closed.
I was told that it happens even before anything gets written to the file.
Can you confirm this?
If you can find another explanation, I would like to know.

@attardi
Copy link
Owner

attardi commented Oct 26, 2015

The problem with the global variable templatePrefix is unrelated with StringIO.
If you look at the code, templatePrefix is assigned at the very beginning in function process_dump(), while reading the siteinfo header.
Its value is taken from the element <namespace key="10">, which must be present if templates are used.
You might check if your dump contains it, looking at the first few lines.

@attardi
Copy link
Owner

attardi commented Nov 19, 2015

Fixed.

@attardi attardi closed this as completed Nov 19, 2015
@ChameleonRed
Copy link
Author

I will test it if fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants