我想将Python转换为导入tensorflow的exe

时间:2019-12-22 06:34:04

标签: python tensorflow

使用pyinstaller进行exe转换时出现问题。

    Traceback (most recent call last):
  File "Find.py", line 1, in <module>
  File "c:\users\hsk15\python_project\javaproject\venv\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
    exec(bytecode, module.__dict__)
  File "lib\site-packages\tensorflow\__init__.py", line 98, in <module>
  File "c:\users\hsk15\python_project\javaproject\venv\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
    exec(bytecode, module.__dict__)
  File "lib\site-packages\tensorflow_core\__init__.py", line 40, in <module>
  File "lib\site-packages\tensorflow\__init__.py", line 50, in __getattr__
  File "lib\site-packages\tensorflow\__init__.py", line 44, in _load
  File "importlib\__init__.py", line 126, in import_module
  File "c:\users\hsk15\python_project\javaproject\venv\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
    exec(bytecode, module.__dict__)
  File "lib\site-packages\tensorflow_core\python\__init__.py", line 49, in <module>
ImportError: cannot import name 'pywrap_tensorflow'
[20188] Failed to execute script Find

此错误..我可以找到问题

为什么不能导入pywrap_tensorflow?什么是pywrap_tensorflow?

2 个答案:

答案 0 :(得分:0)

Pywrap张量流是TensorFlow SWIG生成的绑定的包装器。

如何使用pyinstaller:

首先,通过执行以下命令,使用命令提示符安装pyinstaller pip install pyinstaller:

在cmd中运行此行:

pip install auto-py-to-exe

要打开应用程序,请在cmd中运行以下行:

自动转至exe

您需要选择的主要选项很少:

Pick your .py file
Pick "One Directory" or "One File" option
Pick additional files

然后,打开应用程序,在cmd中运行此行,输入命令 pyinstaller filename.py用您的python代码文件替换文件名。

答案 1 :(得分:0)

第一;创建虚拟环境。为此,您应该在 cmd 上运行它:

pip install virtualenv

然后,运行这个:

  • python -m venv VIRTUAL_ENVIRONMENT'S_NAME

  • VIRTUAL_ENVIRONMENT'S_NAME/Scripts/activate

  • pip install pyinstaller

然后,下载您使用的所有库。例如:

  • pip install requests
  • pip install datetime

将您的代码文件移动到:

VIRTUAL_ENVIRONMENT'S_NAME/Scripts

现在,您可以使用:

pyinstaller --onefile PYTHON_FILE'S_NAME