Manjaro: ModuleNotFoundError: No module named 'pacman_mirrors'

Daniel

February 13, 2020

Introduction

Usually I use a Debian based distribution for my Linux system such as Ubuntu, but upon seeing the increasing popularity of the Manjaro distribution, I decided to give it a try. Manjaro is based on Arch Linux. Unlike Debian which usually use APT as its package manager, Arch uses pacman as its package manager.

After installing Manjaro, I found that some updates wouldn't install due to conflicting versions, and some packages also seemed to fail to install completely. To solve this issue lets first look at what pacman can do.

pacman has various flags for package management, the most notable ones for beginners are:

  • -S --sync -installs packages from the remote repository including all dependencies.
  • -U --upgrade - upgrade or add packages to the system and install required dependencies.
  • -R --remove  - remove packages from the system.
  • -Syu - refreshes package database and updates packages with newer versions.
  • -Syy - forcefully refreshes the package database, even if they are not outdated, and no updating.
  • -Syyu - forcefully refreshes the package database and updates all packages on the system. Must do this when switching branches or mirrors.
  • -Syyuu - forcefully refresh the package database, updates all packages on the system and allow packages to be downgraded. Use when switching to an older branch.

Two good references for pacman and its use are the Manjaro pacman docs and the Arch Linux pacman docs.

Solution

After some googling why the certain packages wouldn't install, I was recommended to update the mirrors on the system.

After reading the pacman-mirror docs, I found to update my mirror-list with the fastest mirrors I should run:

sudo pacman-mirrors --fasttrack && sudo pacman -Syyu

However after running this command, I was presented with the following error:

ImportError: No module named requests

This error came from a Python Traceback. It seemed that the Python was missing the requests module.

It is preferred not to use pip when installing Python packages system-wide and rather use your package management system, in this case pacman. This is because using pip means your package management system wont know about them. This can cause dependency issues and conflicts in the future when upgrading your system.

With pacman you can install Python3 packages using:

sudo pacman -S python-'package'

or for Python2:

sudo pacman -S python2-'package'

For development always use a virtual environment. You can read about how to set up a virtual Python environment here.

To install the missing requests module I used pacman:

sudo pacman -S python-requests

Rerunning my pacman-mirror command, I still had the same error.

The next step I tried was to reinstall the pacman-mirrors package:

sudo pacman -S pacman-mirrors

Rerunning the command produced a new error:

Traceback (most recent call last):
 File "/usr/bin/pacman-mirrors", line 20, in <module></module>
   from pacman_mirrors import pacman_mirrors
ModuleNotFoundError: No module named 'pacman_mirrors

After some searching I found this occurred because none of the mirrors in my mirror-list were valid.

To update my mirror list I navigated to the Manjaro repo page which has a list of valid mirrors for every country.
Then I found the best mirror for my country and added this to my mirror-list by running:

sudo nano /etc/pacman.d/mirrorlist

At the top of the file I added:

Server = https://mirror.alpix.eu/manjaro/stable/$repo/$arch

After saving the file I ran:

sudo pacman -Syyu

as was this recommended when changing mirrors and branch to refresh the database, and suddenly had 500 updates.
I accepted the updates and everything worked well and I could install the package I originally wanted.

Finally I decided to auto generate my mirror list like I originally planned by running:

sudo pacman-mirrors --fasttrack && sudo pacman -Syyu

This generated my mirror-list using the fastest mirrors and edited the file for me.

TL;DR

If you are experiencing issues with Manjaro updates, or conflicts, check your system is up to date and your mirror-list is valid.

A list of mirrors can be found here: https://repo.manjaro.org/

Daniel

Daniel

I am a Software Engineer working as part of the nerd.vision team, mainly working on the backend systems and agents. When I'm not squashing bugs, I enjoy travelling, gaming and experiencing new foods and cultures.