Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notebook does not work on Windows, "ImportError: DLL load failed while importing shell: The specified procedure could not be found." #277

Closed
phil-blain opened this issue May 6, 2022 · 10 comments · Fixed by #279
Labels
bug Issues that present a reasonable conviction there is a reproducible bug.

Comments

@phil-blain
Copy link
Contributor

What happened: I tried to open the "Calculating ENSO with Xarray" tutorial on my Windows laptop. It does not work because of some error with package pywin32.

What you expected to happen: It works.

Minimal Complete Verifiable Example:

  1. Install Miniconda (well, Miniforge)
  2. Follow https://foundations.projectpythia.org/preamble/how-to-use.html:
conda env create --force -f https://raw.githubusercontent.com/ProjectPythia/pythia-foundations/main/environment.yml
conda activate pythia-book-dev
git clone git@github.com:ProjectPythia/pythia-foundations.git
cd pythia-foundations
jupyter notebook

then open "enso-xarray" Notebook and execute the first cell. Result:

ImportError: DLL load failed while importing shell: The specified procedure could not be found.
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_31200/1210338269.py in <module>
      2 import matplotlib.pyplot as plt
      3 import xarray as xr
----> 4 from pythia_datasets import DATASETS

~\AppData\Local\miniforge3\envs\pythia-book-dev\lib\site-packages\pythia_datasets\__init__.py in <module>
      4 from pkg_resources import DistributionNotFound, get_distribution
      5 
----> 6 from .datasets import DATASETS, locate
      7 
      8 try:

~\AppData\Local\miniforge3\envs\pythia-book-dev\lib\site-packages\pythia_datasets\datasets.py in <module>
      3 
      4 DATASETS = pooch.create(
----> 5     path=pooch.os_cache('pythia-datasets'),
      6     base_url='https://github.com/ProjectPythia/pythia-datasets/raw/main/data/',
      7     env='PYTHIA_DATASETS_DIR',

~\AppData\Local\miniforge3\envs\pythia-book-dev\lib\site-packages\pooch\utils.py in os_cache(project)
     97 
     98     """
---> 99     return Path(appdirs.user_cache_dir(project))
    100 
    101 

~\AppData\Local\miniforge3\envs\pythia-book-dev\lib\site-packages\appdirs.py in user_cache_dir(appname, appauthor, version, opinion)
    291         if appauthor is None:
    292             appauthor = appname
--> 293         path = os.path.normpath(_get_win_folder("CSIDL_LOCAL_APPDATA"))
    294         if appname:
    295             if appauthor is not False:

~\AppData\Local\miniforge3\envs\pythia-book-dev\lib\site-packages\appdirs.py in _get_win_folder_with_pywin32(csidl_name)
    478 
    479 def _get_win_folder_with_pywin32(csidl_name):
--> 480     from win32com.shell import shellcon, shell
    481     dir = shell.SHGetFolderPath(0, getattr(shellcon, csidl_name), 0, 0)
    482     # Try to make this a unicode path because SHGetFolderPath does

ImportError: DLL load failed while importing shell: The specified procedure could not be found.

Anything else we need to know?: I read https://github.com/mhammond/pywin32#the-specified-procedure-could-not-be-found--entry-point-not-found-errors but I'm not administrator on my computer...

Environment:

  • Python version: 3.8.13
  • Operating System: Windows 10 1909
  • Install method (conda, pip, source): conda
@phil-blain phil-blain added the bug Issues that present a reasonable conviction there is a reproducible bug. label May 6, 2022
@phil-blain
Copy link
Contributor Author

phil-blain commented May 6, 2022

I did try pywin32_postinstall.py -install after activating the environment and before running jupyter notebook, and the same error happens.

Output:

 PS C:\Users\me> pywin32_postinstall.py -install
Parsed arguments are: Namespace(install=True, remove=False, wait=None, silent=False, quiet=False, destination='C:\\Users\\me\\AppData\\Local\\miniforge3\\Lib\\site-packages')
Copied pythoncom39.dll to C:\Users\me\AppData\Local\miniforge3\pythoncom39.dll
Copied pywintypes39.dll to C:\Users\me\AppData\Local\miniforge3\pywintypes39.dll
You do not have the permissions to install COM objects.
The sample COM objects were not registered.
NOTE: PyWin32.chm can not be located, so has not been registered
Registered help file
Pythonwin has been registered in context menu
Creating directory C:\Users\me\AppData\Local\miniforge3\Lib\site-packages\win32com\gen_py
Can't install shortcuts - 'C:\\Users\\me\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Python 3.9' is not a folder
The pywin32 extensions were successfully installed

@phil-blain
Copy link
Contributor Author

I also read https://jupyter-notebook.readthedocs.io/en/latest/troubleshooting.html#resolving-pywin32-issues and tried using:
python.exe $env:CONDA_PREFIX/Scripts/pywin32_postinstall.py -install:

Parsed arguments are: Namespace(destination='C:\\Users\\me\\AppData\\Local\\miniforge3\\envs\\pythia-book-dev\\Lib\\site-packages', install=True, quiet=False, remove=False, silent=False, wait=None)        
Copied pythoncom38.dll to C:\Users\me\AppData\Local\miniforge3\envs\pythia-book-dev\pythoncom38.dll
  Copied pywintypes38.dll to C:\Users\me\AppData\Local\miniforge3\envs\pythia-book-dev\pywintypes38.dll
You do not have the permissions to install COM objects.
  The sample COM objects were not registered.
      NOTE: PyWin32.chm can not be located, so has not been registered 
 Registered help file
     Failed to register pythonwin as editor
   Traceback (most recent call last):
 File "C:\Users\me\AppData\Local\miniforge3\envs\pythia-book-dev/Scripts/pywin32_postinstall.py", line 524, in install
  RegisterPythonwin(True, lib_dir)
       File "C:\Users\me\AppData\Local\miniforge3\envs\pythia-book-dev/Scripts/pywin32_postinstall.py", line 328, in RegisterPythonwin
from win32com.shell import shell, shellcon
   ImportError: DLL load failed while importing shell: La procédure spécifiée est introuvable.
      Creating directory C:\Users\me\AppData\Local\miniforge3\envs\pythia-book-dev\Lib\site-packages\win32com\gen_py
       DLL load failed while importing shell: La procédure spécifiée est introuvable.
   The pywin32 extensions were successfully installed.

Again, same error when executing the first cell.

@phil-blain
Copy link
Contributor Author

A short and faster reproducer:

mamba env create -f https://raw.githubusercontent.com/ProjectPythia/pythia-foundations/main/environment.yml
conda activate pythia-book-dev
python -c 'import pythia_datasets'

@brian-rose
Copy link
Member

@phil-blain thanks for this concise reproducer!

It doesn't sound like the error has anything to do with Pythia content per se, but maybe someone on our team has some knowledge about pywin32 and Jupyter notebooks.

@phil-blain
Copy link
Contributor Author

Yes I agree. I just wanted to report since it's the environment description you ship with the repo that creates this user experience on Windows...

@phil-blain
Copy link
Contributor Author

phil-blain commented May 6, 2022

OK, even smaller env that reproduces:

mamba create -n test python=3.8 pythia-datasets pywin32
conda activate test
 python -c 'import pythia_datasets'

Without =3.8 it installs Python 3.10, and this works. So something in the rest of the packages listed in https://github.com/ProjectPythia/pythia-foundations/main/environment.yml seems to constrain Python to 3.8, in which apparently pywin32 interacts badly ...

@phil-blain
Copy link
Contributor Author

Ok, wrote too fast, the environment.yml itself constrains Python to 3.8 ...

@phil-blain
Copy link
Contributor Author

And removing =3.8 from the environment YAML file does result in a full working environment.

I could submit a PR to do that.

@brian-rose
Copy link
Member

Interesting, I can't remember if there was a good reason that the pythia-book-dev environment was pinned to Python 3.8.

I suggest submitting a PR that removes that, and we'll see if all the tests pass.

phil-blain added a commit to phil-blain/pythia-foundations that referenced this issue May 6, 2022
The environment that conda (or mamba) creates from this file on Windows
does not work; importing 'pythia_datasets' results in a cryptic error:

    ImportError: DLL load failed while importing shell: The specified procedure could not be found.

It seems there is some incompatibility between 'pywin32', a dependency
of 'jupyter_core' on Windows, and 'appdirs' (a dependency of
pythia_dataset's dependency 'pooch'), at least under Python 3.8.

Fix this by lifting the version constrain on the 'python' package. This
creates an environment with Python 3.10, where importing
'pythia_datasets' works correctly.

Closes: ProjectPythia#277
@phil-blain
Copy link
Contributor Author

PR is here: #279

brian-rose pushed a commit that referenced this issue May 9, 2022
The environment that conda (or mamba) creates from this file on Windows
does not work; importing 'pythia_datasets' results in a cryptic error:

    ImportError: DLL load failed while importing shell: The specified procedure could not be found.

It seems there is some incompatibility between 'pywin32', a dependency
of 'jupyter_core' on Windows, and 'appdirs' (a dependency of
pythia_dataset's dependency 'pooch'), at least under Python 3.8.

Fix this by lifting the version constrain on the 'python' package. This
creates an environment with Python 3.10, where importing
'pythia_datasets' works correctly.

Closes: #277
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issues that present a reasonable conviction there is a reproducible bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants