TypeError when trying to “repo init” on Python 3.3
I have Arch Linux
I’ve downloaded the latest repo, and if i try to do the repo init from the Google example, i get this error:
[username@otp-username-l2 teste]$ repo init -u https://android.googlesource.com/platform/manifest Traceback (most recent call last): File "/home/username/bin/repo", line 738, in <module> main(sys.argv[1:]) File "/home/username/bin/repo", line 705, in main _Init(args) File "/home/username/bin/repo", line 234, in _Init _CheckGitVersion() File "/home/username/bin/repo", line 274, in _CheckGitVersion if not ver_str.startswith('git version '): TypeError: startswith first arg must be bytes or a tuple of bytes, not str
The reason for which i am forced to do a new repo init is that i must do a commit from an already initialized repo, but i’ve changed the git user from everywhere, and i still get this:
Writing objects: 100% (12/12), 966 bytes, done. Total 12 (delta 11), reused 0 (delta 0) o ssh://firstname.lastname@example.org:29418/stelvio/mm ![remote rejected] branchname -> refs/for/main_dev (you are not committer email@example.com) error: failed to push some refs to 'ssh://firstname.lastname@example.org:29418/project/one'
3 Solutions collect form web for “TypeError when trying to “repo init” on Python 3.3”
Repo does not yet fully support Python 3. Some work has been done, such as using the
For now, you’ll need to use it with Python 2. You could edit the shebang at the top of the
repo executable by replacing
python2 or you could run:
python2 `which repo`
assuming you have a version of Python 2 installed in your path as
You can easily reproduce the problem:
Python 3.2.3 (default, Nov 7 2012, 19:36:04) [GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> b'asd'.startswith('asd') Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: startswith first arg must be bytes or a tuple of bytes, not str
And here is the relevent code of
def _CheckGitVersion(): cmd = [GIT, '--version'] try: proc = subprocess.Popen(cmd, stdout=subprocess.PIPE) ... ver_str = proc.stdout.read().strip() proc.stdout.close() proc.wait() if not ver_str.startswith('git version '):
stdout of the
Popen call returns
bytes, and so what is passed to
startswith has to also be
bytes (raw bytes of data) rather than
str (a sequence of Unicode code points).
I ran into the same problem, agf’s solutions made the repo-script work, but it still exited stating that it won’t work with python 3:
error: Python 3 support is not fully implemented in repo yet.
Please use Python 2.6 – 2.7 instead.
The (admittedly rather dirty) way around this for me was to change the symlink for the python bin from python3 to python2.
Remember to revert this once you’re done!
Just stumbled upon this error while trying to revive my P990.
The first fix is to modify the repo command (in ~/bin in your case, otherwise check which repo to find where it is) and change the first line from
This allows you to repo init, but you will run into the message klauspeter mentioned:
error: Python 3 support is not fully implemented in repo yet. Please use Python 2.6 - 2.7 instead.
I wouldn’t recommend changing the system-wide symlink. Instead, navigate into the newly created .repo folder.
If you started repo init in $basedir, you want to check $basedir/.repo/repo. Inside you’ll find a local repo installation, again having a shebang with plain ‘python’ (we want python2).
So edit all files containing that line (main.py, repo and wrapper.py) according to the first steps above and you’re good to go. For me repo now even asked me to update my global installation (that is, copying $basedir/.repo/repo/repo to ~/bin), which you’re free to do (that version is ‘fixed’ now).