Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] os.path use inside imported module? #400

Closed
asd417 opened this issue Jun 19, 2023 · 5 comments
Closed

[Question] os.path use inside imported module? #400

asd417 opened this issue Jun 19, 2023 · 5 comments
Labels

Comments

@asd417
Copy link

asd417 commented Jun 19, 2023

I made a calendar app on python using google api.
It has no problems running but after packaging I get this error.

 File "apimanager.py", line 52, in get_service
  File "googleapiclient\_helpers.py", line 130, in positional_wrapper
  File "googleapiclient\discovery.py", line 287, in build
  File "googleapiclient\discovery.py", line 404, in _retrieve_discovery_doc
googleapiclient.errors.UnknownApiNameOrVersion: name: calendar  version: v3

So I looked at what the line was doing, it was using this in \venv\Lib\site-packages\googleapiclient\discovery_cache\__init__.py

DISCOVERY_DOC_DIR=os.path.join(
    os.path.dirname(os.path.realpath(__file__)), "documents"
)
...
try:
        with open(os.path.join(DISCOVERY_DOC_DIR, doc_name), "r") as f:
            content = f.read()
    except FileNotFoundError:
        # File does not exist. Nothing to do here.
        pass

What this tries to do is essentially open bunch of json files inside
\venv\Lib\site-packages\googleapiclient\discovery_cache\documents

So I tried to include the folder with --add-data
with documents/ and discovery_cache/documents/
but it still gives me the same error.

Is there a way to fix this?

@github-actions
Copy link

👋 Hi, just a reminder that if you haven't read the help post yet, give it a read to see if your issue is covered in it and make sure to follow the debugging section.

Also please note, as stated in the README, if your issue is only associated with your application and not auto-py-to-exe itself, please do not create an issue in this repository - instead, comment on the help post, video or create a new discussion.

@brentvollebregt
Copy link
Owner

Check out this comment and this PR - might pay to pick up the changes from that PR and see if it fixes your issues (could use a very recent build of pyinstaller)

@ArthurKlausHoff
Copy link

ArthurKlausHoff commented Jun 21, 2023

This error should be fixed by the PR mentioned above.

You could get it, if you don't want to wait for a new release of the hooks, by installing pyinstaller-hooks-contrib directly from git using pip install --upgrade git+https://github.com/pyinstaller/pyinstaller-hooks-contrib@master (i only recommend doing this inside a virtual env).

Or you could add static_discovery=False to your call to discovery.build in apimanager.py, like:

def get_service(...):
  ...
  discovery.build("calendar", "v3", developerKey="...", static_discovery=False)
  ...

And remove it when a new release of the hooks comes out.

Just some info. With the fix the bundled app might take a little more time to startup (on onefile mode) and/or take more space (specially on onedir mode) because discovery_cache has like 459 json files. It is just a waste of space and time in 99.9% of use cases, where it will only use a maximum of 10 different APIs.

@github-actions
Copy link

This issue is stale because it has been open for 60 days with no activity. Remove stale label or comment on this issue or it will be closed in 5 days.

@github-actions github-actions bot added the Stale label Jul 22, 2023
@github-actions
Copy link

Closing issue due to no activity in more than 60 days.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Jul 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants