Question
Why will Pyinstaller not work with goose
files? Is it an issue with the executable creator or my code?
Code
from goose.Goose import Goose
url =
'http://sociedad.elpais.com/sociedad/2012/10/27/actualidad/1351332873_157836.html'
g = Goose({'debug':False,'enableImageFetching': False,'localStoragePath':'./tmp'})
article = g.extractContent(url=url)
#article.title
print article.cleanedArticleText[:150].encode("utf8","ignore")
Error Log From Pyinstaller
My program, created with pyinstaller, fails to find goose files in this path:
IOError: Couldn't open file C:\Users\user\Desktop\dist\main.exe?118272\goose/resources/text/stopwords-en.txt
This happens:
Traceback (most recent call last):
File "<string>", line 15, in <module>
File "C:\Users\user\Desktop\build\pyi.win32\main\out00-PYZ.pyz\goose.Goose",line 52, in extractContent
File "C:\Users\user\Desktop\build\pyi.win32\main\out00-PYZ.pyz\goose.Goose",line 59, in sendToActor
File "C:\Users\user\Desktop\build\pyi.win32\main\out00-PYZ.pyz\goose.Crawler", line 86, in crawl
File "C:\Users\user\Desktop\build\pyi.win32\main\out00-PYZ.pyz\goose.extractors", line 245, in calculateBestNodeBasedOnClustering
File "C:\Users\user\Desktop\build\pyi.win32\main\out00-PYZ.pyz\goose.text", line 97, in __init__
File "C:\Users\user\Desktop\build\pyi.win32\main\out00-PYZ.pyz\goose.utils",line 76, in loadResourceFile
IOError: Couldn't open file C:\Users\user\Desktop\dist\main.exe?118272\goose/resources/text/stopwords-en.txt
What's wrong?
It seems as though goose
requires data files in addition the Python source for normal operation. eg. It looks up goose/resources/text/stopwords-en.txt
. When you freeze the Python app with PyInstaller, if goose
looks in the standard filesystem locations for its resource files they will not be present since when you create an executable with PyInstaller, all of the files are within the installer.
So, you have to tell PyInstaller to add these extra resources to your executable, then modify the goose
code to obtain its resources from an alternate location when run from the the exe generated by PyInstaller.
Details are in the PyInstaller manual under the Accessing Data Files heading.