Cannot import PyMc3

Viewed 302

I have installed PyMc3 but the import pymc3 as pm fails. Here is the error message:

WARNING (theano.configdefaults): g++ not available, if using conda: `conda install m2w64-toolchain`
C:\Users\miallana\AppData\Local\Programs\Python\Python39\lib\site-packages\theano\configdefaults.py:560: UserWarning: DeprecationWarning: there is no c++ compiler.This is deprecated and with Theano 0.11 a c++ compiler will be mandatory
  warnings.warn("DeprecationWarning: there is no c++ compiler."
WARNING (theano.configdefaults): g++ not detected ! Theano will be unable to execute optimized C-implementations (for both CPU and GPU) and will default to Python implementations. Performance will be severely degraded. 
To remove this warning, set Theano flags cxx to an empty string.
WARNING (theano.tensor.blas): Using NumPy C-API based implementation for BLAS functions.
Traceback (most recent call last):
  File "c:\Users\miallana\Documents\project\stats.py", line 26, in <module>
    import pymc3 as pm
  File "C:\Users\miallana\AppData\Local\Programs\Python\Python39\lib\site-packages\pymc3\__init__.py", line 41, in <module>
    from .distributions import *
  File "C:\Users\miallana\AppData\Local\Programs\Python\Python39\lib\site-packages\pymc3\distributions\__init__.py", line 15, in <module>
    from . import timeseries
  File "C:\Users\miallana\AppData\Local\Programs\Python\Python39\lib\site-packages\pymc3\distributions\timeseries.py", line 22, in <module>
    from pymc3.util import get_variable_name
  File "C:\Users\miallana\AppData\Local\Programs\Python\Python39\lib\site-packages\pymc3\util.py", line 19, in <module>
    import xarray
  File "C:\Users\miallana\AppData\Local\Programs\Python\Python39\lib\site-packages\xarray\__init__.py", line 1, in <module>
    from . import testing, tutorial
  File "C:\Users\miallana\AppData\Local\Programs\Python\Python39\lib\site-packages\xarray\testing.py", line 9, in <module>
    from xarray.core import duck_array_ops, formatting, utils
  File "C:\Users\miallana\AppData\Local\Programs\Python\Python39\lib\site-packages\xarray\core\duck_array_ops.py", line 26, in <module>
    from . import dask_array_compat, dask_array_ops, dtypes, npcompat, nputils
  File "C:\Users\miallana\AppData\Local\Programs\Python\Python39\lib\site-packages\xarray\core\npcompat.py", line 72, in <module>
    _SupportsDType[np.dtype],
  File "C:\Users\miallana\AppData\Local\Programs\Python\Python39\lib\typing.py", line 262, in inner
    return func(*args, **kwds)
  File "C:\Users\miallana\AppData\Local\Programs\Python\Python39\lib\typing.py", line 980, in __class_getitem__
    _check_generic(cls, params, len(cls.__parameters__))
  File "C:\Users\miallana\AppData\Local\Programs\Python\Python39\lib\site-packages\typing_extensions.py", line 92, in _check_generic
    raise TypeError(f"{cls} is not a generic class")
TypeError: <class 'numpy.typing._dtype_like._SupportsDType'> is not a generic class

I installed it with pip install pymc3 and then tried this and this. I don't have conda.

My installation is:

Python 3.9.1
pymc3 3.9.3
Theano 1.0.5
Windows 10
2 Answers

I solved my problem. It seems that xarray has trouble working with numpy: i had xarray 2022.6.0 and numpy 1.20.0 installed, just as mentionned here. Then, from here, xarray 2022.3.0 seemed to do the job. So i uninstalled xarray 2022.6.0 and installed 2022.3.0.

Then, there was also version compatibility issues between pymc3 3.9.3 and arviz 0.12.1. So i installed latest version of pymc3, which is 3.11.5. Then the module imports with no error, even though i still have the warning.

if I understood your question correctly, you were able to install PyMc3 without any problem but importing the module into the python file is a problem. I have already encountered this error on Microsoft Windows with the beepy module and I managed to fix it by installing the latest version of visual c++ : https://docs.microsoft.com/fr-fr/cpp/windows/latest-supported-vc-redist?view=msvc-170 . I hope that this solution will be useful and that it will allow you to continue your project.

Related