I am working on a news crawling program and want to take my python file and turn it into an executable application. But I am having a lot of trouble with the newspaper3k library. My program works fine on PyCharm, but when I try to run the executable functions relying on newspaper3k are broken. I get the following error:
Error occurred while processing author and published date for https://www.npr.org/2023/05/04/1174015808/nfl-investigation-claims-gender-discrimination-harassment#:~:text=The%20attorneys%20general%20of%20California: [Errno 2] No such file or directory: '/Users/.../dist/headline_hunter/newspaper/resources/text'
I tried a number of different things, including creating a hook file and a spec file and using them with pyinstaller:
from PyInstaller.utils.hooks import collect_data_files
datas = collect_data_files('newspaper3k')
and
# -*- mode: python ; coding: utf-8 -*-
from PyInstaller.utils.hooks import collect_data_files
block_cipher = None
datas = collect_data_files('newspaper3k')
a = Analysis(
['headline_hunter.py'],
pathex=[],
binaries=[],
datas=datas,
hiddenimports=[],
hookspath=['.'],
hooksconfig={},
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False,
)
pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)
exe = EXE(
pyz,
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
[],
name='headline_hunter',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
upx_exclude=[],
runtime_tmpdir=None,
console=True,
disable_windowed_traceback=False,
argv_emulation=False,
target_arch=None,
codesign_identity=None,
entitlements_file=None,
)
I also tried copying the resources folder into the same directory as my script and doing this:
pyinstaller --add-data "resources:./newspaper/resources" headline_hunter.py
Any help would be much appreciated.