无法在 PyCharm 的 __init__.py 文件中找到 ‘get_accounts’ 的引用。

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

Cannot find reference 'get_accounts' in '__init__.py' in PyCharm

问题

我看到有其他类似的问题,但没有一个能解决我的问题。
我正在尝试在PyCharm中使用Algosdk,按照教程片段进行操作。
但是,当我尝试在PyCharm中编写它时,我总是得到这个错误

在__init__.py中找不到引用'get_accounts'

在这个的第一行

from utils import get_accounts, get_algod_client 
from algosdk import account, mnemonic

accts = get_accounts()

相同的错误也出现在get_algod_client

我已经按照路径进行了操作,发现utils__init__.py是空的,但我不知道如何填充它,因为我是从官方的Algorand网站下载的。
我还在我的项目解释器中导入了py-algorand-sdk(设置->项目:我的项目-> Python解释器),但没有任何变化。
感谢大家的帮助。

英文:

I see there are other question like this but none can solve my issue.
I'm trying the Algosdk in PyCharm following the tutorial snippet.
But when I try to write it in my PyCharm i get always this error

Cannot find reference 'get_accounts' in __init__.py

in PyCharm in the first line of this

from utils import get_accounts, get_algod_client 
from algosdk import account, mnemonic

accts = get_accounts()

The same error appears also in get_algod_client

I've followed the path and I've discovered that the __init__.py of utils is empty, but I don't know how to fill it, because i downloaded it from the official Algorand website.
I have also imported the the py-algorand-sdk in my Project interpreter (Settings->Project: MyProject-> Python interpreter) but nothing changed.
Thanks all for the help

答案1

得分: 1

我刚刚尝试了一个全新的PyCharm 2023.1.2项目(Python 3.11与venv),在项目中创建了两个文件:main.pyutils.py
我没有遇到这个问题。

main.py

from utils import get_accounts, get_algod_client
from algosdk import account, mnemonic
from algosdk import transaction

# 示例:ACCOUNT_GENERATE
private_key, address = account.generate_account()
print(f"地址:{address}")
print(f"私钥:{private_key}")
print(f"助记词:{mnemonic.from_private_key(private_key)}")

utils.py来自https://github.com/algorand/py-algorand-sdk/blob/79c6ce965391dddc6764d75d8e2f6f11a194a21d/examples/utils.py

然而,如果您使用的是旧版本可能会出现一些问题。

您可以尝试/检查:

  1. 检查utils.py是否存在于相同的文件夹并且是上面提到的那个文件。
  2. 更新PyCharm到最新版本。
  3. 如果这不起作用,并且您的源代码位于子文件夹中,请将该目录标记为"Source root"。请参见https://stackoverflow.com/a/20479761和https://stackoverflow.com/a/52390958

您还可以通过在控制台中运行python3 main.py来检查问题是否与PyCharm有关。

英文:

I have just tried on a fresh new PyCharm 2023.1.2 project (Python 3.11 with a venv), creating just two files in the project: main.py and utils.py.
And I do not have the issue.

main.py:

from utils import get_accounts, get_algod_client
from algosdk import account, mnemonic
from algosdk import transaction

# example: ACCOUNT_GENERATE
private_key, address = account.generate_account()
print(f"address: {address}")
print(f"private key: {private_key}")
print(f"mnemonic: {mnemonic.from_private_key(private_key)}")

utils.py from https://github.com/algorand/py-algorand-sdk/blob/79c6ce965391dddc6764d75d8e2f6f11a194a21d/examples/utils.py

It is possible however that if you have an older version that has some issues.

Can you try/check:

  1. Check that utils.py exists in the same folder and is the one above.
  2. Update PyCharm to the latest version?
  3. If this does not work and if your sources are in a subfolder, mark the director as "Source root". See https://stackoverflow.com/a/20479761 and https://stackoverflow.com/a/52390958

You can also check whether the issue is PyCharm-related or not, by running in the console python3 main.py.

huangapple
  • 本文由 发表于 2023年6月1日 17:42:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/76380590.html
匿名

发表评论

匿名网友

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

确定