Skip to content

Commit

Permalink
Add workaround for bug in win32api
Browse files Browse the repository at this point in the history
pywintypes38.dll isn't found when importing win32api after pip
installing pywin32, but explicitly importing pywintypes finds it and
allows win32api to be loaded.

See mhammond/pywin32#1399
  • Loading branch information
tonyroberts committed Feb 18, 2021
1 parent 11bb9b5 commit a2479bd
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pyxll_jupyter/kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@
_all_jupyter_processes = []

try:
# pywintypes needs to be imported before win32api for some Python installs.
# See https://github.com/mhammond/pywin32/issues/1399
import pywintypes
import win32api
except ImportError:
pywintypes = None
win32api = None

if getattr(sys, "_ipython_kernel_running", None) is None:
Expand Down Expand Up @@ -290,6 +294,13 @@ def launch_jupyter(connection_file, cwd=None, timeout=30):
env = dict(os.environ)
env["PYTHONPATH"] = ";".join(pythonpath)

# Workaround for bug in win32api
# https://github.com/mhammond/pywin32/issues/1399
if pywintypes is not None:
path = env.get("PATH", "").split(";")
path.insert(0, os.path.dirname(pywintypes.__file__))
env["PATH"] = ";".join(path)

# Set PYXLL_IPYTHON_CONNECTION_FILE so the manager knows what to connect to
env["PYXLL_IPYTHON_CONNECTION_FILE"] = connection_file

Expand Down

0 comments on commit a2479bd

Please sign in to comment.