I am trying to convert a Python script into a standalone executable using both PyInstaller and py2exe. However, I'm encountering a ModuleNotFoundError for the undetected_chromedriver module in both cases. My Python version is 3.11.7. The script runs perfectly in my development environment, but when packaged with PyInstaller or py2exe, it fails to recognize the undetected_chromedriver module.
Attempt with PyInstaller:
I used the following command with PyInstaller:
pyinstaller --clean --onefile --debug=all .\main.py
The build completes successfully, but running the executable yields:
ModuleNotFoundError: No module named 'undetected_chromedriver'
Attempt with py2exe:
For py2exe, I used this setup script (setup.py):
from distutils.core import setup
import py2exe
setup(console=['main.py'])
And ran the build using:
python setup.py py2exe
Again, the build is successful, but the executable produces the same ModuleNotFoundError.
Details:
- Python Version: 3.11.7
- OS: Windows 10
- The script runs without issues in
PyCharmand via theWindows command line. undetected_chromedriveris installed and working in the development environment.
I have tried using the --hidden-import flag with PyInstaller and specifying includes in the setup.py for py2exe without success.
- How can I resolve the
ModuleNotFoundErrorforundetected_chromedriverwhen usingPyInstallerandpy2exe? - Are there specific considerations for
undetected_chromedriverwith these tools that I might be missing?