无法使用 gspread 从 python 生成工作 exe

Cannot make work exe from python with gspread

我有一个脚本,它使用 gspread 来操纵 Google 驱动器数据。 我想在 Windows 中创建一个简单的可执行文件。但是还是没有运气。

备注

到目前为止我尝试过的:


  1. PyInstaller

    转到步骤 60020 信息:寻找 ctypes DLL 然后

    废话废话...

      File "C:\Python34\lib\ntpath.py", line 246, in basename
        return split(p)[1]
      File "C:\Python34\lib\ntpath.py", line 217, in split
        d, p = splitdrive(p)
      File "C:\Python34\lib\ntpath.py", line 161, in splitdrive
        normp = p.replace(_get_altsep(p), sep)
    AttributeError: 'tuple' object has no attribute 'replace'
    

  1. py2exe

Setup.py(配置占用here

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

sys.setrecursionlimit(5000)
sys.argv.append('py2exe')

setup(
    options = {'py2exe': {'bundle_files': 1, 'compressed': True}},
    windows = [{'script': "main.py"}],
    zipfile = None,
)

错误是 mf3 文件 ,所以我添加了 "excludes":["six.moves.urllib.parse"] 但错误是一样的。


  1. Cx_Freeze 这是离成功最近的一次。甚至创建了exe。但是 cacert 在获取 [Errno 2] No such file or directory 时存在问题 我已经尝试了 here and here here 中的所有方法,复制了 cacerts.txt、cacert.pem 但仍然 [Errno 2] No such file or directory

这里是setup.py的代码:

import sys
from cx_Freeze import setup, Executable
import requests.certs

includefiles = ['key.json', (requests.certs.where(),'cacert.pem')]
includes = []
excludes = []
icon = None
base = None
if (sys.platform == "win32"):
    base = "Win32GUI"

setup(
    name = 'Scraper',
    version = '1.0',

    author = 'GriMel',
    author_email = 'GriefMontana@gmail.com',
    options = {'build_exe': {'excludes':excludes,
                             'include_files':includefiles,
                             'icon' : icon}},
    executables = [Executable('main.py')],
    )

期待您的帮助。

实际答案 - here 所以,一步一步

  1. 转到 C:\Python34\Lib\site-packages\httplib2
  2. 编辑init.py
  3. 替换

CA_CERTS = os.path.join(os.path.dirname(os.path.abspath(__file__ )), "cacerts.txt")

来自

CA_CERTS = os.path.join(os.path.dirname(sys.executable), "cacerts.txt")

  1. 运行 cx_freeze 脚本
  2. 搜索 cacerts.txtcacert.pem(在我的例子中 C:\Python34\Lib\site-packages\certifiC:\Python34\Lib\site-packages\httplib2
  3. 复制cacerts.txtcacert.pem到exe文件所在的文件夹
  4. 利润

至少 cx_freeze 制作的 exe 现在可以运行了。