Skip to content

Commit

Permalink
Allow an import of pywintypes to work when installed before the post_…
Browse files Browse the repository at this point in the history
…install script has been run
  • Loading branch information
mhammond committed Jan 21, 2018
1 parent 375dca3 commit 45975ce
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions win32/Lib/pywintypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,18 @@ def __import_pywin32_system_module__(modname, globs):
# easy_install...
if os.path.isfile(os.path.join(os.path.dirname(__file__), filename)):
found = os.path.join(os.path.dirname(__file__), filename)
if found is None:
# We might have been installed via PIP and without the post-install
# script having been run, so they might be in the
# lib/site-packages/pywin32_system32 directory.
# This isn't ideal as it means, say 'python -c "import win32api"'
# will not work but 'python -c "import pywintypes, win32api"' will,
# but it's better than nothing...
import distutils.sysconfig
maybe = os.path.join(distutils.sysconfig.get_python_lib(plat_specific=1),
"pywin32_system32", filename)
if os.path.isfile(maybe):
found = maybe
if found is None:
# give up in disgust.
raise ImportError("No system module '%s' (%s)" % (modname, filename))
Expand Down

0 comments on commit 45975ce

Please sign in to comment.