Cython with python3

Hi,

I’m new to acados and I’m trying to run the code example cython_example_closed_loop.py but I’m encountering this error,

I’m using the command python3 cython_example_closed_loop.py
for python 3.8
I guess it calls cython from python2.7
other than cython examples, every example runs smooth.

Traceback (most recent call last):
File “/usr/bin/cython”, line 8, in
main(command_line = 1)
File “/usr/lib/python2.7/dist-packages/Cython/Compiler/Main.py”, line 720, in main
result = compile(sources, options)
File “/usr/lib/python2.7/dist-packages/Cython/Compiler/Main.py”, line 695, in compile
return compile_multiple(source, options)
File “/usr/lib/python2.7/dist-packages/Cython/Compiler/Main.py”, line 673, in compile_multiple
result = run_pipeline(source, options, context=context)
File “/usr/lib/python2.7/dist-packages/Cython/Compiler/Main.py”, line 494, in run_pipeline
err, enddata = Pipeline.run_pipeline(pipeline, source)
File “/usr/lib/python2.7/dist-packages/Cython/Compiler/Pipeline.py”, line 341, in run_pipeline
data = phase(data)
File “/usr/lib/python2.7/dist-packages/Cython/Compiler/Pipeline.py”, line 35, in parse
tree = context.parse(source_desc, scope, pxd = 0, full_module_name = full_module_name)
File “/usr/lib/python2.7/dist-packages/Cython/Compiler/Main.py”, line 349, in parse
with Utils.open_source_file(source_filename) as f:
File “/usr/lib/python2.7/dist-packages/Cython/Utils.py”, line 306, in open_source_file
encoding=encoding, errors=error_handling)
LookupError: unknown encoding: future_fstrings
Makefile:131: recipe for target ‘ocp_cython_c’ failed
make: *** [ocp_cython_c] Error 1
Traceback (most recent call last):
File “cython_example_closed_loop.py”, line 145, in
main()
File “cython_example_closed_loop.py”, line 114, in main
acados_ocp_solver = AcadosOcpSolver.create_cython_solver(solver_json)
File “/home/rahmani/acados/interfaces/acados_template/acados_template/acados_ocp_solver.py”, line 393, in create_cython_solver
acados_ocp_solver_pyx = importlib.import_module(f’{os.path.split(code_export_directory)[1]}.acados_ocp_solver_pyx’)
File “/usr/lib/python3.8/importlib/init.py”, line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File “”, line 1014, in _gcd_import
File “”, line 991, in _find_and_load
File “”, line 973, in _find_and_load_unlocked
ModuleNotFoundError: No module named ‘c_generated_code.acados_ocp_solver_pyx’

again no acados_ocp_solver_pyx is generated in c_generated_code
since the build was unsuccessful

Solution:

So after hours of searching and testing, I solved the problem by going to
usr/bin and searched for cython file, in the file I changed the first line from
#!/usr/bin/python to #!/usr/bin/python3
then I faced another error.
fatal error: Python.h: No such file or directory
#include “Python.h”
^~~~~~~~~~

The problem was that in usr/include didn’t had python3.8 in it so I removed python3.8.16 and reinstalled python 3.8.0
and it worked like a charm in my example

cheers