Search code examples
pythonpython-3.4py2exepyinstallercx-freeze

Cannot make work exe from python with gspread


I have a script, which uses gspread for manupilating with Google Drive data. And I want to create a simple executable in Windows. But yet no luck.

Note

  • Python 3.4
  • Windows XP

What I've tried so far:

  • PyInstaller 3.0
  • py2exe 0.9.9.2
  • cx_Freeze

  1. PyInstaller

    Goes to the step 60020 INFO: Looking for ctypes DLLs and then

    blah-blah-blah...

      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 (configuration took 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,
)
  • Before I added sys.setrecursionlimit(5000) I was getting RuntimeError: Maximum recursion depth exceeded.

  • Added sys.setrecursionlimit(5000) and RuntimeError: maximum recursion depth exceeded in comparison

Error is with mf3 file as here, so I added "excludes":["six.moves.urllib.parse"] but error is the same.


  1. Cx_Freeze This was the closest to success. Even created exe. But there's a problem with cacert with getting [Errno 2] No such file or directory I've tried all methods from here and here here, copied cacerts.txt, cacert.pem but still [Errno 2] No such file or directory

Here is a code of 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 = '[email protected]',
    options = {'build_exe': {'excludes':excludes,
                             'include_files':includefiles,
                             'icon' : icon}},
    executables = [Executable('main.py')],
    )

Looking forward to you help.


Solution

  • The actual answer - here So, step by step

    1. Go to C:\Python34\Lib\site-packages\httplib2
    2. Edit init.py
    3. Replace

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

    by

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

    1. Run cx_freeze script
    2. Search for cacerts.txt and cacert.pem (in my case C:\Python34\Lib\site-packages\certifi and C:\Python34\Lib\site-packages\httplib2
    3. Copy cacerts.txt and cacert.pem to the folder with exe file.
    4. PROFIT

    At least exe, made by cx_freeze now works.