python-3.xpycharmalgorand

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


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


Solution

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