PyMC3 无法在 MacOS Big Sur/ PyCharm 上执行

问题描述

我试图在 MacOS Big Sur 上的 PyCharm 中运行一些简单的 PyMC3 代码,但执行失败并抛出以下错误

Exception: ('Compilation Failed (return status=1): ld: library not found for -lSystem. clang-10: error: linker command Failed with exit code 1 (use -v to see invocation). ','[Elemwise{add,no_inplace}(TensorConstant{1.0},TensorConstant{1.0})]')

我使用的是 PyCharm 2020.3.2。我可以将 pymc3(3.8 版)和 theano(1.0.4)安装到环境中。我试图运行的代码如下:

import numpy as np
import scipy.stats as stats
import matplotlib.pyplot as plt
import pymc3 as pm

np.random.seed(123)
n_experiments = 4
theta_real = 0.35
data = stats.bernoulli.rvs(p=theta_real,size=n_experiments)

with pm.Model() as our_first_model:
    theta = pm.Beta('theta',alpha=1,beta=1)
    y = pm.Bernoulli('y',p=theta,observed=data)
    start = pm.find_MAP()
    step = pm.Metropolis()
    trace = pm.sample(1000,step=step,start=start)
    burnin = 100
    chain = trace[burnin:]
    pm.traceplot(chain,lines={'theta':theta_real});

我禁用了 Apple 系统完整性保护,因为有人猜测 Apple 隐藏了 /usr/include 可能是问题的根源;它没有任何区别。不知道如何解决这个问题。

解决方法

从评论中的信息来看,你的蟒蛇似乎坏了。 更新 anaconda 并重试。

如果这不起作用,请尝试在系统 Python 中安装 PyMC3,而不是 Anaconda。 这将使用系统 clang 而不是 Anaconda clang