Skip to content

Python coin tutorial does not run (install problem?) #13

@ronquist

Description

@ronquist

After creating a virtual environment and then installing the treeppl python package according to instructions on my MacBook Pro M2 (arm), I get the following error when I try the coin flipping tutorial:

>>> coin = treeppl.Model(filename="../treeppl-fork/models/lang/coin.tppl")
Traceback (most recent call last):
  File "<python-input-2>", line 1, in <module>
    coin = treeppl.Model(filename="../treeppl-fork/models/lang/coin.tppl")
  File "/Users/ronquist/dev/treeppl-python/env/lib/python3.14/site-packages/treeppl/base.py", line 66, in __init__
    get_tpplc_binary(),
    ~~~~~~~~~~~~~~~~^^
  File "/Users/ronquist/dev/treeppl-python/env/lib/python3.14/site-packages/treeppl/base.py", line 43, in get_tpplc_binary
    with importlib.resources.path('treeppl', tarball_name) as tarball:
         ^^^^^^^^^^^^^^^^^^^
AttributeError: module 'importlib' has no attribute 'resources'

The error message is similar if I try to compile from a text string describing the coin flipping model.

After locating the base.py file and adding the line import importlib.resources after the line import importlib, as suggested by Viktor P, and retrying the coin flipping example I get a different error:

>>> coin_source = """\
... model function coin(outcomes: Bool[]) => Real {
...   assume p ~ Beta(2.0, 2.0);
...   for i in 1 to (length(outcomes)) {
...     observe outcomes[i] ~ Bernoulli(p);
...   }
...   return(p);
... }
... """
>>> coin = treeppl.Model(source=coin_source)
Traceback (most recent call last):
  File "<python-input-2>", line 1, in <module>
    coin = treeppl.Model(source=coin_source)
  File "/Users/ronquist/dev/treeppl-python/env/lib/python3.14/site-packages/treeppl/base.py", line 82, in __init__
    with Popen(
         ~~~~~^
        args=args, cwd=self.temp_dir.name, stdout=PIPE, stderr=STDOUT
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ) as proc:
    ^
  File "/opt/homebrew/Cellar/python@3.14/3.14.2/Frameworks/Python.framework/Versions/3.14/lib/python3.14/subprocess.py", line 1038, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
    ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                        pass_fds, cwd, env,
                        ^^^^^^^^^^^^^^^^^^^
    ...<5 lines>...
                        gid, gids, uid, umask,
                        ^^^^^^^^^^^^^^^^^^^^^^
                        start_new_session, process_group)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.14/3.14.2/Frameworks/Python.framework/Versions/3.14/lib/python3.14/subprocess.py", line 1989, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/treeppl-0.2/tpplc'
```

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions