简体   繁体   中英

ImportError: No module named 'distutils' in pandas pyinstaller

I have created an executable via pyinstaller. While running the exe found the error from pandas.

Traceback (most recent call last):
  File "score_python.py", line 3, in <module>
    import pandas as pd, numpy as np
  File "d:\virtual\sc\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
    exec(bytecode, module.__dict__)
  File "site-packages\pandas\__init__.py", line 23, in <module>
  File "d:\virtual\sc\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
    exec(bytecode, module.__dict__)
  File "site-packages\pandas\compat\__init__.py", line 32, in <module>
ImportError: No module named 'distutils'

Has anyone found the same?

This is an issue with virtualenv from version 16.4.0 onward, as indicated in the following issue on github: https://github.com/pyinstaller/pyinstaller/issues/4064

These workarounds were suggested:

  1. In the .spec file, at the line “hiddenimports=[]”, change to "hiddenimports=['distutils']", then run pyinstaller using the spec file.

    Tried this, but it didn't work in my case, now distutils module could be found, but it threw an error while importing the module.

  2. Downgrade virtualenv to an earlier version.

    I downgraded virtualenv to version 16.1.0 and and recreated the execution bundle. The new execution file worked alright in my case.

Found the solution, it's because of the virtual environment.

The error occurred because of the creation of a new virtual environment while creating the project. I have deleted my existing virtual and created new virtual by setting up the python interpreter and opting the pre-existing interpreter option.

The IDE will create a virtual named venv and copies all the python files from Python/bin to this folder and then import modules from here, by activating the same solved my issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM