3

Im working with Python 3.7.3 and PyInstaller 4.0, and windows 10. My script looks like

import pandas as pd
print('hello')

But when I try to do the .exe file I have an error.

I have tried the following so far:

pyinstaller --hidden-import=pandas --onefile myscript.py

But it doesn't work. I also update to the current development version here: https://pyinstaller.readthedocs.io/en/stable/installation.html

Also, I edit the .spec file and write

# -*- mode: python -*-block_cipher = Nonedef get_pandas_path():
    import pandas
    pandas_path = pandas.__path__[0]
    return pandas_patha = Analysis(['FIFA.py'],
             pathex=['C:\\Users\\NBenton\\PycharmProjects\\RES3D_BETA'],
             binaries=[],
             datas=[],
             hiddenimports=[],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher)

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)pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)
exe = EXE(pyz,
          a.scripts,
          a.binaries,
          a.zipfiles,
          a.datas,
          name='FIFA',
          debug=False,
          strip=False,
          upx=True,
          runtime_tmpdir=None,
          console=True )

and then run

pyinstaller myscript.spec --onefile

I know it is a common question, but the answers in other questions doesn't work for me.

Any help? Thank you

After a lot of lines, the error is:

File "c:\programdata\anaconda3\lib\site-packages\PyInstaller\hooks\hook-numpy.core.py", line 29, in <module>
    pkg_base, pkg_dir = get_package_paths('numpy.core')
  File "c:\programdata\anaconda3\lib\site-packages\PyInstaller\utils\hooks\__init__.py", line 528, in get_package_paths
    file_attr = get_module_file_attribute(package)
  File "c:\programdata\anaconda3\lib\site-packages\PyInstaller\utils\hooks\__init__.py", line 330, in get_module_file_attribute
    raise ImportError
ImportError

4
  • what does your hook-pandas.py file look like? Apr 23, 2020 at 20:11
  • It will be somewhere like \AppData\Local\Programs\Python\Python36\Lib\site-packages\PyInstaller\hooks Apr 23, 2020 at 20:39
  • from PyInstaller.utils.hooks import collect_submodules # Pandas keeps Python extensions loaded with dynamic imports here. hiddenimports = collect_submodules('pandas._libs')
    – LizUlloa
    Apr 23, 2020 at 20:40
  • What warnings do you see when running pyinstaller? For example warning Hidden import pandas._libs.tslibs.timedeltas not found Apr 23, 2020 at 20:49

2 Answers 2

3

hook-pandas.py

Adding datas = collect_data_files('pandas') to the hook-pandas.py file worked for me

from PyInstaller.utils.hooks import collect_submodules
from PyInstaller.utils.hooks import collect_data_files

# Pandas keeps Python extensions loaded with dynamic imports here.
hiddenimports = collect_submodules('pandas._libs')
datas = collect_data_files('pandas')

Anaconda prompt

I also added the hidden-import pkg_resources.py2_warn because that was an error I received

(base) C:\Users\...\test_folder>pyinstaller test.py -F --hidden-import pkg_resources.py2_warn
102 INFO: PyInstaller: 3.6
102 INFO: Python: 3.7.6 (conda)
106 INFO: Platform: Windows-10-10.0.18362-SP0
116 INFO: wrote C:\Users...\test_folder\test.spec
120 INFO: UPX is not available.
125 INFO: Extending PYTHONPATH with paths

Note: -F is the same as --onefile in pyinstaller test.py -F --hidden-import pkg_resources.py2_warn

test.py

import pandas as pd
print('hello world')
input()
2
  • 2
    Hmm pandas issues again. Would you mind looking into this and seeing if our hooks need updating? If so, please submit a PR. (I'm a PyInstaller developer)
    – Legorooj
    Apr 24, 2020 at 0:18
  • @Legorooj I will take a look when I get some time. I appreciate your work on pyinstaller; great package. Apr 24, 2020 at 0:29
1

pyinstaller had this issue as reported here

  1. Set your hidden imports as suggested in the thread:
hiddenimports = ['pandas._libs.tslibs.timedeltas',
'pandas._libs.tslibs.nattype',
'pandas._libs.tslibs.np_datetime',
'pandas._libs.skiplist']
  1. If that does not work, try installing pandas using pip.

    pip install pandas and not via conda

I am surprised to see the version 4.0 of Pyinstaller as it has not been released as far as I know.

1
  • I do not believe this will work as the OP indicated that all the hidden imports from pandas._libs are collected in the hook-pandas.py file: hiddenimports = collect_submodules('pandas._libs') Apr 23, 2020 at 21:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.