Search code examples
pythonselenium-webdriverweb-scrapingpipexe

Problems with .exe file after converting it from .py. "ModuleNotFoundError: no module named 'selenium'"


Hear me out: Quite a newbie with Python. I totally may have messed up somewhere in this.

Here's the error message in full:

Traceback (most recent call last):
  File "webScrapingTool.py", line 1, in <module>
    from selenium import webdriver
ModuleNotFoundError: No module named 'selenium'

I wrote the code on Ubuntu 22.04, whose default Python version is 3.10.4. I have a dual-boot system. I had not realized that I apparently(?) needed to make a Windows executable directly in Windows, so I moved the file to there and tried. I downloaded Python for Windows, whose version is 3.12.2. As far as I understand, this is possibly part one of the problem.

Keep in mind that I have tried both 'pyinstaller' and 'auto-py-to-exe' on Ubuntu and I tried 'pyinstaller' on Windows too. When I create the executable in Windows, it will show the error message as above.

As mentioned, I am almost brand new to Python and I did a pretty basic project, but I really need to know what the issue is with finally making my file executable/usable for the average person.

When I try to do "pip install cx_freeze" or to install the 'requirements.txt' with pip, I get the error message like this:

https://pastebin.com/KheA21nM

The leads that I can give with this are that I'm almost certain that it is associated with where the program was written versus where the executable is being made (two different Python versions). I have seen a few pages that mentioned 'hiddenimports' in the .spec file, but no luck from what some suggested. Hopefully somebody knows exactly what I mean because while there are similar questions here, none of them are exactly like my situation here. Please let me know of anything that I can do to fix this. Thanks!


Solution

  • Description:

    Inside the error focus on this line:

    error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": [url here - Reddit doesn't like links, so I removed it)
    

    This indicates that you have to install or upgrade your previous version of Microsoft Visual C++. As C++ plays a vital role in converting your python file into a windows executable.

    Secondly, if you familiar with manual library importing in pyinstaller, perform that action for the libraries that can't be installed by pyinstaller.