Python Forum
Help with pyinstaller "No module named" - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Help with pyinstaller "No module named" (/thread-40121.html)



Help with pyinstaller "No module named" - korenron - Jun-06-2023

Hello,
I'm trying to create a EXE file from my (Working) python code.

When I try to run the exe file I get the error:
Traceback (most recent call last):
  File "Test_data.py", line 4, in <module>
ModuleNotFoundError: No module named 'mysql.connector'
[9768] Failed to execute script 'Test_data' due to unhandled exception!
why is it?
when I run pyinstaller isn't it store all the packages into the exe file?

Thanks,


RE: Help with pyinstaller "No module named" - Axel_Erfurt - Jun-06-2023

Maybe it's your imports?


RE: Help with pyinstaller "No module named" - deanhystad - Jun-06-2023

You really should post code along with the error.

You'll need to install mysql connector (and possibly mysql server) on the machine that runs your exe. mysql-connector-python is an interface to mysql connector, not a python version of mysql connector.


RE: Help with pyinstaller "No module named" - rajeshgk - Jun-06-2023

Do you have the below installed?

pip install mysql-connector-python


RE: Help with pyinstaller "No module named" - korenron - Jun-07-2023

everything is install wand working on my Py-Charm
now that I install using pip3 - it's working

so why the Pyinstaller won't take the package and put it in the exe file ?
isn't it all the purpose of using exe file ? (everything in 1 place)?


RE: Help with pyinstaller "No module named" - Axel_Erfurt - Jun-07-2023

Do you have this imports ?

import mysql
import mysql.connector



RE: Help with pyinstaller "No module named" - buran - Jun-07-2023

Read Helping PyInstaller Find Modules


RE: Help with pyinstaller "No module named" - korenron - Jun-15-2023

me again
same problem with another package


C:\>cd C:\Users\user\Documents\Codes\Python\Projects\pythonProject4\dist

C:\Users\user\Documents\Codes\Python\Projects\pythonProject4\dist>Ebus.exe
Traceback (most recent call last):
  File "Test_data.py", line 4, in <module>
ModuleNotFoundError: No module named 'routeros_api'
[7768] Failed to execute script 'Test_data' due to unhandled exception!

C:\Users\user\Documents\Codes\Python\Projects\pythonProject4\dist>pip install routeros_api
Requirement already satisfied: routeros_api in c:\users\user\appdata\local\programs\python\python310\lib\site-packages (0.17.0)
Requirement already satisfied: six in c:\users\user\appdata\local\programs\python\python310\lib\site-packages (from routeros_api) (1.16.0)

C:\Users\user\Documents\Codes\Python\Projects\pythonProject4\dist>pip3 install routeros_api
Requirement already satisfied: routeros_api in c:\users\user\appdata\local\programs\python\python310\lib\site-packages (0.17.0)
Requirement already satisfied: six in c:\users\user\appdata\local\programs\python\python310\lib\site-packages (from routeros_api) (1.16.0)
but as you can see the module is install

also when I run the code from cmd
c:\Users\user\Documents\Codes\Python\Projects\pythonProject4>python Test_data.py
it's running
so what could be the problem? what is wrong now?

Thanks ,


RE: Help with pyinstaller "No module named" - buran - Jun-15-2023

As explained in the link I shared - there are cases where pyinstaller is unable to detect some imports (a.ka. hidden imports) and thus it does not include the respective modules/packages in the bundle. There are different steps you can take to help pyinstaller find which modules they need to include and where to locate them.
The modules are installed, but probably pyinstaller didn't include them in the bundle.


RE: Help with pyinstaller "No module named" - snippsat - Jun-15-2023

It work when i test,i use virtual environment always when troubleshoot Pyinstaller.
# Make 
G:\div_code
λ python -m venv router_env

# Cd in
G:\div_code
λ cd router_env\

# Activate
G:\div_code\router_env
λ G:\div_code\router_env\Scripts\activate.bat

# Install
(router_env) G:\div_code\router_env
λ pip install pyinstaller RouterOS-api
.....
Installing collected packages: pywin32-ctypes, altgraph, six, pyinstaller-hooks-contrib, pefile, RouterOS-api, pyinstaller
Successfully installed RouterOS-api-0.17.0 altgraph-0.17.3 pefile-2023.2.7 pyinstaller-5.12.0
pyinstaller-hooks-contrib-2023.3 pywin32-ctypes-0.2.0 six-1.16.0
Test code:
# router.py
import routeros_api

connection = routeros_api.RouterOsApiPool('IP', username='admin', password='')
print(connection.username)
input('Press Enter to exit')
Build:
(router_env) G:\div_code\router_env
λ pyinstaller --onefile route.py
500 INFO: PyInstaller: 5.12.0
500 INFO: Python: 3.11.3
572 INFO: Platform: Windows-10-10.0.19045-SP0
.....
16020 INFO: Building EXE from EXE-00.toc completed successfully.
When run router.exe it print admin,so it work and find module routeros_api,
if not i would have gotten same error message as you get.