Python 2语法错误在Python 3环境中使用ape工具中发生。

huangapple go评论74阅读模式
英文:

Python 2 Syntax Error Encountered in Python 3 Environment with ape Tool

问题

我在Python 3.9.17中使用eth-ape工具遇到了问题。

你好,我目前在Python 3.9.17中使用eth-ape工具遇到了问题。虽然我已经成功安装了它,但我遇到了与'print'语句相关的语法错误,这通常与Python 2的语法相关。以下是我收到的错误消息:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.10/bin/ape", line 6, in <module>
    from ape.main import main
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/ape/__init__.py", line 109
    print inspect.getdoc(self._tasks)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)?

我对为什么会出现这个问题感到困惑,因为我正在使用Python 3来运行eth-ape。以下是我使用的Python版本:

python --version
Python 3.9.17

我已经确认eth-ape已安装在我的Python 3环境中:

python3 -m pip install eth-ape
Requirement already satisfied: ape in ./env/lib/python3.9/site-packages (0.4.0)
Requirement already satisfied: featuremonkey>=0.2.2 in ./env/lib/python3.9/site-packages (from ape) (0.3.1)

以下是我的deloy.py代码:

from brownie import accounts

def deploy_simple_storage():
    account = accounts[0]
    print(account)

def main():
    deploy_simple_storage()

请问有人可以帮助我找到解决这个问题的方法吗?我将非常感激提供的任何建议或指导。在此先提前表示感谢!

英文:

I'm encountering an issue with the eth-ape tool in Python 3.9.17.

Hello, I am currently facing a problem with the eth-ape tool in Python 3.9.17. Although I have installed it successfully, I am encountering a syntax error related to the 'print' statement, which is commonly associated with Python 2 syntax. Here is the error message I received:

Traceback (most recent call last):
  File &quot;/Library/Frameworks/Python.framework/Versions/3.10/bin/ape&quot;, line 6, in &lt;module&gt;
    from ape.main import main
  File &quot;/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/ape/__init__.py&quot;, line 109
    print inspect.getdoc(self._tasks)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: Missing parentheses in call to &#39;print&#39;. Did you mean print(...)?

I am confused about why this issue is happening since I am using Python 3 to run eth-ape. Here is the version of Python I am using:

python --version
Python 3.9.17

And I have confirmed that eth-ape is installed in my Python 3 environment:

python3 -m pip install eth-ape
Requirement already satisfied: ape in ./env/lib/python3.9/site-packages (0.4.0)
Requirement already satisfied: featuremonkey&gt;=0.2.2 in ./env/lib/python3.9/site-packages (from ape) (0.3.1)

below is my deloy.py code:

from brownie import accounts


def deploy_simple_storage():
    account = accounts[0]
    print(account)


def main():
    deploy_simple_storage()

Can someone please help me find a solution to this problem? I would greatly appreciate any suggestions or guidance provided. Thank you in advance!

答案1

得分: 2

没有版本的 ape 支持过 Python 3。它也是一个已经停止维护的项目,最后一次发布是在2014年,仓库最后一次活动是在2017年,所以不会有任何版本支持Python 3。

> 我对为什么会出现这个问题感到困惑,因为我正在使用Python 3来运行ape。

是的,这就是为什么ape的Python 2的语法不起作用的原因。

从评论中我们可以看到,ape 实际上并不是你要找的项目。你想要的是完全不相关的包 eth-ape。卸载 ape 并安装那个包。

英文:

No release of ape has ever supported Python 3. It's also a dead project, with the last release in 2014 and the last activity on the repository in 2017, so no release is ever going to support Python 3.

> I am confused about why this issue is happening since I am using Python 3 to run ape.

Yes, which is why ape's Python 2-only syntax isn't working.

From the comments, we can see that ape isn't actually the project you're looking for. You want the completely unrelated package eth-ape. Uninstall ape and install that.

答案2

得分: 0

在Python 3中,print 需要使用括号。

&gt;&gt;&gt; print("foo")
  File "&lt;stdin&gt;", line 1
    print("foo")
              ^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print("foo")?
&gt;&gt;&gt; print("foo")
foo

而在Python 2中省略括号是完全有效的。

&gt;&gt;&gt; print "foo"
foo
英文:

print in Python 3 requires parentheses.

&gt;&gt;&gt; print &quot;foo&quot;
  File &quot;&lt;stdin&gt;&quot;, line 1
    print &quot;foo&quot;
              ^
SyntaxError: Missing parentheses in call to &#39;print&#39;. Did you mean print(&quot;foo&quot;)?
&gt;&gt;&gt; print(&quot;foo&quot;)
foo

Whereas it's perfectly valid in Python 2 to elide the parentheses.

&gt;&gt;&gt; print &quot;foo&quot;
foo

huangapple
  • 本文由 发表于 2023年8月5日 12:49:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/76840171.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定