<p>Repo还没有完全支持Python 3。已经做了一些工作,例如<a href="https://gerrit.googlesource.com/git-repo/+/cecd1d864fc3cf02cf50d367111e0d0e173c5dc6" rel="noreferrer">using the ^{<cd1>} function</a>和<a href="https://gerrit.googlesource.com/git-repo/+/1f7627fd3ccab0fbab88ad2d082b67f5719af92c" rel="noreferrer">importing the correct urllib</a>,但这项工作似乎还没有完成。</p>
<p>现在,您需要将它与Python 2一起使用。您可以用<code>python2</code>替换<code>python</code>来编辑<code>repo</code>可执行文件顶部的shebang,也可以运行:</p>
<pre><code>python2 `which repo`
</code></pre>
<p>假设您的路径中安装了Python 2的版本<code>python2</code>。</p>
<p>您可以很容易地重现问题:</p>
<pre><code>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
</code></pre>
<p>下面是<code>_CheckGitVersion()</code>的相关代码:</p>
<pre><code>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 '):
</code></pre>
<p><code>read</code>调用的<code>stdout</code>返回<code>bytes</code>,因此传递给<code>startswith</code>的内容也必须是<code>bytes</code>(原始数据字节),而不是<code>str</code>(Unicode代码点序列)。</p>