尝试" repo init"时出现TypeError在Python 3.3上

时间:2013-04-09 22:45:07

标签: python git python-3.x repository

我有Arch Linux Python 3.3.0 我已经下载了最新的repo,如果我尝试从Google示例中执行repo init,我会收到此错误:

 [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

我被迫做一个新的repo init的原因是我必须从已经初始化的repo做一个提交,但我已经从任何地方改变了git用户,我仍然得到这个:

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'

3 个答案:

答案 0 :(得分:5)

Repo尚未完全支持Python 3.已经完成了一些工作,例如using the print functionimporting the correct urllib,但这项工作似乎没有完成。

目前,您需要在Python 2中使用它。您可以通过将repo替换为python来编辑python2可执行文件顶部的shebang,或者您可以运行:

python2 `which repo`

假设您的路径中安装了Python 2版本python2

您可以轻松地重现问题:

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

以下是_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 '):

read stdout来电Popen来电回复bytes,因此传递给startswith的内容也必须bytes (原始数据字节)而不是str(Unicode代码点序列)。

答案 1 :(得分:4)

在尝试恢复我的P990时偶然发现了这个错误。

第一个修复是修改repo命令(在你的情况下在〜/ bin中,否则检查哪个repo找到它的位置)并改变第一行

#!/usr/bin/env python

#!/usr/bin/env python2

这允许你repo init,但是你会遇到klauspeter提到的消息:

error: Python 3 support is not fully implemented in repo yet.
Please use Python 2.6 - 2.7 instead.

我不建议更改系统范围的符号链接。而是导航到新创建的.repo文件夹。

如果您在$ basedir中启动了repo init,则需要检查$ basedir / .repo / repo。在里面你会找到一个本地的repo安装,再次有一个带有普通'python'的shebang(我们想要python2)。

根据上面的第一步,编辑包含该行的所有文件( main.py,repo和wrapper.py ),你就可以了。对我来说repo现在甚至要求我更新我的全局安装(即将$ basedir / .repo / repo / repo复制到〜/ bin),你可以自由地做(这个版本现在是'修复')。 / p>

答案 2 :(得分:1)

我遇到了同样的问题,agf的解决方案使repo-script工作,但它仍然表示它不能用于python 3:

  

错误:尚未在repo中完全实现Python 3支持。
  请改用Python 2.6 - 2.7。

对我来说,这是一种(当然相当肮脏)的方法是将python bin的符号链接从python3更改为python2。

请记住,一旦完成,请将其还原!