Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 动态模块加载的Pyinstaller_Python_Pyinstaller - Fatal编程技术网

Python 动态模块加载的Pyinstaller

Python 动态模块加载的Pyinstaller,python,pyinstaller,Python,Pyinstaller,我有一个简单的架构,一个脚本动态调用另一个脚本: -| test_wrapper.py | module.py 测试包装器.py的代码: from importlib import import_module import sys if __name__ == "__main__": mod_name = sys.argv[1] func_name = sys.argv[2] effective_module = import_module(mo

我有一个简单的架构,一个脚本动态调用另一个脚本:

-| test_wrapper.py
 | module.py
测试包装器.py的代码:

from importlib import import_module
import sys

if __name__ == "__main__":
    mod_name = sys.argv[1]
    func_name = sys.argv[2]
    effective_module = import_module(mod_name)
    callable_element = getattr(effective_module, func_name)
    result = callable_element()
    print(result)
def myFunc():
    return "success"
模块.py的代码:

from importlib import import_module
import sys

if __name__ == "__main__":
    mod_name = sys.argv[1]
    func_name = sys.argv[2]
    effective_module = import_module(mod_name)
    callable_element = getattr(effective_module, func_name)
    result = callable_element()
    print(result)
def myFunc():
    return "success"
如果我从命令行调用:

python test_wrapper.py module myFunc
一切都好。现在,我想要实现的是,我可以从命令行成功调用:

test_wrapper.exe module myFunc
因此,我安装了pyinstaller,运行它并编辑了隐藏导入的规范文件:

# -*- mode: python ; coding: utf-8 -*-

block_cipher = None


a = Analysis(['test_wrapper.py'],
             pathex=['C:\\Dev'],
             binaries=[],
             datas=[],
             hiddenimports=['C:\\Dev\\module.py'],
             hookspath=[],
             runtime_hooks=['C:\\Dev\\module.py'],
             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,
          [],
          exclude_binaries=True,
          name='test_wrapper',
          debug=False,
          bootloader_ignore_signals=False,
          strip=False,
          upx=True,
          console=True )
coll = COLLECT(exe,
               a.binaries,
               a.zipfiles,
               a.datas,
               strip=False,
               upx=True,
               upx_exclude=[],
               name='test_wrapper')
但接下来要跑:

dist\test_wrapper\test_wrapper.exe folder myFunc
返回

File "test_wrapper.py", line 8, in <module>
effective_module = import_module(mod_name)
File "importlib\__init__.py", line 126, in import_module
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'module'
[26468] Failed to execute script test_wrapper
文件“test_wrapper.py”,第8行,在
有效模块=导入模块(模块名称)
文件“importlib\\ uuuuu init\ uuuuuu.py”,第126行,在导入模块中
文件“”,第994行,在_gcd_导入中
文件“”,第971行,在_find_和_load中
文件“”,第953行,在“查找”和“加载”中解锁
ModuleNotFoundError:没有名为“module”的模块
[26468]无法执行脚本测试\u包装
我真的不知道如何在spec文件中包含module.py以使其正常工作,我看过了,但没有“具体”的示例提供帮助。我在听任何建议