"Unable to correct problems, you have held broken packages."

This error happens whenever I try to build anything… I have no idea of what’s happening.

Traceback (most recent call last):
  File "/snap/snapcraft/1177/bin/snapcraft", line 11, in <module>
    load_entry_point('snapcraft==2.39.2', 'console_scripts', 'snapcraft')()
  File "/snap/snapcraft/1177/usr/lib/python3.6/site-packages/pkg_resources/__init__.py", line 565, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/snap/snapcraft/1177/usr/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2631, in load_entry_point
    return ep.load()
  File "/snap/snapcraft/1177/usr/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2291, in load
    return self.resolve()
  File "/snap/snapcraft/1177/usr/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2297, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "/snap/snapcraft/1177/lib/python3.6/site-packages/snapcraft/cli/__main__.py", line 43, in <module>
  File "/snap/snapcraft/1177/lib/python3.6/site-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/snap/snapcraft/1177/lib/python3.6/site-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/snap/snapcraft/1177/lib/python3.6/site-packages/click/core.py", line 1043, in invoke
    return Command.invoke(self, ctx)
  File "/snap/snapcraft/1177/lib/python3.6/site-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/snap/snapcraft/1177/lib/python3.6/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/snap/snapcraft/1177/lib/python3.6/site-packages/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/snap/snapcraft/1177/lib/python3.6/site-packages/snapcraft/cli/_runner.py", line 72, in run
  File "/snap/snapcraft/1177/lib/python3.6/site-packages/click/core.py", line 553, in forward
    return self.invoke(cmd, **kwargs)
  File "/snap/snapcraft/1177/lib/python3.6/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/snap/snapcraft/1177/lib/python3.6/site-packages/snapcraft/cli/lifecycle.py", line 139, in snap
    project_options, directory=directory, output=output)
  File "/snap/snapcraft/1177/lib/python3.6/site-packages/snapcraft/internal/lifecycle/_packer.py", line 46, in snap
    execute('prime', project_options)
  File "/snap/snapcraft/1177/lib/python3.6/site-packages/snapcraft/internal/lifecycle/_runner.py", line 79, in execute
    _Executor(config, project_options).run(step, part_names)
  File "/snap/snapcraft/1177/lib/python3.6/site-packages/snapcraft/internal/lifecycle/_runner.py", line 185, in run
    self._run_step(step, part, part_names)
  File "/snap/snapcraft/1177/lib/python3.6/site-packages/snapcraft/internal/lifecycle/_runner.py", line 215, in _run_step
    getattr(part, 'prepare_{}'.format(step))()
  File "/snap/snapcraft/1177/lib/python3.6/site-packages/snapcraft/internal/pluginhandler/__init__.py", line 268, in prepare_pull
  File "/snap/snapcraft/1177/lib/python3.6/site-packages/snapcraft/internal/pluginhandler/__init__.py", line 254, in _fetch_stage_packages
  File "/snap/snapcraft/1177/lib/python3.6/site-packages/snapcraft/internal/repo/_deb.py", line 312, in get
    self._mark_install(apt_cache, package_names)
  File "/snap/snapcraft/1177/lib/python3.6/site-packages/snapcraft/internal/repo/_deb.py", line 229, in _mark_install
  File "/snap/snapcraft/1177/lib/python3.6/site-packages/apt/package.py", line 1309, in mark_install
SystemError: E:Unable to correct problems, you have held broken packages.

You’re trying to add build-packages which conflict with packages that are already on the system. This is often due to building either in the host system, or in a persistent LXD container, where you’ve:

  1. added packages to build-packages
  2. tried building
  3. removed a package and added a conflicting package to the list
  4. tried building again, hitting the error

Removing a package from build-packages does not remove it from a persistent system which is why we recommend using snapcraft cleanbuild where possible, because it uses a new empty LXD container for every build.

Alright, thank you.

(I seem to have accidentally fixed this by running sudo apt autoremove as well, but oh well…)

That’s the correct fix actually, for building in the host environment. Snapcraft installs all dependencies as “automatically installed” so that you can clean them up easily.

But it should certainly be more helpful here in explaining that. I’ll look into a proper error message for this case.

Looks like autoremove doesn’t always fix it either… Just had it happen to me right after an autoremove.

Can you provide more details? With what packages did and didn’t it work?

I have no idea, the only details on the failure I get in the logs is what I have already posted… Somehow restarting the PC seems to fix things. This issue seems to be quite random.