Skip to content

Commit

Permalink
Add work-around for tensorflow < 2.3.0 trying to use site.USER_SITE
Browse files Browse the repository at this point in the history
Add a run-time hook for `tensorflow` that sets `site.USER_SITE` to
an empty string, in order to prevent run-time errors caused by
`tensorflow` < 2.3.0 blindly passing `site.USER_SITE` to
`str.startswith`.

Due to `site` being disabled in PyInstaller-frozen application,
`site.USER_SITE` is `None`. In PyInstaller versions prior to v5.5,
this was mitigated by PyInstaller's own fake `site` module, which
also set `site.USER_SITE` to an empty string.
  • Loading branch information
rokm committed Feb 13, 2023
1 parent 36d6811 commit 74467d1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
3 changes: 3 additions & 0 deletions news/546.update.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Add work-around for ``tensorflow`` < 2.3.0 trying to use
``site.USER_SITE``, which is ``None`` in PyInstaller 5.5 and later
due to removal of PyInstaller's fake ``site`` module.
1 change: 1 addition & 0 deletions src/_pyinstaller_hooks_contrib/hooks/rthooks.dat
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
'pythoncom': ['pyi_rth_pythoncom.py'],
'pyqtgraph': ['pyi_rth_pyqtgraph_multiprocess.py'],
'pywintypes': ['pyi_rth_pywintypes.py'],
'tensorflow': ['pyi_rth_tensorflow.py'],
}
19 changes: 19 additions & 0 deletions src/_pyinstaller_hooks_contrib/hooks/rthooks/pyi_rth_tensorflow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#-----------------------------------------------------------------------------
# Copyright (c) 2023, PyInstaller Development Team.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
#
# The full license is in the file COPYING.txt, distributed with this software.
#
# SPDX-License-Identifier: Apache-2.0
#-----------------------------------------------------------------------------

# `tensorflow` versions prior to 2.3.0 attempt to use `site.USER_SITE` in path/string manipulation functions.
# As frozen application runs with disabled `site`, the value of this variable is `None`, and causes path/string
# manipulation functions to raise an error. As a work-around, we set `site.USER_SITE` to an empty string, which is
# also what the fake `site` module available in PyInstaller prior to v5.5 did.
import site

if site.USER_SITE is None:
site.USER_SITE = ''

0 comments on commit 74467d1

Please sign in to comment.