Linux install problems: sudo vs pip, snap, and apt out-of-date

I’m trying to get Anki running on Ubuntu 20.04, and running into issues with every method I’ve tried.

apt, snap

I prefer to install via apt or snap since they automatically keep up-to-date with security issues, but the versions there are far out-of-date, so the volunteers managing those have not kept up. Yeah, I know, it’s a challenge!

i.e., apt has 2.1.15+dfsg-1

snap says version 2.1.35 will be the last stable version for snap, as the upstream was sometimes changing the whole build system to use Bazel)

pip

I tried pip install anki (using Python 3.8.10 and pip 22.1.2), but had several questions about that. It is pulling 2.1.49 rather than the latest (and pypi even advertises 2.1.54 which is the latest now it seems).
It also had failures along the way:

...
Building wheels for collected packages: stringcase
  Building wheel for stringcase (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: /home/neal/Envs/anki/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-_jin2wk_/stringcase/setup.py'"'"'; __file__='"'"'/tmp
/pip-install-_jin2wk_/stringcase/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(c
ode, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-7f69ige6
       cwd: /tmp/pip-install-_jin2wk_/stringcase/
  Complete output (6 lines):
  usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
     or: setup.py --help [cmd1 cmd2 ...]
     or: setup.py --help-commands
     or: setup.py cmd --help
  
  error: invalid command 'bdist_wheel'
  ----------------------------------------
  ERROR: Failed building wheel for stringcase
  Running setup.py clean for stringcase
Failed to build stringcase
Installing collected packages: protobuf, stringcase, decorator, idna, charset-normalizer, urllib3, certifi, PySocks, requests, distro, orjson, soupsieve, beautifulsoup4, zipp,
 importlib-metadata, markdown, anki
    Running setup.py install for stringcase ... done
Successfully installed PySocks-1.7.1 anki-2.1.49 beautifulsoup4-4.11.1 certifi-2022.6.15 charset-normalizer-2.0.12 decorator-5.1.1 distro-1.7.0 idna-3.3 importlib-metadata-4.1
2.0 markdown-3.3.7 orjson-3.7.5 protobuf-4.21.2 requests-2.28.0 soupsieve-2.3.2.post1 stringcase-1.2.0 urllib3-1.26.9 zipp-3.8.0

So it seems like it worked at the end, for the older version at least, but I end up with no anki command.

Linux binary

I tried downloading the .zst file from apps dot ankiweb dot net which is up-to-date, but it wants me to run sudo install. Given generic advice about the insecurity of that, as well as all the the other packaging issues, I really don’t like that idea, at least without some compelling confidence-building explanations of how it is safe in this case. I fear both the basic insecurity of being asked to install via sudo, and I don’t want anki to screw around with my Python libraries or other system files.

I wish you would modify the binary install so it doesn’t need sudo, or at least clarify why you’ve chosen not to.

Fixing the pip install seems best offhand. Who can help with either the version issue or the missing anki command?

Thanks!

Apt / snap

Ubuntu’s / Debian’s repository (ie. where apt fetches packages) have no up-to-date versions of Anki, so installing with apt is impossible.

On the other hand, snap has more recent version (2.1.49, while the current stable is 2.1.53 I think), but it is named anki-ppd. That package used to keep up with Anki’s pace since 2.1.49, but now it hasn’t updated for a few weeks. I don’t know if the maintainer is just slow (maybe they went on holiday or something), or if they just dropped support.

Pip

pip is not a package manager, and even though some people may like it for managing Python dependencies, as a package manager it is inferior to snap or apt. I would not recommend installing via pip unless everything else fails.

Linux binary

This is exactly why you would use a package manager in the first place, however when you decide to install a package by hand, you are forced do some system administration (which requires doing them as root) yourself, hence the sudo. In this case, you should not really worry about it as I assume Anki’s installer knows what it does. In general, when you install packages, there are two ways to install them: either system-wide, or only for yourself. If you do a system-wide installation, you’ll always need to do it as root, and since most installer’s only available method of installation is system-wide, there is no real way around sudo. This is done because usually it is expected that packages are managed system-wide. Installing packages only for a user is, I would say, a more advanced Linux operation.

Other solutions

Turns out there are other package managers that are distribution-agnostic, besides snap, which do package the latest version of Anki. I can think of two: flatpak and nix (beware that NixOS is a Linux distribution based on nix; the package manager is called just nix). Currently flatpak has packaged version 2.1.54, while nix has packaged 2.1.52 (under the name anki-bin), but in general nix and flatpak update their Anki package approximately at the same pace, and they are both actively maintained.

If you don’t know them but still would like to give either a try, the main difference between them is that flatpak is the more popular choice, and it’s also easier to use. Flatpak is very similar in usage to apt or snap. Nix, on the other hand, has considerably more advanced features, but is also harder to use and has poor documentation. It is quite different from the other mentioned package managers since you usually don’t install packages with a command such as package-manager install the-package, but it is possible to do so.

2 Likes

The pip install failed because recent versions require Python 3.9.

As is mentioned in the README file, you can run Anki directly from the folder you untarred it into - sudo is only required to install it in a system location.

4 Likes

Thank you for a quick response! Your insights around flatpak and nix are very helpful, and I suggest adding them to the download/install page for Anki.

I’ll note for the record that pip has advantages for managing package installation over apt and snap, in that you can indeed do an install only for a single user, and avoid use of root or messing up the system. That is actually now the default. Of course, these days, most LInux systems are single-user. It is also nice to also be able to install to a virtualenv so you can easily switch between versions or avoid dependency conflicts between python libraries. I wonder if there is a way to clearly explain or signal on pip install that 3.9 is required.

I’ll also push back on the notion that users should assume they can trust the developers of every application they use with sudo power on install. Today the threat from supply chain attacks and third-party software, even when it is open source, is long since out of control. I suspect it is often better to use the ability to run straight out of git as kindly pointed out by @dae, rather than do a sudo install, but a package install from the repositories you suggest is generally more appropriate than either of those.

FWIW, I’d suggest that Anki would also benefit (now or soon) from exploring the use of emerging code-signing tools like sigstore-python (github/sigstore/sigstore-python) as explained by Dustin Ingram at Securing the Open Source Software Supply Chain on Youtube. (Search for it since I can’t include a nice link yet.)