#Compiler Broken out of nowhere? Critical Key Error: 0

197 messages · Page 1 of 1 (latest)

small peak
#

~

#

class Test(ARC4Contract):
    def __init__(self) -> None:
        pass```
#

Can't even get this to compile:

#
info: using puyapy version 5.4.0
warning: cannot determine package root for contract/test.py
info: using python search path: ['C:\\Users\\atsoc\\AppData\\Local\\Programs\\Python\\Python312\\python312.zip', 'C:\\Users\\atsoc\\AppData\\Local\\Programs\\Python\\Python312\\DLLs', 'C:\\Users\\atsoc\\AppData\\Local\\Programs\\Python\\Python312', 'C:\\Users\\atsoc\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages', 'C:\\Users\\atsoc\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\win32', 'C:\\Users\\atsoc\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\win32\\lib', 'C:\\Users\\atsoc\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\Pythonwin']
warning: could not determine algopy version
critical: KeyError: 0
#
HTTP Request: GET https://api.github.com/repos/algorandfoundation/algokit-cli/releases/latest "HTTP/1.1 200 OK"
timestamp: 2025-11-27T20:20:28+00:00
AlgoKit: 2.9.1
AlgoKit Python: 3.12.10 (tags/v3.12.10:0cc8128, Apr  8 2025, 12:21:36) [MSC v.1943 64 bit (AMD64)] (location: C:\Users\atsoc\AppData\Local\Programs\Python\Python312)
OS: Windows-11-10.0.26100-SP0
docker: 27.4.0
docker compose: 2.31.0-desktop.2
git: 2.47.1.windows.2
python: 3.12.10 (location: C:\Users\atsoc\AppData\Local\Programs\Python\Python312\python.EXE)
python3: Command not found!
pipx: 1.7.1
poetry: 2.0.1
node: 22.13.1
npm: 10.9.2
winget: 1.12.350
#

I already pip uninstalled algokit and algorand-python and reinstalled

copper monolith
#

Interesting @celest swallow didn’t you have this same error?

small peak
#

I kept commenting things out until I got down to this barebones contract above hypers , so weird, not sure what changed

copper monolith
#

Yeah Astha had this same error yesterday trying to build Folks Finance’s NTT contracts

small peak
#

There wasn't an update recently was there? Or even within the past few hours? It was compiling just fine 2 hours ago

copper monolith
#

I don’t think so, it’s a strange error

#

I’ll make sure the AlgoKit team sees this

small peak
#
Usage: algokit [OPTIONS] COMMAND [ARGS]...
Try 'algokit -h' for help.

Error: No such command 'compile'.

What happened to the compile command T.T

modern flume
small peak
modern flume
#

add the path in the end the same

small peak
#

puyapy not a command

#

Could this just be pip installed?

#

1 sec

#

XD

info: using puyapy version 5.4.0
warning: cannot determine package root for contract/test.py
info: using python search path: ['C:\\Users\\atsoc\\AppData\\Local\\Programs\\Python\\Python314\\python314.zip', 'C:\\Users\\atsoc\\AppData\\Local\\Programs\\Python\\Python314\\DLLs', 'C:\\Users\\atsoc\\AppData\\Local\\Programs\\Python\\Python314', 'C:\\Users\\atsoc\\AppData\\Local\\Programs\\Python\\Python314\\Lib\\site-packages', 'C:\\Users\\atsoc\\AppData\\Local\\Programs\\Python\\Python314\\Lib\\site-packages\\win32', 'C:\\Users\\atsoc\\AppData\\Local\\Programs\\Python\\Python314\\Lib\\site-packages\\win32\\lib', 'C:\\Users\\atsoc\\AppData\\Local\\Programs\\Python\\Python314\\Lib\\site-packages\\Pythonwin']
critical: KeyError: 0```
modern flume
#

Ok, so same error, but now maybe we can assume it's coming directly from puyapy instead of being algokit related

#

Let me try doing it

small peak
#

warning: cannot determine package root for contract/test.py

This is new for me, its like its trying to find the specific algokit config for the project before compiling

#

Which I have no idea what that has to do with outputting the respective arc files and TEAL for a contract

#

I could just use an older version but then forfeit future optimizations and functionality

modern flume
#

It works for me

small peak
#

Interesting

modern flume
#

tested algokit project build and puyapy

#

and i do have puyapy 5.4.0

small peak
#
  bootstrap    Bootstrap local dependencies in an AlgoKit project; run from project root directory.
  completions  Install and Uninstall AlgoKit shell integrations.
  config       Configure AlgoKit settings.
  deploy       Deploy smart contracts from AlgoKit compliant repository.
  dispenser    Interact with the AlgoKit TestNet Dispenser.
  doctor       Diagnose potential environment issues that may affect AlgoKit.
  explore      Explore the specified network in the browser using Dappflow.
  generate     Generate code for an Algorand project.
  goal         Run the Algorand goal CLI against the AlgoKit LocalNet.
  init         Initializes a new project from a template; run from project parent directory.
  localnet     Manage the AlgoKit LocalNet.
  task         Collection of useful tasks to help you develop on Algorand.```
#

You have an older algokit version I think

#

project is not even a command anymore for me

modern flume
#

which alogkit version do you have?

small peak
#

oh sht

#

Uh 1.11.0

modern flume
#

...

small peak
#

Why does it always install the oldest version

modern flume
#

The doctor outpus says you have 2.9.1?

small peak
#

Well I've been uninstall and installing a bunch of things lol

#

Now I've wiped python off my PC and am on python version 3.14

#

pip install algokit => installs 1.11.0

#

pip install algokit --upgrade => "Yeah you already have 1.11.0 dont worry"

modern flume
#

Hmm

#

Some guy in the general chat yesterday had a similar problem

small peak
#

This happens to me at least three times a year

#

I never remember what the steps were to fix

modern flume
#

Did you update Python to 3.14 before this error?

small peak
#

No

modern flume
#

So the error is independent of Python 3.14?

#

Cause the guy yesterday also had Python 3.14

small peak
#

It is probably 3.14 issue

modern flume
#

If you said you got this error before updating to 3.14?

#

I'm still running 3.13, so i don't know what happens with 3.14

small peak
#

2.9.1 Requires-Python >=3.10,<3.14

#

Will just downgrade to 3.13

modern flume
#

Yeah, that means it needs to be less than 3.14

copper monolith
#

Pip install is just for your project’s virtual environment isn’t it?

#

Does globally installing with pipx have the same issue?

small peak
#

Yeah back to square one

#

key error :0

#

Let me uninstall and use pipx

#

Yeah even with pipx global install same key error issue

#
Package                  Version
------------------------ ---------------
aggdraw                  1.3.19
aiohappyeyeballs         2.6.1
aiohttp                  3.12.13
aiosignal                1.3.2
algokit-client-generator 2.1.0
algokit-utils            4.2.1
annotated-types          0.7.0
anyio                    4.9.0
argcomplete              3.6.2
 . . .
 . . .

(Not in Pip)

uninstalled algokit! ✨ 🌟 ✨
PS C:\Users\atsoc\OneDrive\Desktop\Algo Idle> pipx uninstall poetry
uninstalled poetry! ✨ 🌟 ✨
PS C:\Users\atsoc\OneDrive\Desktop\Algo Idle> pipx install algokit
  installed package algokit 2.9.1, installed using Python 3.13.9
  These apps are now globally available
    - algokit.exe
done! ✨ 🌟 ✨
PS C:\Users\atsoc\OneDrive\Desktop\Algo Idle> pipx install poetry
  installed package poetry 2.2.1, installed using Python 3.13.9
  These apps are now globally available
    - poetry.exe
done! ✨ 🌟 ✨
PS C:\Users\atsoc\OneDrive\Desktop\Algo Idle> algokit compile py contract/test.py
puyapy is already on your PATH and installed at
    C:\Users\atsoc\AppData\Local\Programs\Python\Python314\Scripts\puyapy.EXE.
    Downloading and running anyway.
info: using puyapy version 5.4.0```

Reinstalled with pipx

```PS C:\Users\atsoc\OneDrive\Desktop\Algo Idle> algokit compile py contract/test.py
puyapy is already on your PATH and installed at
    C:\Users\atsoc\AppData\Local\Programs\Python\Python314\Scripts\puyapy.EXE.
    Downloading and running anyway.
info: using puyapy version 5.4.0
warning: cannot determine package root for contract/test.py
info: using python search path: ['C:\\Users\\atsoc\\AppData\\Local\\Programs\\Python\\Python313\\python313.zip', 'C:\\Users\\atsoc\\AppData\\Local\\Programs\\Python\\Python313\\DLLs', 'C:\\Users\\atsoc\\AppData\\Local\\Programs\\Python\\Python313', 'C:\\Users\\atsoc\\AppData\\Local\\Programs\\Python\\Python313\\Lib\\site-packages', 'C:\\Users\\atsoc\\AppData\\Local\\Programs\\Python\\Python313\\Lib\\site-packages\\win32', 'C:\\Users\\atsoc\\AppData\\Local\\Programs\\Python\\Python313\\Lib\\site-packages\\win32\\lib', 'C:\\Users\\atsoc\\AppData\\Local\\Programs\\Python\\Python313\\Lib\\site-packages\\Pythonwin']
warning: could not determine algopy version
critical: KeyError: 0
HTTP Request: GET https://api.github.com/repos/algorandfoundation/algokit-cli/releases/latest "HTTP/1.1 200 OK"
timestamp: 2025-11-27T21:39:14+00:00
AlgoKit: 2.9.1
AlgoKit Python: 3.13.9 (tags/v3.13.9:8183fa5, Oct 14 2025, 14:09:13) [MSC v.1944 64 bit (AMD64)] (location: C:\Users\atsoc\pipx\venvs\algokit)
OS: Windows-11-10.0.26100-SP0
docker: 27.4.0
docker compose: 2.31.0-desktop.2
git: 2.47.1.windows.2
python: 3.13.9 (location: C:\Users\atsoc\AppData\Local\Programs\Python\Python313\python.EXE)
python3: Command not found!
pipx: 1.8.0
poetry: 2.2.1
node: 22.13.1
npm: 10.9.2
winget: Command not found!```
#

Heading off to thanksgiving dinner~

modern flume
copper monolith
#

yeah try adding a minimal .algokit.toml in your project root

#
[project]
name = "project"
type = "contract"
#

had to do the same for non-algokit initted projects

#

dunno why it's coupled to that but that minimal file should do it

small peak
#

Still nothing

copper monolith
#

.toml***

small peak
#

Still nothing

modern flume
small peak
copper monolith
#

yeah algokit compile py works fine for me

small peak
#

With just a single file with some contract code?

#

Or with algokit init => algokit compile py

copper monolith
#

in non-algokit projects yeah

#

oh

#

you're doing algokit compile py contract/test.py

#

try algokit compile py ./contract/test.py

#

bet that's it

modern flume
copper monolith
modern flume
#

Someone had this same version yesterday upon installing

#

That's hella weird

copper monolith
#

never seen that before, does that happen to you too?

modern flume
#

No, someone yesterday in the general chat

#

Was asking for help

copper monolith
#

might be someone messed up the registries? haven't heard anything tho

modern flume
#

And they had the same version upon running the install algokit command

#

Maybe that fxcks something up in the pipeline

#

@small peak mr.Leo, can you do poetry show

modern flume
#

just a quick tidbit for the audience

copper monolith
#

I did not haha TIL

modern flume
#

@small peak mr.Leo, do you have an __init__.py file present in your contract directory when you're doing your weird compilation techniques?

#

Ah, he went to eat Thanksgiving turkey it seems

#

Even though he's not American

#

Whatever, i'm gonna take a shower

copper monolith
#

Yeah likewise I’m being chastised for being on my phone

small peak
small peak
copper monolith
small peak
#

But let me connect remotely and try it

#

Same error

copper monolith
#

You’re running this via WSL?

small peak
#

I’m on windows so VS code defaults to WSL but I have git as well, I was just trying to point out the reasoning for syntax difference

#

Anyways I will probably have to reset my PC to factory settings at this point 😂

#

Maybe @inner jay has seen “Key Error: 0” before when trying to compile?

#

Came out of nowhere and won’t go away

#

Can’t compile any contract

#

Maybe it’s even a VS code issue? Some caching somewhere

small peak
#

File "C:\Users\atsoc\pipx\.cache\71ada45990af50d\Lib\site-packages\puya\ir\optimize\repeated_code_elimination.py", line 61, in compute_dominator_tree idom_ids.pop(start.id) ~~~~~~~~~~~~^^^^^^^^^^ KeyError: 0 critical: KeyError: 0

#

So if I compile with the --log-level debug I get the above error

#

So it happens during optimization

#

If I set optimization level to 0

#

It compiles:

#

algokit compile py test.py -O 0 --log-level debug

copper monolith
#

Nice there you go

small peak
#

So I just don't optimize ever again :P?

copper monolith
#

Seems like an optimization bug, weird that it pops up inconsistently

small peak
#

I have no idea what happened, I was adding some logic and recompiled, then got this optimization error, kept commenting out code until the contract was bare bones, same error

#

Then as you know I uninstalled and reinstalled algokit, algorand-python, even python itself in my system trying to fix it

inner jay
small peak
#

Working now @inner jay Thank you!

wintry jayBOT
#

Gave +1 Rep to @inner jay (current: #23 - 16)

small peak
#

Hey @inner jay

Im getting the same error with python version 3.13.9

Doctor output:

HTTP Request: GET https://api.github.com/repos/algorandfoundation/algokit-cli/releases/latest "HTTP/1.1 200 OK"
timestamp: 2025-12-04T19:03:27+00:00
AlgoKit: 2.9.1
AlgoKit Python: 3.13.9 (tags/v3.13.9:8183fa5, Oct 14 2025, 14:09:13) [MSC v.1944 64 bit (AMD64)] (location: C:\Users\atsoc\OneDrive\Desktop\AVM Linear Regression\venv)
OS: Windows-11-10.0.26100-SP0
docker: 27.4.0
docker compose: 2.31.0-desktop.2
git: 2.47.1.windows.2
python: 3.13.9 (location: C:\Users\atsoc\OneDrive\Desktop\AVM Linear Regression\venv\Scripts\python.EXE)
python3: Command not found!
pipx: 1.8.0
poetry: Command not found!
  Poetry is required for some Python-based templates;
  install via `algokit project bootstrap` within project directory, or via:
  https://python-poetry.org/docs/#installation
node: 22.13.1
npm: 10.9.2
winget: Command not found!```
#

Error: $ algokit compile py linear_regression_contract.py --output-arc56 --out-dir contract_files warning: cannot determine package root for linear_regression_contract.py info: using python search path: ['C:\\Users\\atsoc\\AppData\\Local\\Programs\\Python\\Python313\\python313.zip', 'C:\\Users\\atsoc\\AppData\\Local\\Programs\\Python\\Python313\\DLLs', 'C:\\Users\\atsoc\\AppData\\Local\\Programs\\Python\\Python313', 'C:\\Users\\atsoc\\OneDrive\\Desktop\\AVM Linear Regression\\venv', 'C:\\Users\\atsoc\\OneDrive\\Desktop\\AVM Linear Regression\\venv\\Lib\\site-packages', 'C:\\Users\\atsoc\\OneDrive\\Desktop\\AVM Linear Regression\\venv\\Lib\\site-packages\\win32', 'C:\\Users\\atsoc\\OneDrive\\Desktop\\AVM Linear Regression\\venv\\Lib\\site-packages\\win32\\lib', 'C:\\Users\\atsoc\\OneDrive\\Desktop\\AVM Linear Regression\\venv\\Lib\\site-packages\\Pythonwin'] critical: KeyError: 0

small peak
#

jk lol

#

Pls help tho when you get a chance, ty king

inner jay
#

what does algokit compile py --version give?

small peak
#

5.2.0 @inner jay

inner jay
#

well there is your problem, fix is in 5.5.0

small peak
#

Ahh, I just used pip install algokit and it defaulted to that version in a virtual environment

#

I did pip freeze > requirements.txt and for some reason puyapy didn't show up. I did pip install puyapy and then pip freeze > requirements.txt again and puyapy is now showing in there, and compiles.

#

So I just need to remember to install algokit, and then puyapy ? pip install algokit puyapy

#

I'm not sure if it was always this way

inner jay
#

puyapy doesn't need algokit

#

if puyapy wasn't in your venv then algokit compile might have been falling back to a global version

#

pip install puyapy would then have added the latest puyapy to the venv which is why it started working

small peak
#

Thank you again! @inner jay

wintry jayBOT
#

Gave +1 Rep to @inner jay (current: #22 - 17)

modern flume
#

@inner jay Hey, i've upgraded puyapy to version 5.5.0

#

Can i now omit the use of decorator @subroutine above my contract's private methods?

#

Because that's what i figured i could do, based on what was written in the github release tag:

Changed
@subroutine decorator is now optional on private contract methods.```
#

Yet, it doesn't work for me

#

It still demands i apply the @subroutine decorator above

inner jay
#

It should work, what error do you get?

modern flume
#

and on call/invoke, error: Cannot invoke smart_contracts.contract.my_subroutine as it is not decorated with algopy.subroutine

inner jay
#

it only applies to methods that are part of a Contract, not functions at the global scope

modern flume
inner jay
#

yeah

modern flume
inner jay
#

e.g.

from algopy import ARC4Contract, String, arc4


class HelloWorldContract(ARC4Contract):
    @arc4.abimethod
    def hello(self, name: String) -> String:
        return self.greeting() + name

    def greeting(self) -> String:
        return String("Hello")
modern flume
#

Right now, if i use the subroutine decorator, i can put my method either within the scope of the contract OR in the global scope

#

Both work

#

What's the difference in practice?

#

Because i just assumed there's no difference

inner jay
#

@subroutine is used to indicate to the puya compiler a algopy compatible function from any other python function. We were able to relax this constraint on methods in a Contract as the Contract itself serves to indicate that its algopy compatible. Free functions still require the decorator tho.

#

@subroutine can also be used to force a function to be explicitly inlined (or not inlined)

modern flume
inner jay
#

yep

modern flume
#

But if it's put inside the contract, it can figure it out, but if it's outside, you still have to tell it explicitly

inner jay
#

yep you got it.

A related change is also allowing an @algopy.public decorator, instead of @algopy.arc4.abimethod no functional difference between the two. But now you don't need to use the arc4 namespace to just write a simple contract

modern flume
inner jay
#

yeah if not specified then the compiler uses some heuristics to decide if it should be inlined or not

#

by default it tries to inline

  • small functions, where the calling overhead is significant compared to the body
  • functions only used once in a contract
modern flume
wintry jayBOT
#

Gave +1 Rep to @inner jay (current: #21 - 18)

inner jay
#

yeah its nicer than having to use arc4.StaticArray

modern flume
#

Now i can enforce a fixed length, i.e. an argument expected to be a hash digest needing to be exactly 32 in size

#

And elegantly work with that and some native opcodes that will return Bytes

inner jay
#

nice!

modern flume
#

Because FixedArray didn't allow me to construct an instance of itsself fromBytes, none of the arrays did except arc4.StaticArray

inner jay
#

oh yeah that would have been awkward

small peak
#
algokit                2.10.2
algokit-utils          4.2.3
algorand-python        3.0.0
py-algorand-sdk        2.11.1
copper monolith
#

what optimization level is your compile script set to?

modern flume
#

hello darkness my old frienddd

#

i've come to talk to you againnn

small peak
#

It compiles if I set it to 0

#

Without the -O flag it fails like it did before with key error

#

Wait do I just pip install —upgrade puyapy?

#

Looking at earlier comments