Very slow sampling. Still can't find what is happening after checking FAQs

I was using Pycharm with Python 3.7.4 and I was trying to learn from this tutorial:
https://docs.pymc.io/en/v3/pymc-examples/examples/generalized_linear_models/GLM.html

After pip install pymc3, I imported it and with 3 warnings:
import pymc3
WARNING (theano.configdefaults): g++ not available, if using conda: conda install m2w64-toolchain
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.
Backend TkAgg is interactive backend. Turning interactive mode on.

Then I tried the linear regression model in that tutorial:
import arviz as az
import bambi as bmb
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import pymc3 as pm
from pymc3 import HalfCauchy, Model, Normal, glm, plot_posterior_predictive_glm, sample

RANDOM_SEED = 8927
rng = np.random.default_rng(RANDOM_SEED)
az.style.use(“arviz-darkgrid”)

size = 200
true_intercept = 1
true_slope = 2
x = np.linspace(0, 1, size)
true_regression_line = true_intercept + true_slope * x
y = true_regression_line + rng.normal(scale=0.5, size=size)
data = pd.DataFrame(dict(x=x, y=y))

with Model() as model: # model specifications in PyMC3 are wrapped in a with-statement
sigma = HalfCauchy(“sigma”, beta=10, testval=1.0)
intercept = Normal(“Intercept”, 0, sigma=20)
x_coeff = Normal(“x”, 0, sigma=20)
likelihood = Normal(“y”, mu=intercept + x_coeff * x, sigma=sigma, observed=y)
trace = sample(100,cores=1,return_inferencedata=True)

BTW I had to add ‘cores=1’ in sample or I would have BrokenPipe Error. That when I found my sampling was very slow, I noticed that in the tutorial it takes only 6s. I found exactly the same question here but there was no clear answer. Any one knows how to fix it?

Welcome!

What platform are you on? And did you follow the installation instructions found here?

Thank you for your reply. It seems that pymc3 must be in a conda environment. Previously I was using pycharm and I used a virtual env (not conda environment) and I didn’t find any pip install of m2w64-toolchain.
image

Did you ever figure this out? I’m dealing with the same issue at the moment.

Finally I use Spyder and a Anaconda environment.