我想冻结一个使用dropbox上传文件的python脚本。我正在使用python 2.7和Windows 7.如果我尝试这个示例代码:
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)
我还试图添加包&#34; dropbox&#34;但它没有用。
我希望有人可以帮助我。也许还有另一种方法可以将文件上传到Dropbox?
Cheers Max
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
我尝试使用此网站解决错误:
但不起作用。有没有人对我的新错误有解决方案?
答案 0 :(得分:1)
我用这种方式解决了这个问题:
1)在您的Dropbox模块位置找到文件“rest.py”(C:\ Python27 \ Lib \ site-packages \ dropbox-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文件并使用您的程序运行py文件
5)使用cx_freeze
重建您的可执行文件6)将trusted-certs.crt文件从dropbox目录复制到library.zip/dropbox
7)享受!