Search code examples
pythoninstallation

Example program of acados not running


Problem


I want test my installation of acados. However i run into a problem when running the first example to test my installation:

Running the recommended example:

$ python minimal_example_ocp.py

I get the following:

Traceback (most recent call last):
  File "minimal_example_ocp.py", line 31, in <module>
    from acados_template import AcadosOcp, AcadosOcpSolver
  File "/home/papaveneti/acados/interfaces/acados_template/acados_template/__init__.py", line 32, in <module>
    from .acados_ocp import AcadosOcp, AcadosOcpConstraints, AcadosOcpCost, AcadosOcpDims, AcadosOcpOptions
  File "<fstring>", line 1
    (self.cost.cost_type_0=)
                          ^
SyntaxError: invalid syntax

I appreciate any insight into the problem and how to fix it.

Steps i followed in the installation:


  1. I followed the steps for installation in linux with cmake, that are listed here. Built was successful with no errors

  2. Then, i wanted to build the python interface.

So first. i downloaded python 3.7 as per these instructions. That is:

sudo add-apt-repository ppa:deadsnakes/ppa -y
sudo apt update
sudo apt install python3.7
sudo apt install python3.7-full

and then i created a virtuan environment and instaled the acados_template package:

cd acados
python3.7 -m venv vEnv
source vEnv/bin/activate
pip install -e ~/acados/interfaces/acados_template
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:"$HOME/acados/lib"
export ACADOS_SOURCE_DIR="$HOME/acados"

  1. And then i try to run the example:
cd ~/acados/examples/acados_python/getting_started
python3.7 minimal_example_ocp.py # or even python minimal_example_ocp.py

Extra checks and info

With pip list -l i get the acados_template package:

acados-template   0.2.6   /home/<user>/acados/interfaces/acados_template

and python --version gives me python 3.7.17.

I have ubuntu 20.04 LTS

Line 32 from /home/papaveneti/acados/interfaces/acados_template/acados_template/__init__.py is the following:

from .acados_ocp import AcadosOcp, AcadosOcpConstraints, AcadosOcpCost, AcadosOcpDims, AcadosOcpOptions

Solution

  • Your version of Python is too old for the {foo=} syntax in that file. (That said, are you sure that's the full traceback? It looks like there may be some lines missing.)

    The = syntax for f-strings was added in Python 3.8. It's unfortunate that the documentation suggests using Python 3.7 if it doesn't work.

    You should upgrade to a supported version of Python 3.