【发布时间】:2021-01-04 19:05:00
【问题描述】:
我正在尝试将 python 模块(邮政编码)包含到我正在转换为 EXE 的程序中。第一次尝试 - 包含该模块数据的 bz2 文件未加载 - 所以我更改了命令行以提取该数据。
测试程序就像下面的(ziptest.py)代码一样简单:
import zipcodes
print('Test message')
checkzip=zipcodes.matching('92688')
print(checkzip)
print("returned the right record:", checkzip[0]['zip_code']=='92688')
pyinstaller 安装命令是:
pyinstaller --debug all --onefile ziptest.py --add-data "venv\lib\site-packages\zipcodes\zips.json.bz2;zipcodes\zips.json.bz2"
当我运行程序并捕获 STDERR - 我认为最相关的代码行是:
import 'json.encoder' # <_frozen_importlib_external.SourcelessFileLoader object at 0x0000019824E121C8>
import 'json' # <_frozen_importlib_external.SourcelessFileLoader object at 0x0000019824E018C8>
Traceback (most recent call last):
File "ziptest.py", line 1, in <module>
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "c:\users\ken\onedrive - rootdir\code\companyppi-scripts\temp_dir\validation\venv\lib\site-packages\zipcodes\__init__.py", line 32, in <module>
with bz2_open(_zips_json, "rb") as f:
File "C:\Users\ken\AppData\Local\Programs\Python\Python37\lib\bz2.py", line 318, in open
binary_file = BZ2File(filename, bz_mode, compresslevel=compresslevel)
File "C:\Users\ken\AppData\Local\Programs\Python\Python37\lib\bz2.py", line 92, in __init__
self._fp = _builtin_open(filename, mode)
PermissionError: [Errno 13] Permission denied: 'C:\\Users\\ken\\AppData\\Local\\Temp\\_MEI65962\\zipcodes\\zips.json.bz2'
[10396] LOADER: Cleaning up Python interpreter.
# cleanup[3] wiping _codecs
我可能需要根据我目前所看到的研究内容为这个模块编写一个钩子,但在我深入研究之前,我想确保这是正确的路径。我必须相信还有其他模块可以从模块安装中提取源数据 - 所以我想让我的方法适合解决方案。
【问题讨论】:
标签: python python-3.x windows windows-10 pyinstaller