When playing around with the python dropbox API to upload files, I ran into issues when trying to make a single executable using pyinstaller.
The error I received was similar as shown below:
I figured it had to do with the trusted-certs file used by the dropbox API to validate its SSL connection to the dropbox servers.
To overcome this issue, I had to perform the below steps:
- First browse to your dropbox API folder and copy the trusted-certs.crt to another location
In my case this was C:\Python27\Lib\site\packages\dropbox\
Copy trusted-certs.crt to d:\
2. Stay in the dropbox api folder and open the rest.py file using your favorite editor program.
3. Within rest.py file look for the section that starts with:
TRUSTED_CERT_FILE = pkg_resources.resource_filename(__name__, ‘trusted-certs.crt’)
change this to:
“”” Get absolute path to resource, works for dev and for PyInstaller “””
# PyInstaller creates a temp folder and stores path in _MEIPASS
base_path = sys._MEIPASS
base_path = os.path.abspath(“.”)
return os.path.join(base_path, relative_path)
TRUSTED_CERT_FILE = (resource_path(‘certs\\trusted-certs.crt’))
This will ensure that the dropbox API will look in the %temp% directory which the standalone .exe creates at runtime.
4. Now you have to recompile rest.pyc so the dropbox API and pyinstaller use the changes made
Open python in CMD and run the following command (change the file path to fit your setup)
>>> import py_compile
5. The final step is to create a pyinstaller .spec file in which you tell pyinstaller to copy and include the trusted-certs.crt file in the %temp% directory where it also writes files needed by the program at run time.
Do the following:
Run pyinstaller using the “yourprogram.py” file which you like to convert into a single exe file
In my case this is:
This will create a find-copy.spec file within the running directory (d:\). Copy and rename this file to something else like myprog.spec.
Open myprog.spec and modify the following. Make sure the trusted-cert.crt path reflects your situation!
a = Analysis([‘find-copy.py’],
6. You are no ready to re-run pyinstaller but this time specifying the myprog.spec file
In my case this looks like this:
Pyinstaller –F myprog.spec find-copy.py
7. If all went well you should now have a working .exe file which copies and finds the required trusted-certs.crt file needed by the dropbox API