Pymc import error - new installation

I just installed pymc into a new environment on ubuntu 22.04

mamba create -c conda-forge -n bayes "pymc>=5"
mamba activate bayes
mamba install nutpie
mamba install ipykernel

I went to VSCode, started a new jupyter-notebook, chose bayes as my kernel and tried to run:

import numpy as np
import pymc as pm

This gives me the following error:

> ---------------------------------------------------------------------------
> AttributeError                            Traceback (most recent call last)
> Cell In[2], line 2
>       1 import numpy as np
> ----> 2 import pymc as pm
> 
> File ~/local/programs/miniforge3/envs/bayes/lib/python3.12/site-packages/pymc/__init__.py:46
>      41     augmented = f"{augmented} -fno-unwind-tables -fno-asynchronous-unwind-tables"
>      43     pytensor.config.gcc__cxxflags = augmented
> ---> 46 __set_compiler_flags()
>      48 from pymc import _version, gp, ode, sampling
>      49 from pymc.backends import *
> 
> File ~/local/programs/miniforge3/envs/bayes/lib/python3.12/site-packages/pymc/__init__.py:29, in __set_compiler_flags()
>      27 def __set_compiler_flags():
>      28     # Workarounds for PyTensor compiler problems on various platforms
> ---> 29     import pytensor
>      31     current = pytensor.config.gcc__cxxflags
>      32     augmented = f"{current} -Wno-c++11-narrowing"
> 
> File ~/local/programs/miniforge3/envs/bayes/lib/python3.12/site-packages/pytensor/__init__.py:119
>     115     return as_tensor_variable(x, **kwargs)
>     118 # isort: off
> --> 119 from pytensor import scalar, tensor
>     120 from pytensor.compile import (
>     121     In,
>     122     Mode,
>    (...)
>     128     shared,
>     129 )
>     130 from pytensor.compile.function import function, function_dump
> 
> File ~/local/programs/miniforge3/envs/bayes/lib/python3.12/site-packages/pytensor/tensor/__init__.py:103
>      99     return len(var.data)
>     102 import pytensor.tensor.exceptions
> --> 103 import pytensor.tensor.rewriting
>     104 from pytensor.gradient import grad, hessian, jacobian
>     106 # adds shared-variable constructors
> 
> File ~/local/programs/miniforge3/envs/bayes/lib/python3.12/site-packages/pytensor/tensor/rewriting/__init__.py:1
> ----> 1 import pytensor.tensor.rewriting.basic
>       2 import pytensor.tensor.rewriting.blas
>       3 import pytensor.tensor.rewriting.blas_c
> 
> File ~/local/programs/miniforge3/envs/bayes/lib/python3.12/site-packages/pytensor/tensor/rewriting/basic.py:43
>      34 from pytensor.graph.rewriting.basic import (
>      35     NodeRewriter,
>      36     RemovalNodeRewriter,
>    (...)
>      40     node_rewriter,
>      41 )
>      42 from pytensor.graph.rewriting.db import RewriteDatabase
> ---> 43 from pytensor.raise_op import Assert, CheckAndRaise, assert_op
>      44 from pytensor.scalar.basic import Second
>      45 from pytensor.tensor.basic import (
>      46     Alloc,
>      47     AllocEmpty,
>    (...)
>      65     zeros_like,
>      66 )
> 
> File ~/local/programs/miniforge3/envs/bayes/lib/python3.12/site-packages/pytensor/raise_op.py:14
>      12 from pytensor.link.c.type import Generic
>      13 from pytensor.scalar.basic import ScalarType
> ---> 14 from pytensor.tensor.type import DenseTensorType
>      17 class ExceptionType(Generic):
>      18     def __eq__(self, other):
> 
> File ~/local/programs/miniforge3/envs/bayes/lib/python3.12/site-packages/pytensor/tensor/type.py:734
>     730 def values_eq_approx_always_true(a, b):
>     731     return True
> --> 734 pytensor.compile.register_view_op_c_code(
>     735     TensorType,
>     736     """
>     737     Py_XDECREF(%(oname)s);
>     738     %(oname)s = %(iname)s;
>     739     Py_XINCREF(%(oname)s);
>     740     """,
>     741     version=1,
>     742 )
>     745 pytensor.compile.register_deep_copy_op_c_code(
>     746     TensorType,
>     747     """
>    (...)
>     773     version=2,
>     774 )
>     776 # Valid static type entries
> 
> AttributeError: partially initialized module 'pytensor' has no attribute 'compile' (most likely due to a circular import)

my conda list output

packages in environment at …/miniforge3/envs/bayes:
Name Version Build Channel
_libgcc_mutex 0.1 conda_forge conda-forge
_openmp_mutex 4.5 2_gnu conda-forge
arviz 0.19.0 pyhd8ed1ab_0 conda-forge
asttokens 2.0.5 pyhd3eb1b0_0
atk-1.0 2.38.0 h04ea711_2 conda-forge
aws-c-auth 0.7.22 hbd3ac97_10 conda-forge
aws-c-cal 0.7.1 h87b94db_1 conda-forge
aws-c-common 0.9.23 h4ab18f5_0 conda-forge
aws-c-compression 0.2.18 he027950_7 conda-forge
aws-c-event-stream 0.4.2 h7671281_15 conda-forge
aws-c-http 0.8.2 he17ee6b_6 conda-forge
aws-c-io 0.14.10 h826b7d6_1 conda-forge
aws-c-mqtt 0.10.4 hcd6a914_8 conda-forge
aws-c-s3 0.6.0 h365ddd8_2 conda-forge
aws-c-sdkutils 0.1.16 he027950_3 conda-forge
aws-checksums 0.1.18 he027950_7 conda-forge
aws-crt-cpp 0.27.3 hda66527_2 conda-forge
aws-sdk-cpp 1.11.329 h46c3b66_9 conda-forge
azure-core-cpp 1.12.0 h830ed8b_0 conda-forge
azure-identity-cpp 1.8.0 hdb0d106_1 conda-forge
azure-storage-blobs-cpp 12.11.0 ha67cba7_1 conda-forge
azure-storage-common-cpp 12.6.0 he3f277c_1 conda-forge
azure-storage-files-datalake-cpp 12.10.0 h29b5301_1 conda-forge
brotli 1.1.0 hd590300_1 conda-forge
brotli-bin 1.1.0 hd590300_1 conda-forge
bzip2 1.0.8 h4bc722e_7 conda-forge
c-ares 1.32.3 h4bc722e_0 conda-forge
ca-certificates 2024.7.4 hbcca054_0 conda-forge
cached-property 1.5.2 hd8ed1ab_1 conda-forge
cached_property 1.5.2 pyha770c72_1 conda-forge
cachetools 5.4.0 pyhd8ed1ab_0 conda-forge
cairo 1.18.0 hbb29018_2 conda-forge
certifi 2024.7.4 pyhd8ed1ab_0 conda-forge
cloudpickle 3.0.0 pyhd8ed1ab_0 conda-forge
comm 0.2.1 py312h06a4308_0
cons 0.4.6 pyhd8ed1ab_0 conda-forge
contourpy 1.2.1 py312h8572e83_0 conda-forge
cycler 0.12.1 pyhd8ed1ab_0 conda-forge
debugpy 1.6.7 py312h6a678d5_0
decorator 5.1.1 pyhd3eb1b0_0
dm-tree 0.1.8 py312h72fbbdf_4 conda-forge
etuples 0.3.9 pyhd8ed1ab_0 conda-forge
executing 0.8.3 pyhd3eb1b0_0
expat 2.6.2 h59595ed_0 conda-forge
filelock 3.15.4 pyhd8ed1ab_0 conda-forge
font-ttf-dejavu-sans-mono 2.37 hab24e00_0 conda-forge
font-ttf-inconsolata 3.000 h77eed37_0 conda-forge
font-ttf-source-code-pro 2.038 h77eed37_0 conda-forge
font-ttf-ubuntu 0.83 h77eed37_2 conda-forge
fontconfig 2.14.2 h14ed4e7_0 conda-forge
fonts-conda-ecosystem 1 0 conda-forge
fonts-conda-forge 1 0 conda-forge
fonttools 4.53.1 py312h41a817b_0 conda-forge
freetype 2.12.1 h267a509_2 conda-forge
fribidi 1.0.10 h36c2ea0_0 conda-forge
gdk-pixbuf 2.42.12 hb9ae30d_0 conda-forge
gflags 2.2.2 h6a678d5_1
giflib 5.2.2 hd590300_0 conda-forge
glog 0.7.1 hbabe93e_0 conda-forge
graphite2 1.3.13 h59595ed_1003 conda-forge
graphviz 11.0.0 hc68bbd7_0 conda-forge
gtk2 2.24.33 h6470451_5 conda-forge
gts 0.7.6 h977cf35_4 conda-forge
h5netcdf 1.3.0 pyhd8ed1ab_0 conda-forge
h5py 3.11.0 nompi_py312hb7ab980_102 conda-forge
harfbuzz 9.0.0 hfac3d4d_0 conda-forge
hdf5 1.14.3 nompi_hdf9ad27_105 conda-forge
icu 73.2 h59595ed_0 conda-forge
ipykernel 6.28.0 py312h06a4308_0
ipython 8.25.0 py312h06a4308_0
jedi 0.19.1 py312h06a4308_0
jupyter_client 8.6.0 py312h06a4308_0
jupyter_core 5.7.2 py312h06a4308_0
keyutils 1.6.1 h166bdaf_0 conda-forge
kiwisolver 1.4.5 py312h8572e83_1 conda-forge
krb5 1.21.3 h659f571_0 conda-forge
lcms2 2.16 hb7c19ff_0 conda-forge
ld_impl_linux-64 2.40 hf3520f5_7 conda-forge
lerc 4.0.0 h27087fc_0 conda-forge
libabseil 20240116.2 cxx17_he02047a_1 conda-forge
libaec 1.1.3 h59595ed_0 conda-forge
libarrow 17.0.0 h34456a7_0_cpu conda-forge
libarrow-acero 17.0.0 he02047a_0_cpu conda-forge
libarrow-dataset 17.0.0 he02047a_0_cpu conda-forge
libarrow-substrait 17.0.0 hc9a23c6_0_cpu conda-forge
libblas 3.9.0 23_linux64_openblas conda-forge
libbrotlicommon 1.1.0 hd590300_1 conda-forge
libbrotlidec 1.1.0 hd590300_1 conda-forge
libbrotlienc 1.1.0 hd590300_1 conda-forge
libcblas 3.9.0 23_linux64_openblas conda-forge
libcrc32c 1.1.2 h6a678d5_0
libcurl 8.9.0 hdb1bdb2_0 conda-forge
libdeflate 1.20 hd590300_0 conda-forge
libedit 3.1.20191231 he28a2e2_2 conda-forge
libev 4.33 hd590300_2 conda-forge
libevent 2.1.12 hdbd6064_1
libexpat 2.6.2 h59595ed_0 conda-forge
libffi 3.4.2 h7f98852_5 conda-forge
libgcc-ng 14.1.0 h77fa898_0 conda-forge
libgd 2.3.3 h119a65a_9 conda-forge
libgfortran-ng 14.1.0 h69a702a_0 conda-forge
libgfortran5 14.1.0 hc5f4f2c_0 conda-forge
libglib 2.80.3 h8a4344b_1 conda-forge
libgomp 14.1.0 h77fa898_0 conda-forge
libgoogle-cloud 2.26.0 h26d7fe4_0 conda-forge
libgoogle-cloud-storage 2.26.0 ha262f82_0 conda-forge
libgrpc 1.62.2 h15f2491_0 conda-forge
libiconv 1.17 hd590300_2 conda-forge
libjpeg-turbo 3.0.0 hd590300_1 conda-forge
liblapack 3.9.0 23_linux64_openblas conda-forge
libnghttp2 1.58.0 h47da74e_1 conda-forge
libnsl 2.0.1 hd590300_0 conda-forge
libopenblas 0.3.27 pthreads_hac2b453_1 conda-forge
libparquet 17.0.0 h9e5060d_0_cpu conda-forge
libpng 1.6.43 h2797004_0 conda-forge
libprotobuf 4.25.3 h08a7969_0 conda-forge
libre2-11 2023.09.01 h5a48ba9_2 conda-forge
librsvg 2.58.2 h9564881_1 conda-forge
libsodium 1.0.18 h7b6447c_0
libsqlite 3.46.0 hde9e2c9_0 conda-forge
libssh2 1.11.0 h0841786_0 conda-forge
libstdcxx-ng 14.1.0 hc0a3c3a_0 conda-forge
libthrift 0.19.0 hb90f79a_1 conda-forge
libtiff 4.6.0 h1dd3fc0_3 conda-forge
libutf8proc 2.8.0 h166bdaf_0 conda-forge
libuuid 2.38.1 h0b41bf4_0 conda-forge
libwebp 1.4.0 h2c329e2_0 conda-forge
libwebp-base 1.4.0 hd590300_0 conda-forge
libxcb 1.16 hd590300_0 conda-forge
libxcrypt 4.4.36 hd590300_1 conda-forge
libxml2 2.12.7 h4c95cb1_3 conda-forge
libzlib 1.3.1 h4ab18f5_1 conda-forge
logical-unification 0.4.6 pyhd8ed1ab_0 conda-forge
lz4-c 1.9.4 h6a678d5_1
markdown-it-py 3.0.0 pyhd8ed1ab_0 conda-forge
matplotlib-base 3.9.1 py312h9201f00_0 conda-forge
matplotlib-inline 0.1.6 py312h06a4308_0
mdurl 0.1.2 pyhd8ed1ab_0 conda-forge
minikanren 1.0.3 pyhd8ed1ab_0 conda-forge
multipledispatch 0.6.0 py_0 conda-forge
munkres 1.1.4 pyh9f0ad1d_0 conda-forge
ncurses 6.5 h59595ed_0 conda-forge
nest-asyncio 1.6.0 py312h06a4308_0
numpy 1.26.4 py312heda63a1_0 conda-forge
nutpie 0.13.1 py312h6a493c6_0 conda-forge
openjpeg 2.5.2 h488ebb8_0 conda-forge
openssl 3.3.1 h4bc722e_2 conda-forge
orc 2.0.1 h17fec99_1 conda-forge
packaging 24.1 pyhd8ed1ab_0 conda-forge
pandas 2.2.2 py312h1d6d2e6_1 conda-forge
pango 1.54.0 h4c5309f_1 conda-forge
parso 0.8.3 pyhd3eb1b0_0
pcre2 10.44 h0f59acf_0 conda-forge
pexpect 4.8.0 pyhd3eb1b0_3
pillow 10.4.0 py312h287a98d_0 conda-forge
pip 24.0 pyhd8ed1ab_0 conda-forge
pixman 0.43.2 h59595ed_0 conda-forge
platformdirs 3.10.0 py312h06a4308_0
prompt-toolkit 3.0.43 py312h06a4308_0
prompt_toolkit 3.0.43 hd3eb1b0_0
psutil 5.9.0 py312h5eee18b_0
pthread-stubs 0.4 h36c2ea0_1001 conda-forge
ptyprocess 0.7.0 pyhd3eb1b0_2
pure_eval 0.2.2 pyhd3eb1b0_0
pyarrow 17.0.0 py312h9cebb41_0 conda-forge
pyarrow-core 17.0.0 py312h264c024_0_cpu conda-forge
pygments 2.18.0 pyhd8ed1ab_0 conda-forge
pymc 5.16.2 hd8ed1ab_0 conda-forge
pymc-base 5.16.2 pyhd8ed1ab_0 conda-forge
pyparsing 3.1.2 pyhd8ed1ab_0 conda-forge
pytensor 2.23.0 py312h526ad5a_0
pytensor-base 2.25.2 py312h7122da0_0 conda-forge
python 3.12.4 h194c7f8_0_cpython conda-forge
python-dateutil 2.9.0 pyhd8ed1ab_0 conda-forge
python-graphviz 0.20.3 pyh717bed2_0 conda-forge
python-tzdata 2024.1 pyhd8ed1ab_0 conda-forge
python_abi 3.12 4_cp312 conda-forge
pytz 2024.1 pyhd8ed1ab_0 conda-forge
pyzmq 25.1.2 py312h6a678d5_0
qhull 2020.2 h434a139_5 conda-forge
re2 2023.09.01 h7f4b329_2 conda-forge
readline 8.2 h8228510_1 conda-forge
rich 13.7.1 pyhd8ed1ab_0 conda-forge
s2n 1.4.17 he19d79f_0 conda-forge
scipy 1.13.1 py312hc2bc53b_0 conda-forge
setuptools 71.0.4 pyhd8ed1ab_0 conda-forge
six 1.16.0 pyh6c4a22f_0 conda-forge
snappy 1.2.1 ha2e4443_0 conda-forge
stack_data 0.2.0 pyhd3eb1b0_0
threadpoolctl 3.5.0 pyhc1e730c_0 conda-forge
tk 8.6.13 noxft_h4845f30_101 conda-forge
toolz 0.12.1 pyhd8ed1ab_0 conda-forge
tornado 6.4.1 py312h5eee18b_0
traitlets 5.14.3 py312h06a4308_0
typing-extensions 4.12.2 hd8ed1ab_0 conda-forge
typing_extensions 4.12.2 pyha770c72_0 conda-forge
tzdata 2024a h0c530f3_0 conda-forge
wcwidth 0.2.5 pyhd3eb1b0_0
wheel 0.43.0 pyhd8ed1ab_1 conda-forge
xarray 2024.6.0 pyhd8ed1ab_1 conda-forge
xarray-einstats 0.7.0 pyhd8ed1ab_0 conda-forge
xorg-kbproto 1.0.7 h7f98852_1002 conda-forge
xorg-libice 1.1.1 hd590300_0 conda-forge
xorg-libsm 1.2.4 h7391055_0 conda-forge
xorg-libx11 1.8.9 hb711507_1 conda-forge
xorg-libxau 1.0.11 hd590300_0 conda-forge
xorg-libxdmcp 1.1.3 h7f98852_0 conda-forge
xorg-libxext 1.3.4 h0b41bf4_2 conda-forge
xorg-libxrender 0.9.11 hd590300_0 conda-forge
xorg-renderproto 0.11.1 h7f98852_1002 conda-forge
xorg-xextproto 7.3.0 h0b41bf4_1003 conda-forge
xorg-xproto 7.0.31 h7f98852_1007 conda-forge
xz 5.2.6 h166bdaf_0 conda-forge
zeromq 4.3.5 h6a678d5_0
zlib 1.3.1 h4ab18f5_1 conda-forge
zstd 1.5.6 ha6fb4c9_0 conda-forge

Thanks for any help
sar

I’m not sure where many of those packages came from (probably nutpie). More importantly, there’s no blas, no gcc, no mkl, etc. Any suggestions @maresb ?

Thanks - I made a new environment without installing nutpie and was able to import pymc. A test run of a model worked. So it looks like that fixed it.

The nutpie suggestion was from the pymc installation page (Installation — PyMC dev documentation) so it might be worthwhile to check whether it’s just something particular to my setup or whether something about the current version of nutpie is breaking it more generally.

Thanks again for your help

Nutpie is great and you should definitely install it. The only thing I immediately see is that the installation instructions set the channel to conda-forge which you appear not to have done:

conda install -c conda-forge nutpie

Now that you have a working environment, maybe you can experiment will trying to install nutpie into it using the recommended approach?

That did work, although it looks like it isn’t nutpie. My mamba installation is set up to default to conda-forge so it did install nutpie from conda-forge before, and this time just used the cached installation it had downloaded previously. However, it had used some cached versions of other packages (libcrc32c, gflags, lz4-c, libevent) that were from pkgs/main that I must have downloaded for a different environment. In particular, libcrc32c was an earlier version (the others were the same version as from conda-forge).

1 Like

All the lines in your package list that don’t say conda-forge are coming from the main channel. In particular, note how pytensor is the main-channel version. This explains why there are no BLAS packages. I’d try adding -c nodefaults to your mamba create command, and this will prevent things from being installed from the main channel.

1 Like

My .condarc from my mamba installation is:

channels:

  • conda-forge

I assumed that meant it pulled from conda-forge first. Is that correct?

That said, I have the same pytensor and pytensor-base versions in the environments that work and don’t work:

For pytensor, here is the conda list output from the environment that does work:

pytensor 2.23.0 py312h526ad5a_0
pytensor-base 2.25.2 py312h7122da0_0 conda-forge

and here is the output from the environment that doesn’t:

pytensor 2.23.0 py312h526ad5a_0
pytensor-base 2.25.2 py312h7122da0_0 conda-forge

In my installation of the one that does work:

mamba create -c conda-forge -n bayes2 “pymc>=5”

it pulled pytensor from pkgs/main anyway

  • pytensor-base 2.25.2 py312h7122da0_0 conda-forge Cached
  • h5netcdf 1.3.0 pyhd8ed1ab_0 conda-forge Cached
  • xarray 2024.6.0 pyhd8ed1ab_1 conda-forge Cached
  • xarray-einstats 0.7.0 pyhd8ed1ab_0 conda-forge Cached
  • arviz 0.19.0 pyhd8ed1ab_0 conda-forge Cached
  • pymc-base 5.16.2 pyhd8ed1ab_0 conda-forge Cached
  • pytensor 2.23.0 py312h526ad5a_0 pkgs/main Cached
  • pymc 5.16.2 hd8ed1ab_0 conda-forge Cached

Even if it happens to be working for some reason, you should still start over with a new environment that is not mixed up with the main channel. Could you please try adding -c nodefaults to your mamba create command to create a fresh environment?

when I do this:

mamba create -c nodefaults -c conda-forge -n bayes3 “pymc>=5”

it still pulled pytensor from my cached version from pkgs/main

However, I tried:

mamba create --override-channels -c conda-forge -n bayes3 “pymc>=5”

and that pulled it from conda-forge

  • pytensor-base 2.25.2 py312h7122da0_0 conda-forge Cached
    • pytensor 2.25.2 py312hb237e42_0 conda-forge 9kB

Thanks

1 Like