How to install holidays library in Python

I’m trying to add the holidays library to one of my Python rules and have been unsuccessful so far. I’m running a standard openhabian installation on a RPi3 with openhab 2.5.8.

When I run

pip install holidays

at the command line it says it installs correctly but adding the line

import holidays

at the start of my rule doesn’t succeed and I see the following in my logs;

2020-11-13 09:48:16.785 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/etc/openhab2/automation/jsr223/python/personal/': ImportError: No module named holidays in <script> at line number 4

A bit of hunting through the forums here revealed that there are some user and directory issues that need to be incorporated into the pip installation process, so I tried the following;

sudo -u openhab pip install --ignore-installed --install-option="--prefix=$OPENHAB_CONF/automation/lib/python/personal" holidays

but this failed. The output from this is as follows;

/usr/lib/python2.7/dist-packages/pip/_internal/commands/ UserWarning: Disabling all use of wheels due to the use of --build-options / --global-options / --install-options.
Looking in indexes:,
Collecting holidays
  Using cached
Collecting convertdate (from holidays)
  Using cached
Collecting korean_lunar_calendar (from holidays)
  Using cached
Collecting python-dateutil (from holidays)
  Using cached
  Installing build dependencies ... error
  Complete output from command /usr/bin/python -m pip install --ignore-installed --no-user --prefix /tmp/pip-build-env-yBGSFg --no-warn-script-location --no-binary :all: --only-binary :none: -i --extra-index-url -- "setuptools; python_version != '3.3'" "setuptools<40.0; python_version == '3.3'" wheel setuptools_scm:
  Ignoring setuptools: markers 'python_version == "3.3"' don't match your environment
  Looking in indexes:,,
  Collecting setuptools
    Using cached
  Collecting wheel
    Using cached
      Complete output from command python egg_info:
      Traceback (most recent call last):
        File "<string>", line 1, in <module>
        File "/tmp/pip-install-iXHpqb/wheel/", line 4, in <module>
          setup(maintainer=u'Alex Grönholm')
        File "/usr/lib/python2.7/dist-packages/setuptools/", line 144, in setup
        File "/usr/lib/python2.7/dist-packages/setuptools/", line 139, in _install_setup_requires
        File "/usr/lib/python2.7/dist-packages/setuptools/", line 724, in fetch_build_eggs
        File "/usr/lib/python2.7/dist-packages/pkg_resources/", line 782, in resolve
        File "/usr/lib/python2.7/dist-packages/pkg_resources/", line 1065, in best_match
          return self.obtain(req, installer)
        File "/usr/lib/python2.7/dist-packages/pkg_resources/", line 1077, in obtain
          return installer(requirement)
        File "/usr/lib/python2.7/dist-packages/setuptools/", line 791, in fetch_build_egg
          return cmd.easy_install(req)
        File "/usr/lib/python2.7/dist-packages/setuptools/command/", line 704, in easy_install
          return self.install_item(spec, dist.location, tmpdir, deps)
        File "/usr/lib/python2.7/dist-packages/setuptools/command/", line 730, in install_item
          dists = self.install_eggs(spec, download, tmpdir)
        File "/usr/lib/python2.7/dist-packages/setuptools/command/", line 915, in install_eggs
          return self.build_and_install(setup_script, setup_base)
        File "/usr/lib/python2.7/dist-packages/setuptools/command/", line 1183, in build_and_install
          self.run_setup(setup_script, setup_base, args)
        File "/usr/lib/python2.7/dist-packages/setuptools/command/", line 1169, in run_setup
          run_setup(setup_script, args)
        File "/usr/lib/python2.7/dist-packages/setuptools/", line 233, in run_setup
          with setup_context(setup_dir):
        File "/usr/lib/python2.7/", line 17, in __enter__
        File "/usr/lib/python2.7/dist-packages/setuptools/", line 195, in setup_context
        File "/usr/lib/python2.7/", line 35, in __exit__
          self.gen.throw(type, value, traceback)
        File "/usr/lib/python2.7/dist-packages/setuptools/", line 166, in save_modules
        File "/usr/lib/python2.7/dist-packages/setuptools/", line 141, in resume
          six.reraise(type, exc, self._tb)
        File "/usr/lib/python2.7/dist-packages/setuptools/", line 154, in save_modules
          yield saved
        File "/usr/lib/python2.7/dist-packages/setuptools/", line 194, in setup_context
        File "setuptools/", line 16, in <module>
        File "setuptools/", line 1, in <module>
        File "pkg_resources/", line 1365
          raise SyntaxError(e) from e
      SyntaxError: invalid syntax
  Command "python egg_info" failed with error code 1 in /tmp/pip-install-iXHpqb/wheel/
Command "/usr/bin/python -m pip install --ignore-installed --no-user --prefix /tmp/pip-build-env-yBGSFg --no-warn-script-location --no-binary :all: --only-binary :none: -i --extra-index-url -- "setuptools; python_version != '3.3'" "setuptools<40.0; python_version == '3.3'" wheel setuptools_scm" failed with error code 1 in None

I’m still pretty new to Python, but is this telling me that this library is written for Python 3 and therefore I won’t be able to install it? Is there any sort of workaround here? Why did it not fail when I ran the initial simple ‘pip’ command?

PyPi says it supports 2.7. You have the files and dependencies already installed, so you could manually copy them over. Or add your python installation directory to the python.path property in EXTRA_JAVA_OPTS.

As a general rule I like to encourage the use of openHAB features where possible. You are writing rules for openHAB after all so you will often end up with a better result if you use the features provided by openHAB instead of using native Python versions of things. Given that, why not use Ephemeris? It uses JollyDay so all you need to do is configure you coutnry and region and it will automatically configure your holidays. If that isn’t sufficient you can define your own. Then you can use the ephemeris actions in your rules. No need to import an external Python library.

OK, I hadn’t come across Ephemeris. It looks like it might do the job, although looking at the XML file for Australia it seems to have very few of our public holidays defined compared with the holidays library. Defining the rest probably isn’t too hard. Will I be able to define ‘the day before the last Saturday in September’?

Yes. See The only ones that are tricky and require changes to code (i.e. we can’t handle that) are those holidays based on the lunar calendar like Easter, Rosh Hashanah, or Ramadan and the like. Those are directly programmed into the library. For everything else though you can define stuff like that.