无法将Python文件作为.exe文件运行,出现错误'ModuleNotFoundError:没有名为'pandas'的模块'

时间:2019-10-12 03:10:26

标签: python pandas exe

原始问题

安装自动py-exe-exe(https://pypi.org/project/auto-py-to-exe/)并解决我的安装问题(How to convert .py to .exe - pip install auto-py-to-exe works but auto-py-to-exe does not)后,我在运行新生成的exe文件时遇到问题。

我收到错误消息-

ModuleNotFoundError: No module named 'pandas'

我以为我已经安装了“熊猫”

Microsoft Windows [Version 10.0.17134.165]
(c) 2018 Microsoft Corporation. All rights reserved.

C:\Users\HP>auto-py-to-exe
^C
C:\Users\HP>pip3 install pandas

Requirement already satisfied: pandas in c:\users\hp\anaconda3\lib\site-packages (0.24.2)
Requirement already satisfied: numpy>=1.12.0 in c:\users\hp\anaconda3\lib\site-packages (from pandas) (1.17.2)
Requirement already satisfied: pytz>=2011k in c:\users\hp\anaconda3\lib\site-packages (from pandas) (2019.1)

Requirement already satisfied: python-dateutil>=2.5.0 in c:\users\hp\anaconda3\lib\site-packages (from pandas) (2.8.0)
Requirement already satisfied: six>=1.5 in c:\users\hp\anaconda3\lib\site-packages (from python-dateutil>=2.5.0->pandas) (1.12.0)

C:\Users\HP>pip install pandas
Requirement already satisfied: pandas in c:\users\hp\anaconda3\lib\site-packages (0.24.2)

Requirement already satisfied: numpy>=1.12.0 in c:\users\hp\anaconda3\lib\site-packages (from pandas) (1.17.2)
Requirement already satisfied: pytz>=2011k in c:\users\hp\anaconda3\lib\site-packages (from pandas) (2019.1)
Requirement already satisfied: python-dateutil>=2.5.0 in c:\users\hp\anaconda3\lib\site-packages (from pandas) (2.8.0)
Requirement already satisfied: six>=1.5 in c:\users\hp\anaconda3\lib\site-packages (from python-dateutil>=2.5.0->pandas) (1.12.0)

C:\Users\HP>pip --version
pip 19.2.3 from c:\users\hp\anaconda3\lib\site-packages\pip (python 3.7)

我有兼容性问题吗?

INSTALLED VERSIONS
------------------
commit: None
python: 3.7.3.final.0
python-bits: 64
OS: Windows
OS-release: 10
machine: AMD64
processor: Intel64 Family 6 Model 142 Stepping 10, GenuineIntel
byteorder: little
LC_ALL: None
LANG: en
LOCALE: None.None

pandas: 0.24.2
pytest: 5.0.1
pip: 19.2.3
setuptools: 41.0.1
Cython: 0.29.12
numpy: 1.17.2
scipy: 1.2.1
pyarrow: None
xarray: None
IPython: 7.6.1
sphinx: 2.1.2
patsy: 0.5.1
dateutil: 2.8.0
pytz: 2019.1
blosc: None
bottleneck: 1.2.1
tables: 3.5.2
numexpr: 2.6.9
feather: None
matplotlib: 3.1.0
openpyxl: 2.6.2
xlrd: 1.2.0
xlwt: 1.3.0
xlsxwriter: 1.1.8
lxml.etree: 4.3.4
bs4: 4.7.1
html5lib: 1.0.1
sqlalchemy: 1.3.5
pymysql: None
psycopg2: None
jinja2: 2.10.1
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
gcsfs: None

这是软件的输出-

Running auto-py-to-exe v2.6.5
Building in the current instances temporary directory at C:\Users\HP\AppData\Local\Temp\tmpcgwenk45
To get a new temporary directory, restart this application
Recursion Limit is set to 5000
Executing: pyinstaller -y  "C:/Users/HP/Documents/Python Scripts/ExcelReader.py"
107309 INFO: PyInstaller: 3.5
107309 INFO: Python: 3.7.3
107310 INFO: Platform: Windows-10-10.0.17134-SP0
107311 INFO: wrote C:\Users\HP\AppData\Local\Temp\tmpcgwenk45\ExcelReader.spec
107583 INFO: UPX is not available.
107654 INFO: Extending PYTHONPATH with paths
['C:\\Users\\HP\\Documents\\Python Scripts',
 'C:\\Users\\HP\\AppData\\Local\\Temp\\tmpcgwenk45']
107655 INFO: checking Analysis
107655 INFO: Building Analysis because Analysis-00.toc is non existent
107655 INFO: Initializing module dependency graph...
107804 INFO: Initializing module graph hooks...
108085 INFO: Analyzing base_library.zip ...
116454 INFO: running Analysis Analysis-00.toc
116554 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
  required by c:\users\hp\appdata\local\programs\python\python37-32\python.exe
122179 INFO: Caching module hooks...
122519 INFO: Analyzing C:\Users\HP\Documents\Python Scripts\ExcelReader.py
122534 INFO: Loading module hooks...
122535 INFO: Loading module hook "hook-encodings.py"...
122667 INFO: Loading module hook "hook-pydoc.py"...
122709 INFO: Loading module hook "hook-xml.py"...
123270 INFO: Looking for ctypes DLLs
123270 INFO: Analyzing run-time hooks ...
123291 INFO: Looking for dynamic libraries
130447 INFO: Looking for eggs
130447 INFO: Using Python library c:\users\hp\appdata\local\programs\python\python37-32\python37.dll
130447 INFO: Found binding redirects: 
[]
130461 INFO: Warnings written to C:\Users\HP\AppData\Local\Temp\tmpcgwenk45\build\ExcelReader\warn-ExcelReader.txt
130527 INFO: Graph cross-reference written to C:\Users\HP\AppData\Local\Temp\tmpcgwenk45\build\ExcelReader\xref-ExcelReader.html
130602 INFO: checking PYZ
130602 INFO: Building PYZ because PYZ-00.toc is non existent
130618 INFO: Building PYZ (ZlibArchive) C:\Users\HP\AppData\Local\Temp\tmpcgwenk45\build\ExcelReader\PYZ-00.pyz
131177 INFO: Building PYZ (ZlibArchive) C:\Users\HP\AppData\Local\Temp\tmpcgwenk45\build\ExcelReader\PYZ-00.pyz completed successfully.
131207 INFO: checking PKG
131208 INFO: Building PKG because PKG-00.toc is non existent
131208 INFO: Building PKG (CArchive) PKG-00.pkg
131458 INFO: Building PKG (CArchive) PKG-00.pkg completed successfully.
131468 INFO: Bootloader c:\users\hp\appdata\local\programs\python\python37-32\lib\site-packages\PyInstaller\bootloader\Windows-32bit\run.exe
131469 INFO: checking EXE
131470 INFO: Building EXE because EXE-00.toc is non existent
131470 INFO: Building EXE from EXE-00.toc
131485 INFO: Appending archive to EXE C:\Users\HP\AppData\Local\Temp\tmpcgwenk45\build\ExcelReader\ExcelReader.exe
131537 INFO: Building EXE from EXE-00.toc completed successfully.
131540 INFO: checking COLLECT
131541 INFO: Building COLLECT because COLLECT-00.toc is non existent
131553 INFO: Building COLLECT COLLECT-00.toc
134365 INFO: Building COLLECT COLLECT-00.toc completed successfully.
Moving project to: C:\Users\HP\output
Complete.

更新1

我通过在“ --hidden-import”中输入“ pandas”解决了这个问题。单击链接以获取屏幕截图。 Screenshot of Advanced Options

1 个答案:

答案 0 :(得分:0)

以下与--hidden-import标志有关的信息对于构建过程可能很重要,并且可以解决您的问题。这来自出现在您问题的链接中的blog post

  

ModuleNotFoundError:没有名为x的模块/ ImportError:没有名为   x

     

这意味着未将特定模块(在这种情况下为'x')添加到   包。我已经在熊猫库中的软件包中看到了这种情况   和win32api;只要您能识别出包裹(例如“ x”),   它很容易修复。

     

要在用户界面中解决此问题,请打开“高级”标签并找到   --hidden-import输入。只需将模块名称粘贴到此输入中,然后重新打包即可。如果仍然出现原始错误,则说明   错误地做到了这一点。