以下是我的代码的截短版本,可以使用Jupyter Notebook完美运行。我希望使用Pyinstaller将其编译成.exe。
import pandas as pd
import numpy as np
from selenium import webdriver
import os, sys
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.by import By
import selenium.webdriver.support.expected_conditions as ec
def resource_path(relative_path):
""" Get absolute path to resource, works for dev and for PyInstaller """
try:
# PyInstaller creates a temp folder and stores path in _MEIPASS
base_path = sys._MEIPASS
except Exception:
base_path = os.path.abspath(".")
return os.path.join(base_path, relative_path)
driver = webdriver.Chrome(r"C:\Users\User\Desktop\Folder\chromedriver.exe")
driver.implicitly_wait(10)
driver.maximize_window()
driver.get("www.google.com")
wait_proxy = input("Press any key to exit...")
我通过引用Stack Overflow上的一些帖子添加了resource_path
函数,但不确定是否确实需要它。
不幸的是,我得到如下错误:
PS C:\Users\User\Desktop\Folder> pyinstaller Simple.py
78 INFO: PyInstaller: 3.5
78 INFO: Python: 3.8.0
78 INFO: Platform: Windows-10-10.0.18362-SP0
78 INFO: wrote C:\Users\User\Desktop\Folder\Simple.spec
78 INFO: UPX is not available.
78 INFO: Extending PYTHONPATH with paths
['C:\\Users\\User\\Desktop\\Folder', 'C:\\Users\\User\\Desktop\\Folder']
78 INFO: checking Analysis
93 INFO: checking PYZ
93 INFO: Building PYZ because PYZ-00.toc is non existent
109 INFO: Building PYZ (ZlibArchive) C:\Users\User\Desktop\Folder\build\Simple\PYZ-00.pyz
Traceback (most recent call last):
File "c:\users\user\appdata\local\programs\python\python38\lib\runpy.py", line 192, in _run_module_as_main
return _run_code(code, main_globals, None,
File "c:\users\user\appdata\local\programs\python\python38\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Users\User\AppData\Local\Programs\Python\Python38\Scripts\pyinstaller.exe\__main__.py", line 9, in <module>
File "c:\users\user\appdata\local\programs\python\python38\lib\site-packages\PyInstaller\__main__.py", line 111, in run
run_build(pyi_config, spec_file, **vars(args))
File "c:\users\user\appdata\local\programs\python\python38\lib\site-packages\PyInstaller\__main__.py", line 63, in run_build
PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
File "c:\users\user\appdata\local\programs\python\python38\lib\site-packages\PyInstaller\building\build_main.py", line 844, in main
build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
File "c:\users\user\appdata\local\programs\python\python38\lib\site-packages\PyInstaller\building\build_main.py", line 791, in build
exec(code, spec_namespace)
File "C:\Users\User\Desktop\Folder\Simple.spec", line 18, in <module>
pyz = PYZ(a.pure, a.zipped_data,
File "c:\users\user\appdata\local\programs\python\python38\lib\site-packages\PyInstaller\building\api.py", line 98, in __init__
self.__postinit__()
File "c:\users\user\appdata\local\programs\python\python38\lib\site-packages\PyInstaller\building\datastruct.py", line 158, in __postinit__
self.assemble()
File "c:\users\user\appdata\local\programs\python\python38\lib\site-packages\PyInstaller\building\api.py", line 128, in assemble
self.code_dict = {
File "c:\users\user\appdata\local\programs\python\python38\lib\site-packages\PyInstaller\building\api.py", line 129, in <dictcomp>
key: strip_paths_in_code(code)
File "c:\users\user\appdata\local\programs\python\python38\lib\site-packages\PyInstaller\building\utils.py", line 652, in strip_paths_in_code
consts = tuple(
File "c:\users\user\appdata\local\programs\python\python38\lib\site-packages\PyInstaller\building\utils.py", line 653, in <genexpr>
strip_paths_in_code(const_co, new_filename)
File "c:\users\user\appdata\local\programs\python\python38\lib\site-packages\PyInstaller\building\utils.py", line 660, in strip_paths_in_code
return code_func(co.co_argcount, co.co_kwonlyargcount, co.co_nlocals, co.co_stacksize,
TypeError: an integer is required (got type bytes)
我的规格文件如下:
# -*- mode: python ; coding: utf-8 -*-
block_cipher = None
a = Analysis(['Simple.py'],
pathex=['C:\\Users\\User\\Desktop\\Folder'],
binaries=[],
datas=[],
hiddenimports=[],
hookspath=[],
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,
[],
exclude_binaries=True,
name='Simple',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
console=True )
coll = COLLECT(exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=True,
upx_exclude=[],
name='Simple')
答案 0 :(得分:3)
点安装https://github.com/pyinstaller/pyinstaller/archive/develop.tar.gz
直接安装最新版本可以与python 3.8兼容
答案 1 :(得分:1)
如果您使用的是python 3.8,请尝试降级,因为pyinstaller不支持所有新的python版本