Open evensonliu opened 2 years ago
It can be work around by add freeze_support before import undetected_chromedriver .
However, I don't know why it can !
from multiprocessing import freeze_support freeze_support() from selenium.webdriver.chrome.options import Options from selenium.webdriver.chrome.webdriver import WebDriver import undetected_chromedriver as uc
python版本3.7.9 undetected-chromedriver版本3.1.2 pyinstaller版本4.8 即使
from multiprocessing import freeze_support
freeze_support()
再或者指定参数use_subprocess
self.browser = uc.Chrome(suppress_welcome=False, options=options,use_subprocess=True,
executable_path=resource_path("chromedriver.exe"))
打包后本地运行没问题,但是换台电脑就不可以了
Process Process-1:
Traceback (most recent call last):
File "multiprocessing\process.py", line 297, in _bootstrap
File "multiprocessing\process.py", line 99, in run
File "undetected_chromedriver\dprocess.py", line 59, in _start_detached
File "subprocess.py", line 800, in __init__
File "subprocess.py", line 1148, in _execute_child
File "subprocess.py", line 555, in list2cmdline
TypeError: argument of type 'NoneType' is not iterable
python版本3.7.9 undetected-chromedriver版本3.1.2 pyinstaller版本4.8 即使
from multiprocessing import freeze_support freeze_support()
再或者指定参数use_subprocess
self.browser = uc.Chrome(suppress_welcome=False, options=options,use_subprocess=True, executable_path=resource_path("chromedriver.exe"))
打包后本地运行没问题,但是换台电脑就不可以了
Process Process-1: Traceback (most recent call last): File "multiprocessing\process.py", line 297, in _bootstrap File "multiprocessing\process.py", line 99, in run File "undetected_chromedriver\dprocess.py", line 59, in _start_detached File "subprocess.py", line 800, in __init__ File "subprocess.py", line 1148, in _execute_child File "subprocess.py", line 555, in list2cmdline TypeError: argument of type 'NoneType' is not iterable
This is mostly like to caused by Chrome.exe not found by undetected-chromedriver if you don't specific the browser_executable_path on call uc.Chrome. You can solve it by refer to this:
https://github.com/ultrafunkamsterdam/undetected-chromedriver/issues/497
python版本3.7.9 undetected-chromedriver版本3.1.2 pyinstaller版本4.8 即使
from multiprocessing import freeze_support freeze_support()
再或者指定参数use_subprocess
self.browser = uc.Chrome(suppress_welcome=False, options=options,use_subprocess=True, executable_path=resource_path("chromedriver.exe"))
打包后本地运行没问题,但是换台电脑就不可以了
Process Process-1: Traceback (most recent call last): File "multiprocessing\process.py", line 297, in _bootstrap File "multiprocessing\process.py", line 99, in run File "undetected_chromedriver\dprocess.py", line 59, in _start_detached File "subprocess.py", line 800, in __init__ File "subprocess.py", line 1148, in _execute_child File "subprocess.py", line 555, in list2cmdline TypeError: argument of type 'NoneType' is not iterable
This is mostly like to caused by Chrome.exe not found by undetected-chromedriver if you don't specific the browser_executable_path on call uc.Chrome. You can solve it by refer to this:
497
Thank you. It's been very productive
Hi, please try it on this way.
def resource_path(relative_path):
""" Get absolute path to resource, works for dev and for PyInstaller """
base_path = getattr(sys, '_MEIPASS', os.path.dirname(os.path.abspath(__file__)))
return os.path.join(base_path, relative_path)
driver = uc.Chrome(options=options, executable_path=resource_path("./selenium/webdriver/chromedriver.exe"))
a = Analysis(
['myscripts.py'],
pathex=[],
datas=[],
binaries=[ ('./chromedriver_win32/chromedriver.exe', '.\\selenium\\webdriver') ],
hiddenimports=[],
hookspath=[],
hooksconfig={},
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False,
)
pyinstaller myscripts.spec
Problem as described by OP remains unchanged:
pyinstaller v 5.1
python v 3.9.13
macos 12.2.1
(Interestingly, this is first report I have seen on macOS.)
It's ok directly run it by python codes, but failed when packaged it into a windows executable file with pyinstaller.
TEST CODES
It's good to run it directly
Run as an executable file
package cmd
run results, it would never end up until memory error occur(all used by it).
and it would never print('1111111111111') and print('2222222222222').
Environment
os: win10 professional, 20H2 edition hardware:
python: Python 3.8.8 (default, Apr 13 2021, 15:08:07) [MSC v.1916 32 bit (Intel)] :: Anaconda, Inc. on win32
pyinstaller: 4.8