ModuleNotFoundError for 'undetected_chromedriver' with PyInstaller and py2exe in Python 3.11.7

57 Views Asked by At

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 PyCharm and via the Windows command line.
  • undetected_chromedriver is 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.

  1. How can I resolve the ModuleNotFoundError for undetected_chromedriver when using PyInstaller and py2exe?
  2. Are there specific considerations for undetected_chromedriver with these tools that I might be missing?
0

There are 0 best solutions below