2014-12-08 68 views
1

我想冻结一个使用dropbox上传文件的python脚本。我使用Python 2.7版和Windows 7。如果我只是尝试这个示例代码:cx_freeze一个python脚本,包括dropbox

import dropbox 
client = dropbox.client.DropboxClient(<authtoken>) 
client.put_file('FileName',"", overwrite=True) 

我创建了Dropbox的应用程序,并产生这是对Dropbox的主页解释的令牌。如果我只是使用python脚本,这个例子可以工作。对于未来的应用程序,我想冻结脚本以在没有python的计算机上使用它。 如果我执行.exe文件我得到以下错误消息,我命名为python脚本dropbox.py:

Traceback (most recent call last): 
File "C:\Python27\lib\site-packages\cx_Freeze\initscripts\Console.py", line 27, in <module> 
exec(code, m.__dict__) 
File "dropbox.py", line 2, in <module> 
File "H:\dropbox.py", line 3, in <module> 
client = dropbox.client.DropboxClient("authToken") 
AttributeError: 'module' object has no attribute 'client' 

解决:不要使用dropbox.py您的示例脚本 该错误提示它无法找到客户端模块,但如何解决这个错误? 我的setup.py文件是:

import cx_Freeze 
import sys 
base = None 

executables = [ 
    cx_Freeze.Executable("dropbox.py", base = base), 
    ] 

build_exe_options = {"includes":[], 
        "include_files":[], 
        "excludes":[], 
        "packages":[] 
        } 
cx_Freeze.setup(
    name = "script", 
    options = {"build_exe": build_exe_options}, 
    version = "0.0", 
    description = "A basic example", 
    executables = executables) 

我也试图在套餐“Dropbox的”添加,但它不工作。

我希望有人能帮助我。也许有另一种上传文件到Dropbox的方法吗?

干杯最大

EDIT1: 事实上,这是我的示例脚本的名称的问题。虽然它仍然不起作用。新的错误是:

Traceback (most recent call last): 
    File "C:\Python27\lib\site-packages\cx_Freeze\initscripts\Console.py", line 27, in <module> 
    exec(code, m.__dict__) 
    File "mydropbox.py", line 2, in <module> 
    File "C:\Python27\lib\site-packages\dropbox\__init__.py", line 3, in <module> 
    from . import client, rest, session 
    File "C:\Python27\lib\site-packages\dropbox\client.py", line 22, in <module> 
    from .rest import ErrorResponse, RESTClient, params_to_urlencoded 
    File "C:\Python27\lib\site-packages\dropbox\rest.py", line 26, in <module> 
    TRUSTED_CERT_FILE = pkg_resources.resource_filename(__name__, 'trusted-certs.crt') 
    File "build\bdist.win32\egg\pkg_resources.py", line 950, in resource_filename 
    File "build\bdist.win32\egg\pkg_resources.py", line 1638, in get_resource_filename 
NotImplementedError: resource_filename() only supported for .egg, not .zip 

我试图用这个网站来解决错误:

enter link description here

,但不起作用。有人有我的新错误的解决方案吗?

+0

你有没有调用脚本'dropbox.py'?如果是这样,请尝试将其称为其他内容,例如'dropbox-upload.py' - 它可能会找到您的脚本而不是Dropbox包。 – 2014-12-08 17:52:02

+0

thx的帮助,它将错误更改为: NotImplementedError:resource_filename()仅支持.egg,而不是.zip – Max 2014-12-08 23:06:45

+0

我还发现了一个线程,您解决了同样的问题,但我无法解决它? https://bitbucket.org/anthony_tuininga/cx_freeze/issue/19/dropbox-include – Max 2014-12-08 23:59:32

回答

1

我已经解决了这个问题是这样的:

1)在你的Dropbox模块位置找到文件 “rest.py”(C:\ Python27 \ LIB \站点包\保管箱,2.2.0- py2.7.egg \ Dropbox的 - 在我的情况)

2)注释的字符串TRUSTED_CERT_FILE = pkg_resources.resource_filename(__name__, 'trusted-certs.crt')

3)你可以写

TRUSTED_CERT_FILE = 'trusted-certs.crt'(我用这个方式)或

if hasattr(sys, 'frozen'):

TRUSTED_CERT_FILE = 'trusted-certs.crt'

else:

TRUSTED_CERT_FILE = pkg_resources.resource_filename(__name__, 'trusted-certs.crt')

4)的Dropbox目录中删除所有PYC文件,并与您的程序

5)重建与cx_freeze可执行文件运行PY文件

6)将dropbox目录下的trusted-certs.crt文件复制到库中。zip/dropbox

7)享受!