brightway-lca / brightway2

Metapackage for brightway2 imports and documentation
https://brightway.dev/
BSD 3-Clause "New" or "Revised" License
100 stars 37 forks source link

Kernel dies at Package Import on Mac M1 #44

Closed michaelweinold closed 2 years ago

michaelweinold commented 2 years ago

Following the installation instructions (tried both "Quickstart" and "Installation on Mac M1"), my kernel dies when importing any package:

from matplotlib import pyplot as plt

returns

The Kernel crashed while executing code in the the current cell or a previous cell. Please review the code in the cell(s) to identify a possible cause of the failure. Click here for more info. View Jupyter log for further details.

The logs read

info 13:1:58.641: Execute Cell 2 /Users/michaelweinold/github/brightway2/notebooks/Systematic bias in Monte Carlo medians.ipynb
error 13:2:12.291: Error in waiting for cell to complete [Error: Canceled future for execute_request message before replies were done
    at a.KernelShellFutureHandler.dispose (/Users/michaelweinold/.vscode/extensions/ms-toolsai.jupyter-2022.6.1101950301/out/node_modules/@jupyterlab/services.js:2:32353)
    at /Users/michaelweinold/.vscode/extensions/ms-toolsai.jupyter-2022.6.1101950301/out/node_modules/@jupyterlab/services.js:2:26572
    at Map.forEach (<anonymous>)
    at y._clearKernelState (/Users/michaelweinold/.vscode/extensions/ms-toolsai.jupyter-2022.6.1101950301/out/node_modules/@jupyterlab/services.js:2:26557)
    at /Users/michaelweinold/.vscode/extensions/ms-toolsai.jupyter-2022.6.1101950301/out/node_modules/@jupyterlab/services.js:2:29000
    at processTicksAndRejections (node:internal/process/task_queues:96:5)]
warn 13:2:12.291: Cell completed with errors {
  message: 'Canceled future for execute_request message before replies were done'
}
info 13:2:12.291: Cancel all remaining cells true || Error || undefined
info 13:2:12.291: Cancel pending cells
info 13:2:12.291: Cell 2 executed with state Error

System: macOS Monterey, 12.4 (21F79) conda 4.13.0

michaelweinold commented 2 years ago

The issue occurs in both the browser-based notebook and VS Code.

Simple printing commands like

print("hello world")

work fine.

Some package imports, such as

import jinja2
import tornado
import tabulate

work fine.

Package imports that kill the kernel:

numpy
pandas
brightway2

Similar log outputs: https://stackoverflow.com/q/71994235 --> confirmed this is not a memory issue https://github.com/microsoft/vscode-jupyter/issues/9157 --> solution not applicable to brightway

michaelweinold commented 2 years ago

Force removing

pyparadiso
mkl

as documented in https://github.com/LCA-ActivityBrowser/activity-browser/issues/705#issuecomment-1032446633 no longer makes the kernel crash. Instead, the following error is thrown:

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
/Users/michaelweinold/github/phd_brightway_sandbox/test.ipynb Cell 4 in <cell line: 1>()
----> 1 import pandas as pd

File /opt/miniconda3/envs/bw_rosetta/lib/python3.9/site-packages/pandas/__init__.py:16, in <module>
     13         missing_dependencies.append(f"{dependency}: {e}")
     15 if missing_dependencies:
---> 16     raise ImportError(
     17         "Unable to import required dependencies:\n" + "\n".join(missing_dependencies)
     18     )
     19 del hard_dependencies, dependency, missing_dependencies
     21 # numpy compat

ImportError: Unable to import required dependencies:
numpy: 

IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!

Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.

We have compiled some common reasons and troubleshooting tips at:

    https://numpy.org/devdocs/user/troubleshooting-importerror.html

Please note and check the following:

  * The Python version is: Python3.9 from "/opt/miniconda3/envs/bw_rosetta/bin/python"
  * The NumPy version is: "1.23.1"

and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.

Original error was: dlopen(/opt/miniconda3/envs/bw_rosetta/lib/python3.9/site-packages/numpy/core/_multiarray_umath.cpython-39-darwin.so, 0x0002): Library not loaded: @rpath/libcblas.3.dylib
  Referenced from: /opt/miniconda3/envs/bw_rosetta/lib/python3.9/site-packages/numpy/core/_multiarray_umath.cpython-39-darwin.so
  Reason: tried: '/opt/miniconda3/envs/bw_rosetta/lib/python3.9/site-packages/numpy/core/../../../../libcblas.3.dylib' (no such file), '/opt/miniconda3/envs/bw_rosetta/lib/python3.9/site-packages/numpy/core/../../../../libcblas.3.dylib' (no such file), '/opt/miniconda3/envs/bw_rosetta/bin/../lib/libcblas.3.dylib' (no such file), '/opt/miniconda3/envs/bw_rosetta/bin/../lib/libcblas.3.dylib' (no such file), '/usr/local/lib/libcblas.3.dylib' (no such file), '/usr/lib/libcblas.3.dylib' (no such file)

The resolution suggested in https://github.com/numpy/numpy/issues/12970 does not resolve the error.

michaelweinold commented 2 years ago

Related: efforts to release platform specific conda packages (pypardiso solver for Win platform, umfpack solver for macOS ARM64 platform):

https://github.com/brightway-lca/brightway2/issues/47 https://github.com/cmutel/conda-recipes/issues/6

cmutel commented 2 years ago

Should be fixed with _nosolver conda packages.