PyMC3, Theano, PyCharm... and Big Sur

Greetings PyMC3 community. I wish my first post here would be more interesting than a plea for help, but I’m desperate. I am running the latest MacOS, Big Sur, and using the PyCharm IDE (latest version). I am currently following the examples in the Bayesian Analysis with Python book by Osvaldo Martin. I create the project in PyCharm using Conda and Python 3.8. It doesn’t appear that I have any problems importing the packages, but when I run the code I get the following error:

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})]’)

I’ve fiddled with a few things following similar problems off StackExchange but nothing seems to work. FYI I just installed the latest Xcode and have the command line tools installed. It seems to me that for some reason, the Theano package can’t get at the C language compiler on my computer but I am stumped. Anyone have advice, or run into this problem before? For what it’s worth, here’s the code I was trying to run:

import theano
import pymc3 as pm
import numpy as np
import scipy.stats as stats
import matplotlib.pyplot as plt
import seaborn as sns
palette = ‘muted’
sns.set_palette(palette); sns.set_color_codes(palette)

actual distribution

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

using PyMC3

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});
plt.show()

This seems to look like an issue @rpgoldman is having these days, so he could have pointers for you.

Also, to make sure PyCharm is not the problem, did you try opening ipython on the terminal directly and import pymc3 (with the apppropriate conda env activated of course)?
I’m asking this because I had this issue recently – PyCharm somehow was unable to find Theano but the conda env has absolutely no problems in the console or in Jupyter :man_shrugging:

According to @michaelosthege (and if I understand correctly), the reason that conda works better is that it has its own compiler configuration.

I am not by any stretch of the imagination a C++ programmer, but my reading around suggests that problems are occurring because Apple has disabled access to /usr/include. The C++ compilers are mostly configured to handle this correctly, but apparently the code that provides the glue from Python to C++ (and perhaps C?) does not.

I’m not entirely sure what to do about this: I have read a great deal of conflicting advice. There are various environment variables that might help, but don’t necessarily work reliably. I don’t have the knowledge (or, frankly, the interest) to wade into understanding the layers that lie between my environment and the environment that a compiler, running inside pip, sees.

I wish I had a more satisfying answer.

This sounds like a bug, though, and one worth filing with Theano-PyMC. @kostoffj What theano are you using? I was able to get PyMC3 to work (I think) with Catalina, but don’t use Big Sur.

@rpgoldman and @AlexAndorra, thanks for the responses. Sorry have not been prompt with the reply thanks to the holiday, but in the next day or two I am going to first test it in ipython and then see where we go from there. After some further reading, this might well be an issue with Apple’s “System Integrity Protection” and hiding certain folders. Apparently you can just turn it off, which might solve the problem outright. I will test it and see, and report back what I find.

Happy New Year to you all!

yes, I tried importing pymc3 in ipython and got the same error message I posted above.

Tested out the idea that Apple System Integrity Protection was the culprit by disabling it and attempting to then run my python script with it turned off. No joy, get the same error message as before. FWIW the version of Theano I am using is 1.0.4. which I believe is current. Will file this as a bug with Theano-PyMC.

Just an update: it seems there is something wrong with my Anaconda installation (and upgrading it didn’t fix it), I installed pymc3 in my system python and not the anaconda one and it worked, or at least didn’t throw the errors I described above. I now have a different error, but I vaguely remember this one from prior to Big Sur, python choked on multiprocessing, e.g.> RuntimeError:

    An attempt has been made to start a new process before the
    current process has finished its bootstrapping phase.

    This probably means that you are not using fork to start your
    child processes and you have forgotten to use the proper idiom
    in the main module:

        if __name__ == '__main__':
            freeze_support()
            ...

    The "freeze_support()" line can be omitted if the program
    is not going to be frozen to produce an executable.