pythonmodulepyinstallermodulenotfounderrorpython-3.12

PyInstaller ModuleNotFoundError: No module named 'art'


I wrote some python code that uses the 'art' module. I simply imported it like this:

import art as a

When I run it using the .py file, it works perfectly.

I used "pyinstaller --onefile file.py". It seemed to work, but when I ran the .exe file in the "dist"-folder, the terminal instantly closed. When I ran the exe from terminal, it gave me the following error:

"ModuleNotFoundError: No module named 'art'."

I tried using "--hidden-import=art" to fix it, but that didn't change anything.


Solution

  • First, go to python's site-packages directory and copy the art package folder. copy art package


    Second, paste the art package folder at your project's root directory. paste art package


    At last, build the exe. Whatever your command is, you should use --add-datacommand to add the art package folder into the exe.

    pyinstaller --onefile --add-data="art/*;art" main.py
    

    --add-data="art/*;art" this means to add all the files and subfolders inside the art folder to the art folder created inside the exe.