How does one run mapillary_tools on Linux?

How does one run mapillary_tools on Linux?
What I’ve done is:

$ git clone GitHub - mapillary/mapillary_tools: Command line tools for processing and uploading Mapillary imagery
$ python3 mapillary_tools --help
Traceback (most recent call last):
File “/usr/lib/python3.9/runpy.py”, line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File “/usr/lib/python3.9/runpy.py”, line 87, in _run_code
exec(code, run_globals)
File “/home/fgouget/projects/mapillary_tools/mapillary_tools/main.py”, line 3, in
from . import commands, VERSION
ImportError: attempted relative import with no known parent package
$ python3 --version
Python 3.9.2

I am certainly missing something very basic. I have made various attempts with PYTHONPATH to no avail.

Use pip instead of git.

python3 -m pip install --upgrade git+https://github.com/mapillary/mapillary_tools
1 Like

That does not help : from my previous message the error happens on line 3 of mapillary_tools/main.py, way before it tries to load the dependencies installed by pip.

From what I figured out the “from .” syntax does not work anymore with Python >= 3.6. This is confirmed by tests on Debian 9 (Python 3.5.3) which gets past line 3, and Debian 11 which gives me the error I reported.

The fix is to change that from line as follows:

diff --git a/mapillary_tools/main.py b/mapillary_tools/main.py
index 9a07e0f…8ca7be2 100644
— a/mapillary_tools/main.py
+++ b/mapillary_tools/main.py
@@ -1,6 +1,6 @@
import sys
import argparse
-from . import commands, VERSION
+from mapillary_tools import commands, VERSION

def main():

Side note: pip cannot be used ‘instead of’ git: the proposed command does not check out the mapillary_tools source so it’s still necessary to then use git to check out the source.

It seems that mapillary_tools is not installed

$ git clone https://github.com/mapillary/mapillary_tools.git
$ python3 setup.py install # install it
$ python3 -m mapillary_tools --help

This error occurs when you try to import a module using a relative import, but Python cannot find the module’s parent package.

To fix this error attempted relative import with no known parent package, you need to make sure that the module being imported is part of a package, and that the package is on the Python path. You can do this by adding an empty init.py file to the package’s directory, and by making sure that the directory containing the package is on the Python path.

Alternatively, you can run the module using the -m flag with the Python interpreter, like this:

python -m mypackage.mymodule

This tells Python to run mymodule.py as a module, which will allow it to correctly resolve relative imports.

The main advantage of using relative imports is that they make it easier to move packages and modules around within a project, without having to update all the import statements. They also make it easier to reuse code across multiple projects, because the import paths can be modified to match the package hierarchy of each project.