question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

PyInstaller fails to package APScheduler various `pkg_resources.DistributionNotFound`

See original GitHub issue

Describe the bug When using PyInstaller to compile an executable python application containing apscheduler the application fails to add all of apschedulers dependencies…

It seems that the apscheduler code is making some “on the run imports” and therefore PyInstaller does not find the packages it needs to integrate. Similar to 131.

Pyinstaller executable package can be configured using a “hook files” but I can’t determine which imports are required…

Running the executable raises various pkg_resources.DistributionNotFound errors. What is strange is that running the same executable multiple times raises different exceptions.

2021-10-12 11:02:17,694 - apscheduler.scheduler - INFO - Scheduler started
Exception in thread Thread-3:
Traceback (most recent call last):
  File "apscheduler/schedulers/base.py", line 901, in _create_plugin_instance
KeyError: 'interval'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "threading.py", line 973, in _bootstrap_inner
  File "sentry_sdk/integrations/threading.py", line 69, in run
  File "sentry_sdk/_compat.py", line 54, in reraise
  File "sentry_sdk/integrations/threading.py", line 67, in run
  File "adapters/primary/scheduler/schedule_runner.py", line 128, in run
  File "adapters/primary/scheduler/scheduler.py", line 51, in add_job
  File "apscheduler/schedulers/base.py", line 425, in add_job
  File "apscheduler/schedulers/base.py", line 926, in _create_trigger
  File "apscheduler/schedulers/base.py", line 904, in _create_plugin_instance
  File "pkg_resources/__init__.py", line 2449, in load
  File "pkg_resources/__init__.py", line 2472, in require
  File "pkg_resources/__init__.py", line 772, in resolve
pkg_resources.DistributionNotFound: The 'setuptools>=0.7' distribution was not found and is required by the application
Traceback (most recent call last):
  File "apscheduler/schedulers/base.py", line 901, in _create_plugin_instance
KeyError: 'interval'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "threading.py", line 973, in _bootstrap_inner
  File "sentry_sdk/integrations/threading.py", line 69, in run
  File "sentry_sdk/_compat.py", line 54, in reraise
  File "sentry_sdk/integrations/threading.py", line 67, in run
  File "adapters/primary/scheduler/schedule_runner.py", line 128, in run
  File "adapters/primary/scheduler/scheduler.py", line 51, in add_job
  File "apscheduler/schedulers/base.py", line 425, in add_job
  File "apscheduler/schedulers/base.py", line 926, in _create_trigger
  File "apscheduler/schedulers/base.py", line 904, in _create_plugin_instance
  File "pkg_resources/__init__.py", line 2449, in load
  File "pkg_resources/__init__.py", line 2472, in require
  File "pkg_resources/__init__.py", line 772, in resolve
pkg_resources.DistributionNotFound: The 'pytz' distribution was not found and is required by the application
2021-10-12 10:55:04,156 - apscheduler.scheduler - INFO - Scheduler started
Exception in thread Thread-3:
Traceback (most recent call last):
  File "apscheduler/schedulers/base.py", line 901, in _create_plugin_instance
KeyError: 'interval'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "threading.py", line 973, in _bootstrap_inner
  File "sentry_sdk/integrations/threading.py", line 69, in run
  File "sentry_sdk/_compat.py", line 54, in reraise
  File "sentry_sdk/integrations/threading.py", line 67, in run
  File "adapters/primary/scheduler/schedule_runner.py", line 128, in run
  File "adapters/primary/scheduler/scheduler.py", line 51, in add_job
  File "apscheduler/schedulers/base.py", line 425, in add_job
  File "apscheduler/schedulers/base.py", line 926, in _create_trigger
  File "apscheduler/schedulers/base.py", line 904, in _create_plugin_instance
  File "pkg_resources/__init__.py", line 2449, in load
  File "pkg_resources/__init__.py", line 2472, in require
  File "pkg_resources/__init__.py", line 772, in resolve
pkg_resources.DistributionNotFound: The 'six>=1.4.0' distribution was not found and is required by the application

To Reproduce Working on this now… https://github.com/iamliamc/pyinstaller_apscheduler_test

Expected behavior Python standalone application works fine. Expect compiled version to run similarly.

Additional context Possibly related tickets: 131 554

As 131 describes I have tried switching over to explicit trigger declarations like:

        self.scheduler.add_job(
            self.restore_defaults.__call__,
            id="RestoreDefaults",
            trigger=IntervalTrigger(
                start_date=self.scheduler.calc_start_for_interval_minutes(self.start_offset) + dt.timedelta(minutes=60),
                seconds=600,
            )
        )

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:19 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
agronholmcommented, Nov 4, 2021

Closing as the problem was resolved via the above PR.

1reaction
agronholmcommented, Oct 13, 2021

Did you add the recursive=True option?

Read more comments on GitHub >

github_iconTop Results From Across the Web

APScheduler pytz-deprecation-shim not found when ...
Without pasting the code --collect-all tzdata into my pyinstaller command, the program again will crash. If I do it everything works fine, but ......
Read more >
Is there a plan to make apscheduler distributed ?
This happens because PyInstaller does not include APScheduler's .egg_info directory when packaging your application. Therefore its packaging metadata and entry ...
Read more >
Pyinstaller resources.DistributionNotFound 'workalendar'
Hi! I have imported workalendar package -together with others packages- to my python script, and It works fine. I compile it with Pyinstaller...
Read more >
Pyinstaller Executable Fails With Pkg_Resources. ...
DistributionNotFound : The *** distribution was not when using pyinstaller after installing the package. When pyinstaller generates an executable file, an error ......
Read more >
apscheduler
Is your feature request related to a problem? Please describe. I recently migrated a workload from Vixie cron to APScheduler, and discovered that...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found