为什么在创建 python 可执行文件后找不到 'splinter' 模块?

Why is 'splinter' module not found after creating python executable?

我使用一些导入在 python 中创建了一个小程序:

splinter、Tkinter、webbrwoser、urllib 和 re

该程序有一个 GUI(通过 tkinter),当我通过命令行 运行 它时一切正常。

但是,当我尝试使用these instructions创建一个可执行文件时,一切似乎都可以工作但是当我实际上 运行 .exe 文件,我收到以下错误:

C:\Python27\dist>pypy.exe
Traceback (most recent call last):
  File "pypy.py", line 1, in <module>
ImportError: No module named splinter

这是我用来获取 .exe 文件的代码:

from distutils.core import setup
import py2exe

setup(console=['pypy.py'])

所以我猜测(在 this SO post 中做了一些阅读之后)问题与我的 dist 文件夹中丢失的文件有关,但对于我来说我的生活我不知道从这里去哪里。

请帮助我使我的 GUI python 程序正常工作。

提前致谢,

乔纳

我发现这个 post 它讨论了从 py2exe 构建中手动排除模块: py2exe "include" modules: when should they be managed manually?

他们提到 tk 是自动包含的,我怀疑 re 和 webbrowser/urllib 也是标准包,但可能需要在 'include' 部分添加其他包。我怀疑您的设置中需要类似以下内容:

setup(
        console=['pypy.py'],
        options={
                "py2exe":{
                        "includes": ["splinter"]
                }
        }
)

希望这对您有所帮助;我没有对 py2exe 做太多,所以如果没有,也许其他人可以提供帮助!

好的!经过相当多的挖掘 (here, here, and here) 我得到了所有的工作!

步骤:

  1. 将整个 splinter 文件夹复制到 Python27\Lib\site-packages before 运行 the setup.py
  2. 同时复制 "webdriver.xpi" 和 "webdriver_prefs.json" C:\Python27\Lib\site-packages\selenium\webdriver\firefox dist\selenium\webdriver\firefox 设置之后(创建 dist 文件夹后)
  3. 好处:如果 .exe 在没有控制台的情况下打开(如果您使用的是 GUI 则很好),在 setup.py 文件中使用 windows 而不是 console =15=]

就是这样!现在程序运行并与 GUI 和 splinter 库一起工作!