我想凍結一個使用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
我試圖用這個網站來解決錯誤:
,但不起作用。有人有我的新錯誤的解決方案嗎?
你有沒有調用腳本'dropbox.py'?如果是這樣,請嘗試將其稱爲其他內容,例如'dropbox-upload.py' - 它可能會找到您的腳本而不是Dropbox包。 – 2014-12-08 17:52:02
thx的幫助,它將錯誤更改爲: NotImplementedError:resource_filename()僅支持.egg,而不是.zip – Max 2014-12-08 23:06:45
我還發現了一個線程,您解決了同樣的問題,但我無法解決它? https://bitbucket.org/anthony_tuininga/cx_freeze/issue/19/dropbox-include – Max 2014-12-08 23:59:32