Cannot Use Cython

Hi, I am a beginner with python and installed the Brian Library.
I compiled the test code but it had a many Fails.
And if I compiled the Example code, there was Warning that Cannnot use Cython, a test compilation failed.
How can i fix this problem
Thank you

WARNING Cannot use Cython, a test compilation failed: command ‘/Users/imhyeonseong/opt/anaconda3/bin/x86_64-apple-darwin13.4.0-clang++’ failed with exit code 1 (LinkError)
Certain compiler configurations (e.g. clang in a conda environment on OS X) are known to be problematic. Note that you can switch the compiler by setting the ‘CC’ and ‘CXX’ environment variables. For example, you may want to try ‘CC=gcc’ and ‘CXX=g++’. [brian2.codegen.runtime.cython_rt.cython_rt.failed_compile_test]
INFO Cannot use compiled code, falling back to the numpy code generation target. Note that this will likely be slower than using compiled code. Set the code generation to numpy manually to avoid this message: = “numpy” [brian2.devices.device.codegen_fallback]

packages in environment at /Users/imhyeonseong/opt/anaconda3:

Name Version Build Channel

brian2 2.5.1.post0.dev86 pypi_0 pypi
brian2tools 0.3 py_0 brian-team

Running tests for target cython:




243 failed, 26 passed, 9 skipped, 426 deselected in 739.86s (0:12:19)

ERROR: 1/4 test suite(s) did not complete successfully (see above).


Hi @ImHS . Not having a working Cython isn’t a big problem, it will only make your simulations a bit slower. As the log message says, you can disable it manually to avoid the error: = “numpy” 

While this will lead to slightly slower simulations, it has the advantage that it does not need to compile code first, i.e. the time until the actual simulation starts is shorter. Especially for simpler simulations, or during development where you change/re-run simulations very often, this can actually be faster in total.

For fixing the issue with Cython, did you try what the info message suggested? You seem to be in the exact situation it mentions (conda on OS X):

Also see this discussion thread: Problem with Cython - #21 by Tioz90

1 Like

I tried ‘CC=gcc’ and ‘CXX=g++’ and problem is solved!

Is there any way to maintain this setting permanently?

I have to do this every time that I run terminal again

Thank you for detail answer

1 Like

Hi @ImHS. Glad it worked out! There are several ways to set environment variables permanently. You can set them globally it in your “bash profile” file(see e.g. How to Set Environment Variables in MacOS | phoenixNAP KB), but I wouldn’t necessarily recommend it since it could break other programs and can potentially lead to issues that are hard to debug.
Another solution would be to set these variables only for the conda environment, as described by @adam here: How to override CXX enviroment variables set by · GitHub Note that in your case, I don’t think you are using a dedicated environment, so you should apply the instructions to the base environment. The instructions also set CLANG and CLANGXX, but this turned out not to be necessary, setting CC and CXX is enough.

Finally, you can also set environment variables directly in a Python script by using something like this:

import os
os.environ['CC'] = 'gcc'
os.environ['CXX'] = 'g++'
1 Like