Closed kenvenner closed 3 years ago
My colleague helped me resolve this - and I made a patch to your code to make it "PyInstaller" aware - I will create a PR for this change in hopes that you will review and chose to accept this change. This change still requires a custom EXE generation command line but it works as expected with this small change. For more information - check out the link in the original posting.
I was unable to make a new branch and submit the change - so I took the posting from the other site that shows the few lines of code that I changed - and posted it here - more than willing to deliver the code change as a pull request if you want to enable me to do this. thanks
i modified the __init__.py
file to be "PyInstaller" aware by adding this function to the code and replacing this line at line 31:
def resource_path(relative_path):
""" Get absolute path to resource, works for dev and for PyInstaller """
try:
# PyInstaller creates a temp folder nad stores path in _MEIPASS
base_path = sys._MEIPASS
except Exception:
base_path = os.path.abspath(".")
return os.path.join(base_path, relative_path)
_zips_json = resource_path(os.path.join(os.path.dirname(os.path.abspath(__file__)), "zips.json.bz2"))
And I updated the EXE generation command line to look like this (which you might want to add this comment to the README.MD file here):
pyinstaller --onefile ziptest.py --add-data ".\venv\Lib\site-packages\zipcodes\zips.json.bz2;zipcodes"
This creates the onefile EXE that i was hoping to create.
Thanks for opening this issue! Could you fork the repository, make the change on your master branch, and open a pull request to this repository? I'd be more than happy to add support for PyInstaller.
I will do that tomorrow – I just need figure out how to do it – which I will do tomorrow.
Ken
From: Sean Pianka notifications@github.com Sent: Thursday, January 7, 2021 3:43 PM To: seanpianka/Zipcodes Zipcodes@noreply.github.com Cc: kenvenner ken@vennerllc.com; Author author@noreply.github.com Subject: Re: [seanpianka/Zipcodes] Unable to compile program that uses this library with pyinstaller (#15)
Thanks for opening this issue! Could you fork the repository, make the change on your master branch, and open a pull request to this repository? I'd be more than happy to add support for PyInstaller.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/seanpianka/Zipcodes/issues/15#issuecomment-756453978, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJWZYSSG3CD5EE3EKT4NSHDSYZBI5ANCNFSM4VYE7A3Q .
Thank you for the solution, finally found the issue. Will this be updated
I have to change the command a bit since I'm using anaconda. pyinstaller --onefile script.py --add-data "C:\Users\pc\anaconda3\envs\pythonTools\Lib\site-packages\zipcodes\zips.json.bz2;zipcodes"
@kenvenner - thank you for this solution, saved me hours of debugging! @seanpianka - thank you for maintaining the library!
One quick question, I've noticed that the most recent build's version is 1.1.3 but when attempting to set this version for the zipcodes library it says 1.1.2 is the latest available. Is it possible that this most recent set of changes was never deployed to pypi?
Thank you both again in advance.
I did not get a chance to deploy 1.1.3 to PyPi, but I will try to do so this week.
Thank you, appreciate the reply.
Version 1.1.3 has been released.
Attempted to build a stand alone EXE for windows using pyinstaller - where this package is part of the solution being generated - and have not quite figured out how to do this - I have posted a message to stack overflow - but thought I would ask the question here also:
https://stackoverflow.com/questions/65568355/permissionerror-errno-13-permission-denied-pyinstaller-exe-zipcodes-windows
Additional testing - we have the same issue when building binary executable on Linux. We think this has something to do with the python->cpython compilation?