1

Python script (v3.6) runs fine in PyCharm, however when the same is converted via Auto Py To Exe then gives following error in CMD.

Traceback (most recent call last):
  File "export_members.py", line 2, in <module>
ModuleNotFoundError: No module named 'pymysql'
[13936] Failed to execute script export_members

Similar error is given if pyinstaller is used to generate an executable, is there a way i can specify import (pymysql) with either one?

Edit: .spec file

# -*- mode: python ; coding: utf-8 -*-

block_cipher = None


a = Analysis(['export_members.py'],
             pathex=['C:\\Users\\x64\\PycharmProjects\\export_members'],
             binaries=[],
             datas=[],
             hiddenimports=['pymysql'],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher,
             noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)
exe = EXE(pyz,
          a.scripts,
          [],
          exclude_binaries=True,
          name='export_members',
          debug=False,
          bootloader_ignore_signals=False,
          strip=False,
          upx=True,
          console=True )
coll = COLLECT(exe,
               a.binaries,
               a.zipfiles,
               a.datas,
               strip=False,
               upx=True,
               upx_exclude=[],
               name='export_members')

Trying with following from CMD:

pyinstaller export_members.spec
Dima Chubarov
  • 16,199
  • 6
  • 40
  • 76
Ayub
  • 510
  • 2
  • 6
  • 21
  • 1
    Pyinstaller allows you to manually define "hidden" imports. See [PyInstaller - Using Spec Files](https://pythonhosted.org/PyInstaller/spec-files.html) and [PyInstaller - When Things Go Wrong](https://pyinstaller.readthedocs.io/en/stable/when-things-go-wrong.html). – Xukrao Oct 31 '19 at 11:17
  • even specified under hidden imports, same ModuleNotFoundError, please see updated question – Ayub Oct 31 '19 at 11:36
  • If you're using virtualenv/conda environments, then did you double-check that the active environment during the pyinstaller run is the same as the one during the PyCharm run? – Xukrao Oct 31 '19 at 12:17
  • I believe its not virtualized environment by that I mean it is just python 3.6 and PyCharm installation on top on a windows pc – Ayub Oct 31 '19 at 13:30

1 Answers1

0

Ran following once more, although i had it already installed:

pip install PyMySQL

Generated the executable using Pyinstaller and it worked fine.

Ayub
  • 510
  • 2
  • 6
  • 21