# Problem with cython using Ubuntu 20.04

**URL:** <https://brian.discourse.group/t/problem-with-cython-using-ubuntu-20-04/580>\
**Category:** Support\
**Created:** [17 January 2022 09:51 UTC](https://brian.discourse.group/t/problem-with-cython-using-ubuntu-20-04/580 "2022-01-17T09:51:47Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![andrewl](https://avatars.discourse-cdn.com/v4/letter/a/3d9bf3/32.png) [@andrewl](https://brian.discourse.group/u/andrewl)\
**Post date:** [17 January 2022 09:51 UTC](https://brian.discourse.group/t/problem-with-cython-using-ubuntu-20-04/580/1 "2022-01-17T09:51:47Z")

</div>

# Description of problem

I am having a problem with cython on Ubuntu 20.04.3 LTS running on my laptop with the following processor: 11th Gen Intel® Core™ i7-1185G7 @ 3.00GHz × 8.

Brian2 was installed via pip in a venv virtual environment.

From the error (see below) it seems `-march=native` is not supported. And `tigerlake`, Intel’s code name for my processor, is not a valid argument to `-march` and `-mtune`.

Unfortunately I don’t know what to try next… Any help would be very much appreciated! Thanks in advance.

# Minimal code to reproduce problem

I ran this example:

> **[Example: CUBA — Brian 2 0.0.post128 documentation](https://brian2.readthedocs.io/en/stable/examples/CUBA.html)**

# What you have aready tried

First tried with default gcc-9 / g+±9.  
Updated to gcc-10 and g+±10 and set them as priority via `update-alternatives`.  
Tried setting CC=gcc and CXX=g++ in the terminal.  
Checked that CC is set to gcc-10 via `readlink -f $(which cc)`.  
Ran the brian2 test suite finding that many tests fail.

# Full traceback of error (if relevant)

```auto
WARNING Removing unsupported flag '-march=native' from compiler flags. [brian2.codegen.cpp_prefs]
cc1plus: error: bad value (‘tigerlake’) for ‘-march=’ switch
cc1plus: note: valid arguments to ‘-march=’ switch are: nocona core2 nehalem corei7 westmere sandybridge corei7-avx ivybridge core-avx-i haswell core-avx2 broadwell skylake skylake-avx512 cannonlake icelake-client icelake-server cascadelake bonnell atom silvermont slm goldmont goldmont-plus tremont knl knm x86-64 eden-x2 nano nano-1000 nano-2000 nano-3000 nano-x2 eden-x4 nano-x4 k8 k8-sse3 opteron opteron-sse3 athlon64 athlon64-sse3 athlon-fx amdfam10 barcelona bdver1 bdver2 bdver3 bdver4 znver1 znver2 btver1 btver2 native
cc1plus: error: bad value (‘tigerlake’) for ‘-mtune=’ switch
cc1plus: note: valid arguments to ‘-mtune=’ switch are: nocona core2 nehalem corei7 westmere sandybridge corei7-avx ivybridge core-avx-i haswell core-avx2 broadwell skylake skylake-avx512 cannonlake icelake-client icelake-server cascadelake bonnell atom silvermont slm goldmont goldmont-plus tremont knl knm intel x86-64 eden-x2 nano nano-1000 nano-2000 nano-3000 nano-x2 eden-x4 nano-x4 k8 k8-sse3 opteron opteron-sse3 athlon64 athlon64-sse3 athlon-fx amdfam10 barcelona bdver1 bdver2 bdver3 bdver4 znver1 znver2 btver1 btver2 generic native
/home/andrew/.cython/brian_extensions/_cython_magic_c60dbfbef46564730dc92eef23e9555e.cpp:36:10: fatal error: Python.h: No such file or directory
   36 | #include "Python.h"
      | ^ ~~~~~~~~~
compilation terminated.
WARNING Cannot use Cython, a test compilation failed: command '/usr/bin/x86_64-linux-gnu-gcc' failed with exit code 1 (CompileError)
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:
prefs.codegen.target = "numpy" [brian2.devices.device.codegen_fallback]

```

---

<div class="post-metadata">

**Author:** ![mstimberg](https://yyz2.discourse-cdn.com/free1/user_avatar/brian.discourse.group/mstimberg/32/11_2.png) [@mstimberg](https://brian.discourse.group/u/mstimberg)\
**Post date:** [17 January 2022 17:10 UTC](https://brian.discourse.group/t/problem-with-cython-using-ubuntu-20-04/580/2 "2022-01-17T17:10:10Z")

</div>

Hi @andrewl . I am a bit confused by the output. It claims that `-march=native` is not accepted, but then later says that `native` is one of the possible options for `-march` (in contrast to `tigerlake`). I suspect that there is interference with compiler options set from somewhere else. Brian itself only sets the options given in `prefs.codegen.cpp.extra_compile_args_gcc`, which should be something like `['-w', '-O3', '-ffast-math', '-fno-finite-math-only', '-march=native', '-std=c++11']`. But Python’s extension build system will also honour other flags set via environment variables. Could you have a look at the `CFLAGS` and `CXXFLAGS` environment variables, in particular whether they contain e.g. `-march=tigerlake`? It might be that unsetting these variables before running the Brian script fixes the problem.

---

<div class="post-metadata">

**Author:** ![carlo](https://avatars.discourse-cdn.com/v4/letter/c/c4cdca/32.png) [@carlo](https://brian.discourse.group/u/carlo)\
**Post date:** [19 January 2022 09:01 UTC](https://brian.discourse.group/t/problem-with-cython-using-ubuntu-20-04/580/3 "2022-01-19T09:01:27Z")

</div>

I have a similar error (Ubuntu 18.04, i5-7500). Both environment variables, `CFLAGS` and `CXXFLAGS`, are empty.

In my case the trace reads as follows:

```auto
WARNING Removing unsupported flag '-w' from compiler flags. [brian2.codegen.cpp_prefs]
WARNING Removing unsupported flag '-O3' from compiler flags. [brian2.codegen.cpp_prefs]
WARNING Removing unsupported flag '-ffast-math' from compiler flags. [brian2.codegen.cpp_prefs]
WARNING Removing unsupported flag '-fno-finite-math-only' from compiler flags. [brian2.codegen.cpp_prefs]
WARNING Removing unsupported flag '-march=native' from compiler flags. [brian2.codegen.cpp_prefs]
WARNING Removing unsupported flag '-std=c++11' from compiler flags. [brian2.codegen.cpp_prefs]
WARNING Cannot use Cython, a test compilation failed: command 'gcc' failed: No such file or directory (CompileError)
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:
prefs.codegen.target = "numpy" [brian2.devices.device.codegen_fallback]

```

---

<div class="post-metadata">

**Author:** ![mstimberg](https://yyz2.discourse-cdn.com/free1/user_avatar/brian.discourse.group/mstimberg/32/11_2.png) [@mstimberg](https://brian.discourse.group/u/mstimberg)\
**Post date:** [19 January 2022 12:00 UTC](https://brian.discourse.group/t/problem-with-cython-using-ubuntu-20-04/580/4 "2022-01-19T12:00:41Z")

</div>

Hi @carlo Your problem seems to be quite different: it says `No such file or directory` for the `gcc` command, i.e. it seems you do not have the C/C++ compiler installed. Since you are on Ubuntu, installing it via `sudo apt-get install build-essential` should work.

---

<div class="post-metadata">

**Author:** ![carlo](https://avatars.discourse-cdn.com/v4/letter/c/c4cdca/32.png) [@carlo](https://brian.discourse.group/u/carlo)\
**Post date:** [19 January 2022 12:13 UTC](https://brian.discourse.group/t/problem-with-cython-using-ubuntu-20-04/580/5 "2022-01-19T12:13:43Z")

</div>

Yes, thanks! I just installed `python3-dev` (recommended by a college) this morning and that solved it already.

Thanks for your fast reply! 🙂

---

<div class="post-metadata">

**Author:** ![mstimberg](https://yyz2.discourse-cdn.com/free1/user_avatar/brian.discourse.group/mstimberg/32/11_2.png) [@mstimberg](https://brian.discourse.group/u/mstimberg)\
**Post date:** [19 January 2022 15:09 UTC](https://brian.discourse.group/t/problem-with-cython-using-ubuntu-20-04/580/6 "2022-01-19T15:09:11Z")

</div>

Hi again @andrewl . One more useful thing to debug this issue: could you please set the environment variable `DISTUTILS_DEBUG` to 1 when running the code? This should then give more information together with the error message.

---

<div class="post-metadata">

**Author:** ![andrewl](https://avatars.discourse-cdn.com/v4/letter/a/3d9bf3/32.png) [@andrewl](https://brian.discourse.group/u/andrewl)\
**Post date:** [20 January 2022 05:56 UTC](https://brian.discourse.group/t/problem-with-cython-using-ubuntu-20-04/580/7 "2022-01-20T05:56:04Z")

</div>

Thanks @mstimberg for your help! I have it running now and will get back with more details as soon as I can.
