TypeError when trying to “repo init” on Python 3.3

给你一囗甜甜゛ 提交于 2021-01-27 05:52:48

问题


I have Arch Linux Python 3.3.0 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://new.username@128.224.0.74:29418/stelvio/mm
![remote rejected] branchname -> refs/for/main_dev (you are not committer  oldusername@email.com)
 error: failed to push some refs to 'ssh://new.username@128.224.0.74:29418/project/one'

回答1:


Repo does not yet fully support Python 3. Some work has been done, such as using the print function and importing the correct urllib, but that work doesn't appear to have been finished.

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 python with python2 or you could run:

python2 `which repo`

assuming you have a version of Python 2 installed in your path as python2.

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 _CheckGitVersion():

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 '):

reading the 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).




回答2:


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

#!/usr/bin/env python

to

#!/usr/bin/env python2

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).




回答3:


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!



来源:https://stackoverflow.com/questions/15913868/typeerror-when-trying-to-repo-init-on-python-3-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!