Pymc3 Installation in Jupyter Notebook +Theano

I installed pymc3 with the following commands pip install pymc3 in cmd.exe and in Anaconda Prompt. Running a python code including pymc3 I am encountered the following error:
AttributeError: partially initialized module ‘theano’ has no attribute ‘compile’ (most likely due to a circular import)
How can I fix this issue?

AttributeError Traceback (most recent call last)
Cell In[9], line 6
3 uncensored=censored[(censored>low)]
4 assert len(uncensored) == n_observed
----> 6 from pymc3.distributions.dist_math import normal_lcdf
7 from pymc3.distributions.dist_math import normal_lccdf
8 import pymc3 as pm

File ~\AppData\Roaming\Python\Python311\site-packages\
20 import platform
22 import semver
—> 23 import theano
25 _log = logging.getLogger(“pymc3”)
27 if not logging.root.handlers:

File ~\AppData\Roaming\Python\Python311\site-packages\
75 # This is the api version for ops that generate C code. External ops
76 # might need manual changes if this number goes up. An undefined
77 # api_version can be understood to mean api version 0.
78 #
79 # This number is not tied to the release version and should change
80 # very rarely.
81 api_version = 1
—> 83 from theano import scalar, tensor
84 from theano.compile import (
85 In,
86 Mode,
93 shared,
94 )
95 from theano.compile.function import function, function_dump

File ~\AppData\Roaming\Python\Python311\site-packages\theano\
----> 1 from .basic import *
2 from .basic_scipy import *

File ~\AppData\Roaming\Python\Python311\site-packages\theano\scalar\
706 return shape_info
709 # Register C code for ViewOp on Scalars.
→ 710 theano.compile.register_view_op_c_code(
711 Scalar,
712 “”"
713 %(oname)s = %(iname)s;
714 “”",
715 1,
716 )
719 bool = get_scalar_type(“bool”)
720 int8 = get_scalar_type(“int8”)

AttributeError: partially initialized module ‘theano’ has no attribute ‘compile’ (most likely due to a circular import)

Any reason you need the now very old pymc3 instead of the up to date pymc?

Recommend installation for the new PyMC is to not use pip: Installation — PyMC 5.10.3 documentation

Dear Ricardo,

I thank You for your reply.
The thing is that I can successfully run the first line of the installation code you indicated in the Anaconda Prompt.
(pm3env) C:\Users\Tihamér>conda create -c conda-forge -n pymc_env “pymc>=5”
WARNING: A conda environment already exists at ‘C:\Users\Tihamér.conda\envs\pymc_env’
However, when I try to run the second line of the installation code: conda activate pymc_env
I am encountered the following error message:
(pm3env) C:\Users\Tihamér>conda activate pymc_env
Error message: The system cannot find the specified path.

Any idea how can we fix this?

Anyway, I have just corrected my bayesian code from pymc3 to pymc and with many warnings but finally it has worked out, I thank you for your idea!

This looks like you’ve made an environment called pymc_env previously? I’d do conda remove -n pymc_env then conda clean --all, then try to create the environment again.

Nuclear option is to go to C:\Users\Tihamér.conda\envs and trashcan the pymc_env folder.

1 Like

It has worked out, thank You so much!

1 Like