ImportError: No module named 'distutils' in pandas pyinstaller

家住魔仙堡 提交于 2019-12-24 10:49:02

问题


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?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/57404906/importerror-no-module-named-distutils-in-pandas-pyinstaller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!