Python Forum
Help with pyinstaller "No module named"
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with pyinstaller "No module named"
#1
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,
Reply
#2
Maybe it's your imports?
Reply
#3
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.
Reply
#4
Do you have the below installed?

pip install mysql-connector-python
Reply
#5
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)?
Reply
#6
Do you have this imports ?

import mysql
import mysql.connector
Reply
#7
Read Helping PyInstaller Find Modules
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#8
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 ,
Reply
#9
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.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#10
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.
buran likes this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  no module named 'docx' when importing docx MaartenRo 1 895 Dec-31-2023, 11:21 AM
Last Post: deanhystad
  Problem with pymodbus - ModuleNotFoundError: No module named 'pymodbus.client.sync' stsxbel 2 23,824 Nov-02-2023, 08:20 AM
Last Post: South_east
  ModuleNotFoundError: No module named 'requests' Serg 18 2,605 Oct-29-2023, 11:33 PM
Last Post: Serg
  Resolving ImportError: No module named gdb (Python in C++) mandaxyz 3 1,465 Oct-04-2023, 02:43 PM
Last Post: mandaxyz
  ModuleNotFoundError: No module named 'PyPDF2' Benitta2525 1 1,527 Aug-07-2023, 05:32 AM
Last Post: DPaul
  ModuleNotFoundError: No module named 'eyed3' Wimpy_Wellington 2 1,350 Jul-10-2023, 03:37 AM
Last Post: Wimpy_Wellington
  How to fix this error: ModuleNotFoundError: No module named 'notears' yaoyao22 2 1,050 Jul-09-2023, 11:24 AM
Last Post: yaoyao22
  Problem with Pyinstaller. No module named '_tkinter' tonynapoli2309 0 1,021 May-15-2023, 02:38 PM
Last Post: tonynapoli2309
  ModuleNotFoundError: No module named 'omsdk.sdkproto' donvito7 4 1,873 Oct-20-2022, 02:56 PM
Last Post: deanhystad
  ModuleNotFoundError: No module named '_struct' when starting pip3 yuhuihu 0 2,885 May-05-2022, 04:41 AM
Last Post: yuhuihu

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020