在Windows命令行上使用PyInstaller时文件夹的ModuleNotFoundError

时间:2018-12-04 00:35:35

标签: python-3.x pycharm kivy python-import pyinstaller

我正在PyCharm上构建一个kivy应用程序。我的Test.py导入testone.py并从中运行一个函数。当我在PyCharm中运行Test.py时,应用程序会构建并正常运行。但是,为了构建该应用程序的.exe,我在命令行中运行以下命令:

python -m PyInstaller --name TestAppWD9 --onefile --add-data "Desktop\KivyUdemyCourse\AdvKivywKV\testone.py;Desktop\KivyUdemyCourse\AdvKivywKV\testone.py" C:\Users\jgldm\Desktop\KivyUdemyCourse\AdvKivywKV\Test.py

我得到了这样的规格文件:

# -*- mode: python -*-
from kivy.deps import sdl2, glew
import pygame.pkgdata

block_cipher = None


a = Analysis(['C:\\Users\\jgldm\\Desktop\\KivyUdemyCourse\\AdvKivywKV\\Test.py'],
             pathex=['C:\\Users\\jgldm'],
             binaries=[],
             datas=[('Desktop\\KivyUdemyCourse\\AdvKivywKV\\testone.py', 'Desktop\\KivyUdemyCourse\\AdvKivywKV\\testone.py')],
             hiddenimports=[],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher,
             noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)
exe = EXE(pyz,
          a.scripts,
          a.binaries,
          a.zipfiles,
          a.datas,
          *[Tree(p) for p in (sdl2.dep_bins + glew.dep_bins)],
          [],
          name='TestAppWD9',
          debug=False,
          bootloader_ignore_signals=False,
          strip=False,
          upx=True,
          runtime_tmpdir=None,
          console=True )

运行从规范文件构建的应用程序时,出现ModuleNotFoundError:没有名为“ AdvKivywKV”的模块

如何获取规格文件以查找并包含AdvKivywKV?

1 个答案:

答案 0 :(得分:0)

需要通过将testone.py放入带有__init__.py文件的子文件夹中来修复文件夹结构。后者可以为空白。之后,我将导入更改为from subfolder_name.testone import function