[英]cx_freeze a python script including dropbox
我想凍結使用dropbox上傳文件的python腳本。 我正在使用python 2.7和Windows7。如果僅嘗試以下示例代碼:
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”包,但是不起作用。
我希望有一個人可以幫助我。 也許還有另一種方法可以將文件上傳到保管箱?
歡呼最大
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
我試圖解決此網站的錯誤:
但不起作用。 有人對我的新錯誤有解決方案嗎?
我已經通過這種方式解決了這個問題:
1)在您的保管箱模塊位置,找到文件“ 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)將可信任的certs.crt文件從保管箱目錄復制到library.zip/dropbox
7)享受!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.