Graduation Baling Spider with cx_Freeze or py2exe

I created a scraper with Scrapy and wxPython, which works as expected, exporting the results file to the desktop in CSV format. I am trying to pack it into an executable using cx_Freeze using the following command line:

cxfreeze ItemStatusChecker.py --target-dir dist

This seems to work fine by creating a dist directory using ItemStatusChecker.exe

However, when I open ItemStatusChecker.exe, I get the following error on the command line and my GUI does not start:

Traceback (most recent call last):
    File "C:\Python27\lib\site-packages\cx_Freeze\initscripts\Console.py", line 27, in <module>
      exec code in m.__dict__
    File "ItemStatusChecker.py", line 6, in <module>
    File "C:\Python27\lib\site-packages\scrapy\__init__.py", line 6, in <module>
      __version__ = pkgutil.get_data(__package__, 'VERSION').strip()
    File "C:\Python27\lib\pkgutil.py", line 591, in get_data
      return loader.get_data(resource_name_)
IOError: [Errno 2] No such file or directory: 'scrapy\\VERSION'

I tried to run it through py2exe. This also works fine when creating the dist directory, but when I try to start exe I get a very similar error:

Traceback (most recent call last):
  File "ItemStatusChecker.py", line 6, in <module>
  File "scrapy\__init__.pyc", line 6, in <module>
  File "pkgutil.pyc", line 591, in get_data
IOError: [Errno 2] No such file or directory: 'scrapy\\VERSION'

python, , . , !

0
2

(http://cx-freeze.readthedocs.org/en/latest/faq.html#using-data-files)

cx-freeze:

C:\Python2.7\Lib\site-packages\scrapy__init __. py

import sys
# Scrapy version
import pkgutil
if getattr(sys, 'frozen', False):
    __version__ = 'VERSION'.decode('ascii').strip()
else:
    __version__ = pkgutil.get_data(__package__, 'VERSION').decode('ascii').strip()

C:\Python2.7\Lib\site-packages\scrapy\responsetypes.py

import sys
from mimetypes import MimeTypes
from pkgutil import get_data
...
   def __init__(self):
        self.classes = {}
        self.mimetypes = MimeTypes()
        if getattr(sys, 'frozen', False):
            mimedata = 'mime.types'
        else:
            mimedata = get_data('scrapy', 'mime.types')
        self.mimetypes.readfp(StringIO(mimedata))

setup.py exe

"include_files": [("C:\\Python27\\Lib\\site-packages\\scrapy\\VERSION","VERSION"),
    ("C:\\Python27\\Lib\\site-packages\\scrapy\\mime.types","mime.types")]}
0

Source: https://habr.com/ru/post/1543216/


All Articles