V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
Alerta
V2EX  ›  Python

[求助] cx_freeze 打包无法用__import__()动态加载模块的问题

  •  
  •   Alerta · 2018-12-04 11:33:09 +08:00 · 1198 次点击
    这是一个创建于 1942 天前的主题,其中的信息可能已经有所发展或是发生改变。

    这次打包的项目相对于以前打包的项目复杂好多,入口文件 run.py 在项目的第二级目录里面“ test/project/run.py

    还没有打包之前,在 run.py 中有一段代码如下

                    if len(test_suite) == 0:
                        print "111-"
                        test_mod = __import__(case_mod)
                        print "111test_mode:", test_mod
                        self.__add_suite(test_mod, tc_info, device)
    

    运行结果如下:

    111-
    111test_mode: <module 'advip_case' from 'E:\idd_project\testcases\advip_case.pyc'>
    

    但是用 cx_freeze 打包出来的 run.exe 跑出来却没能打印出来"111test_mode"的信息,并且脚本就结束运行了。 检查了一下

    1.需要加载的 advip_case.pyc 正确在当前目录中

    2.当前目录已加上__init__.pyc (不过使用__import__方法好像不需要__init__文件)

    求助各位大神,这是怎么回事?

    3 条回复    2018-12-04 11:53:18 +08:00
    cs371332219
        1
    cs371332219  
       2018-12-04 11:38:05 +08:00
    使用 PyInstaller 的时候遇到过同样的问题,打包的时候加参数手动把你 __import__ 的包补进来就行,更好的办法就不知道了。
    Alerta
        2
    Alerta  
    OP
       2018-12-04 11:50:52 +08:00
    @cs371332219 我已经手动把那个包加进来了,但不知道为什么就没有 import 成功,也没有任何错误信息
    cs371332219
        3
    cs371332219  
       2018-12-04 11:53:18 +08:00
    @Alerta cx-freeze 我当时没跑起来就换 PyInstaller 了,抱歉。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3422 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 10:36 · PVG 18:36 · LAX 03:36 · JFK 06:36
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.