python from sync import Sync giving script error ModuleNotFoundError: No module named 'sync'

946 Views Asked by At

I am attempting to do my own build of Android for the DragonBoard 410c using the materials from Qualcomm under Ubuntu 20. I have downloaded from the Qualcomm developer portal the file, linux_android_board_support_package_vla.br_.1.2.7-01010-8x16.0-4.zip, containing the materials which I have unzipped into a folder ~/Documents/linux_android_board_support_package_vla.br.1.2.7-01010-8x16.0-4 making the materials available include the shell script DB410c_build.sh.

The unpacking and setup is done by DB410c_build.sh which performs the various actions such as generating the .repo directory tree with the python files that are used by the shell script and downloading the source.

I have run into a number of syntax errors from the various python scripts, it appears this was written for python 2, that I have been able to address thus far. By the way, python --version reports python 2.7.18 yet I still see errors indicating python 3 is being used.

The latest error comes from the python script, .repo/repo/subcmds/smartsync.py and when it executes, I get the following error that I have been unable to figure out or find a solution through searches.

Traceback (most recent call last):
  File "/home/rick/Documents/linux_android_board_support_package_vla.br.1.2.7-01010-8x16.0-4/APQ8016_410C_LA.BR.1.2.7-01010-8x16.0_6.0.1_Marsh_Mallo_P2/.repo/repo/main.py", line 42, in <module>
    from subcmds import all as all_commands
  File "/home/rick/Documents/linux_android_board_support_package_vla.br.1.2.7-01010-8x16.0-4/APQ8016_410C_LA.BR.1.2.7-01010-8x16.0_6.0.1_Marsh_Mallo_P2/.repo/repo/subcmds/__init__.py", line 33, in <module>
    mod = __import__(__name__,
  File "/home/rick/Documents/linux_android_board_support_package_vla.br.1.2.7-01010-8x16.0-4/APQ8016_410C_LA.BR.1.2.7-01010-8x16.0_6.0.1_Marsh_Mallo_P2/.repo/repo/subcmds/smartsync.py", line 16, in <module>
    from sync import Sync
ModuleNotFoundError: No module named 'sync'

The complete python source file, smartsync.py is as follows:

#
# Copyright (C) 2010 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from sync import Sync

class Smartsync(Sync):
  common = True
  helpSummary = "Update working tree to the latest known good revision"
  helpUsage = """
%prog [<project>...]
"""
  helpDescription = """
The '%prog' command is a shortcut for sync -s.
"""

  def _Options(self, p):
    Sync._Options(self, p, show_smart=False)

  def Execute(self, opt, args):
    opt.smart_sync = True
    Sync.Execute(self, opt, args)

This just the latest issue with the python scripts from this file downloaded from https://developer.qualcomm.com/hardware/dragonboard-410c/software attempting to use

Android Board Support Package 
vLA.BR.1.2.7-01010-8x16.0-4

Most of the previous errors have been due to incorrect syntax with except and raise as well as print along with a couple of import errors that were easy to find solutions for (Thank you StackOverFlow!).

However I can't find anything about this one.

1

There are 1 best solutions below

0
On BEST ANSWER

The problem was due to a syntax error in the file smartsync.py located in the folder .repo/repo/subcmds and the from sync import Sync statement in that file.

The sync is actually referencing the file sync.py which is also located in the folder .repo/repo/subcmds and not some python file external to this body of python source code.

The from statement was missing the directory specifier of subcmds where the file sync.py is located. The line of code should have been written from subcmds.sync import Sync in order to import the class Sync from the file sync.py located in the folder subcmds. I assume this is because the python script is being run with the current directory set to .repo/repo and not .repo/repo/subcmds.

After this change was made to the file, the script ran successfully until the next error in a different file which needed to be corrected.