简体   繁体   English

导入错误:pandas pyinstaller 中没有名为“distutils”的模块

[英]ImportError: No module named 'distutils' in pandas pyinstaller

I have created an executable via pyinstaller.我已经通过 pyinstaller 创建了一个可执行文件。 While running the exe found the error from pandas.在运行 exe 时发现了熊猫的错误​​。

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这是 16.4.0 版本以后的 virtualenv 的问题,如 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.在 .spec 文件中的“hiddenimports=[]”行中,更改为“hiddenimports=['distutils']”,然后使用 spec 文件运行 pyinstaller。

    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.试过这个,但它在我的情况下不起作用,现在可以找到 distutils 模块,但是在导入模块时它抛出了一个错误。

  2. Downgrade virtualenv to an earlier version.将 virtualenv 降级到早期版本。

    I downgraded virtualenv to version 16.1.0 and and recreated the execution bundle.我将 virtualenv 降级到 16.1.0 版并重新创建了执行包。 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.我已经删除了我现有的虚拟并通过设置 python 解释器并选择pre-existing interpreter选项创建了新的虚拟。

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. IDE 将创建一个名为venv的虚拟并将所有 python 文件从 Python/bin 复制到此文件夹,然后从这里导入模块,通过激活解决了我的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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