如何制作使用PyMongo的Python程序的.exe

时间:2013-10-08 12:56:48

标签: python-2.7 pymongo py2exe

我想使用py2exe

为我的python程序制作一个.exe文件

setup.py

from distutils.core import setup
    import py2exe

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

first.py

print "hello"

然后我运行这个命令:

  

python setup.py py2exe

在我的dist文件夹中成功创建了first.exe。

现在我想制作使用PyMongo的程序。 (我已经安装了PyMongo,这个程序可以独立运行)

first.py

from pymongo import MongoClient
    client = MongoClient()

    db = client['configdb']

    x = db.Model.find_one()

    print x

再次运行

  

python setup.py py2exe

但是当我运行first.exe时出现以下错误:

Traceback (most recent call last):
      File "first.py", line 1, in <module>
      File "pymongo\__init__.pyc", line 80, in <module>
      File "pymongo\connection.pyc", line 39, in <module>
      File "pymongo\mongo_client.pyc", line 45, in <module>
      File "pymongo\pool.pyc", line 22, in <module>
      File "pymongo\thread_util.pyc", line 28, in <module>
      File "gevent\coros.pyc", line 5, in <module>
      File "gevent\lock.pyc", line 5, in <module>
      File "gevent\_semaphore.pyc", line 12, in <module>
      File "gevent\_semaphore.pyc", line 5, in __load
    AttributeError: 'module' object has no attribute 'path'

我是py2exe的初学者。我怎样才能做到这一点?

1 个答案:

答案 0 :(得分:0)

只需更改我的setup.py

即可
from distutils.core import setup
import py2exe, sys, os

sys.argv.append('py2exe')

setup(
    options = {'py2exe': {'bundle_files': 1}},
    console = [{'script': "fisrt.py"}],
    zipfile = None,
)

现在工作正常。