2

I'm trying to build an executable from a module of mine with pyinstaller but every attempt to do this ended with:

File "C:\Python 3.6.5\lib\site-packages\PyInstaller\hooks\hook-clr.py", line 37, in <module>
raise Exception(pyruntime + ' not found')

Exception: Python.Runtime not found

After some research I found that this is due to pandas module. Infact every time I insert pandas import into module I get this error, without it pyinstaller does the job. I read that the cause may be that PyInstaller is grabbing pandas python code, but not grabbing the lib. So I tried to add

def get_pandas_path():
    import pandas
    pandas_path = pandas.__path__[0]
    return pandas_path


dict_tree = Tree(get_pandas_path(), prefix='pandas', excludes=["*.pyc"])
a.datas += dict_tree
a.binaries = filter(lambda x: 'pandas' not in x[0], a.binaries)

to spec file and launch

pyinstaller --onefile my_project.spec

as suggested in [this thread] (ImportError with Pyinstaller and Pandas) anyway I get the same error.

As requested, I'm adding the entire Traceback:

Traceback (most recent call last):
  File "C:\Python 3.6.5\Scripts\pyinstaller-script.py", line 11, in <module>
    load_entry_point('PyInstaller==3.4', 'console_scripts', 'pyinstaller')()
  File "c:\python 3.6.5\lib\site-packages\PyInstaller\__main__.py", line 111, in run
    run_build(pyi_config, spec_file, **vars(args))
  File "c:\python 3.6.5\lib\site-packages\PyInstaller\__main__.py", line 63, in run_build
    PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
  File "c:\python 3.6.5\lib\site-packages\PyInstaller\building\build_main.py", line 838, in main
    build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
  File "c:\python 3.6.5\lib\site-packages\PyInstaller\building\build_main.py", line 784, in build
    exec(text, spec_namespace)
  File "<string>", line 17, in <module>
  File "c:\python 3.6.5\lib\site-packages\PyInstaller\building\build_main.py", line 241, in __init__
    self.__postinit__()
  File "c:\python 3.6.5\lib\site-packages\PyInstaller\building\datastruct.py", line 158, in __postinit__
    self.assemble()
  File "c:\python 3.6.5\lib\site-packages\PyInstaller\building\build_main.py", line 500, in assemble
    module_hook.post_graph()
  File "c:\python 3.6.5\lib\site-packages\PyInstaller\building\imphook.py", line 410, in post_graph
    self._load_hook_module()
  File "c:\python 3.6.5\lib\site-packages\PyInstaller\building\imphook.py", line 377, in _load_hook_module
    self.hook_module_name, self.hook_filename)
  File "c:\python 3.6.5\lib\site-packages\PyInstaller\compat.py", line 736, in importlib_load_source
    return mod_loader.load_module()
  File "<frozen importlib._bootstrap_external>", line 399, in _check_name_wrapper
  File "<frozen importlib._bootstrap_external>", line 823, in load_module
  File "<frozen importlib._bootstrap_external>", line 682, in load_module
  File "<frozen importlib._bootstrap>", line 265, in _load_module_shim
  File "<frozen importlib._bootstrap>", line 684, in _load
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "c:\python 3.6.5\lib\site-packages\PyInstaller\hooks\hook-clr.py", line 37, in <module>
    raise Exception(pyruntime + ' not found')
Exception: Python.Runtime not found

Pyinstaller log:

421 INFO: PyInstaller: 3.4
421 INFO: Python: 3.6.5
421 INFO: Platform: Windows-10-10.0.17134-SP0
421 INFO: wrote C:\Users\LENOVO2\Desktop\GDPRScanner\GDPRScanner+Oracle\core2.spec
421 INFO: UPX is not available.
437 INFO: Extending PYTHONPATH with paths
['C:\\Users\\LENOVO2\\Desktop\\GDPRScanner\\GDPRScanner+Oracle',
 'C:\\Users\\LENOVO2\\Desktop\\GDPRScanner\\GDPRScanner+Oracle']
437 INFO: checking Analysis
437 INFO: Building Analysis because Analysis-00.toc is non existent
437 INFO: Initializing module dependency graph...
437 INFO: Initializing module graph hooks...
437 INFO: Analyzing base_library.zip ...
6201 INFO: running Analysis Analysis-00.toc
6232 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
  required by c:\python 3.6.5\python.exe
6295 WARNING: lib not found: api-ms-win-crt-heap-l1-1-0.dll dependency of c:\python 3.6.5\python.exe
6357 WARNING: lib not found: api-ms-win-crt-stdio-l1-1-0.dll dependency of c:\python 3.6.5\python.exe
6420 WARNING: lib not found: api-ms-win-crt-runtime-l1-1-0.dll dependency of c:\python 3.6.5\python.exe
6467 WARNING: lib not found: api-ms-win-crt-math-l1-1-0.dll dependency of c:\python 3.6.5\python.exe
6529 WARNING: lib not found: api-ms-win-crt-locale-l1-1-0.dll dependency of c:\python 3.6.5\python.exe
6592 WARNING: lib not found: api-ms-win-crt-heap-l1-1-0.dll dependency of c:\python 3.6.5\VCRUNTIME140.dll
6654 WARNING: lib not found: api-ms-win-crt-stdio-l1-1-0.dll dependency of c:\python 3.6.5\VCRUNTIME140.dll
6701 WARNING: lib not found: api-ms-win-crt-string-l1-1-0.dll dependency of c:\python 3.6.5\VCRUNTIME140.dll
6764 WARNING: lib not found: api-ms-win-crt-convert-l1-1-0.dll dependency of c:\python 3.6.5\VCRUNTIME140.dll
6826 WARNING: lib not found: api-ms-win-crt-runtime-l1-1-0.dll dependency of c:\python 3.6.5\VCRUNTIME140.dll
6982 WARNING: lib not found: api-ms-win-crt-heap-l1-1-0.dll dependency of c:\python 3.6.5\python36.dll
7045 WARNING: lib not found: api-ms-win-crt-stdio-l1-1-0.dll dependency of c:\python 3.6.5\python36.dll
7107 WARNING: lib not found: api-ms-win-crt-locale-l1-1-0.dll dependency of c:\python 3.6.5\python36.dll
7170 WARNING: lib not found: api-ms-win-crt-string-l1-1-0.dll dependency of c:\python 3.6.5\python36.dll
7248 WARNING: lib not found: api-ms-win-crt-environment-l1-1-0.dll dependency of c:\python 3.6.5\python36.dll
7310 WARNING: lib not found: api-ms-win-crt-convert-l1-1-0.dll dependency of c:\python 3.6.5\python36.dll
7373 WARNING: lib not found: api-ms-win-crt-runtime-l1-1-0.dll dependency of c:\python 3.6.5\python36.dll
7420 WARNING: lib not found: api-ms-win-crt-time-l1-1-0.dll dependency of c:\python 3.6.5\python36.dll
7482 WARNING: lib not found: api-ms-win-crt-math-l1-1-0.dll dependency of c:\python 3.6.5\python36.dll
7545 WARNING: lib not found: api-ms-win-crt-conio-l1-1-0.dll dependency of c:\python 3.6.5\python36.dll
7607 WARNING: lib not found: api-ms-win-crt-filesystem-l1-1-0.dll dependency of c:\python 3.6.5\python36.dll
7654 WARNING: lib not found: api-ms-win-crt-process-l1-1-0.dll dependency of c:\python 3.6.5\python36.dll
7654 INFO: Caching module hooks...
7670 INFO: Analyzing C:\Users\LENOVO2\Desktop\script\core2.py
8263 INFO: Processing pre-find module path hook   distutils
8763 INFO: Processing pre-safe import module hook   six.moves
12200 INFO: Processing pre-safe import module hook   setuptools.extern.six.moves
13028 INFO: Processing pre-find module path hook   site
13028 INFO: site: retargeting to fake-dir 'c:\\python 3.6.5\\lib\\site-packages\\PyInstaller\\fake-modules'
27415 INFO: Loading module hooks...
27415 INFO: Loading module hook "hook-distutils.py"...
27431 INFO: Loading module hook "hook-encodings.py"...
27540 INFO: Loading module hook "hook-lib2to3.py"...
27556 INFO: Loading module hook "hook-lxml.etree.py"...
27556 INFO: Loading module hook "hook-numpy.core.py"...
27899 INFO: Loading module hook "hook-numpy.py"...
27899 INFO: Loading module hook "hook-openpyxl.py"...
27915 INFO: Loading module hook "hook-pandas.py"...
28805 INFO: Loading module hook "hook-pkg_resources.py"...
29399 INFO: Processing pre-safe import module hook   win32com
29537 INFO: Loading module hook "hook-pydoc.py"...
29552 INFO: Loading module hook "hook-pythoncom.py"...
29927 INFO: Loading module hook "hook-pytz.py"...
30021 INFO: Loading module hook "hook-pywintypes.py"...
30427 INFO: Loading module hook "hook-regex.py"...
30443 INFO: Loading module hook "hook-setuptools.py"...
31162 INFO: Loading module hook "hook-sqlalchemy.py"...
31662 INFO:   Found 4 sqlalchemy hidden imports
31662 WARNING: Hidden import "pysqlite2" not found!
34489 WARNING: Hidden import "sqlalchemy.sql.functions.func" not found!
34489 INFO: Import to be excluded not found: 'sqlalchemy.testing'
34489 INFO: Loading module hook "hook-sqlite3.py"...
34630 INFO: Loading module hook "hook-sysconfig.py"...
34630 INFO: Loading module hook "hook-win32com.py"...
34739 INFO: Loading module hook "hook-xml.etree.cElementTree.py"...
34755 INFO: Loading module hook "hook-xml.py"...
34864 INFO: Loading module hook "hook-_mysql.py"...
34864 INFO: Loading module hook "hook-_tkinter.py"...
34942 WARNING: lib not found: api-ms-win-crt-stdio-l1-1-0.dll dependency of c:\python 3.6.5\DLLs\_tkinter.pyd
34989 WARNING: lib not found: api-ms-win-crt-string-l1-1-0.dll dependency of c:\python 3.6.5\DLLs\_tkinter.pyd
35067 WARNING: lib not found: api-ms-win-crt-runtime-l1-1-0.dll dependency of c:\python 3.6.5\DLLs\_tkinter.pyd
35270 INFO: checking Tree
35348 INFO: checking Tree
35364 INFO: Loading module hook "hook-clr.py"...
Ignus
  • 139
  • 1
  • 8

3 Answers3

4

For me, this issue went away when I installed pythonnet: pip install pythonnet

TechNerd
  • 91
  • 5
2

It looks like you need to open the hook-clr.py and add the path to your Python.Runtime.dll to data=[]: https://github.com/pyinstaller/pyinstaller/issues/1801

if is_win:
    pyruntime = 'Python.Runtime'
    library = ctypes.util.find_library(pyruntime)
    datas = ['path\\to\\Python.Runtime.dll']

    if library:
        datas = [(library, '')]
    else:
        # find Python.Runtime.dll in pip-installed pythonnet package
        for sitepack in getsitepackages():
            library = join(sitepack, pyruntime + '.dll')
            if exists(library):
                datas = [(library, '')]
        if not datas:
            raise Exception(pyruntime + ' not found')
It_is_Chris
  • 13,504
  • 2
  • 23
  • 41
  • Hi, unfortunately this solution doesn't work for me, modyifing hook-clr.py as suggested returns me ValueError: too many values to unpack (expected 2). I'll update my OP with more infos – Ignus Oct 08 '18 at 10:51
  • @Ignus Ran into this as well looks like it expects an array of a single tuple with the path and '.' see here: https://stackoverflow.com/questions/40676027/pyinstaller-valueerror-too-many-values-to-unpack/41541482 – nimig18 Dec 11 '20 at 18:54
0

Old question I know, but I could not find a solution to this online, including OP's follow up that the solution from It_is_Chis did not work fully. I found the same initial error, then after the solution from It_is_Chris, the same issue in receiving the ValueError. However, the solution is quite simple after reading the PyInstaller docs (How to use .spec files with PyInstaller):

Relevant snip from PyInstaller webpage

To give a slightly more full answer for noobs like me, navigate to your python site-packages folder then into PyInstaller and finally hooks (this can be found under interpreter paths, otherwise mine was in: C:\Users*user*\AppData\Roaming\Python\Python38\site-packages\PyInstaller\hooks. Then open the hook-clr.py file.

Then all it takes is to make your addition to datas a tupple as follows:

if is_win:
    pyruntime = 'Python.Runtime'
    library = ctypes.util.find_library(pyruntime)
    datas = [('path\\to\\Python.Runtime.dll','.')]

    if library:
        datas = [(library, '')]
    else:
        # find Python.Runtime.dll in pip-installed pythonnet package
        for sitepack in getsitepackages():
            library = join(sitepack, pyruntime + '.dll')
            if exists(library):
                datas = [(library, '')]
        if not datas:
            raise Exception(pyruntime + ' not found')
Rezy
  • 1