#Compiler Broken out of nowhere? Critical Key Error: 0
197 messages · Page 1 of 1 (latest)
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
Interesting @celest swallow didn’t you have this same error?
I kept commenting things out until I got down to this barebones contract above
, so weird, not sure what changed
Yeah Astha had this same error yesterday trying to build Folks Finance’s NTT contracts
There wasn't an update recently was there? Or even within the past few hours? It was compiling just fine 2 hours ago
I don’t think so, it’s a strange error
I’ll make sure the AlgoKit team sees this
Usage: algokit [OPTIONS] COMMAND [ARGS]...
Try 'algokit -h' for help.
Error: No such command 'compile'.
What happened to the compile command T.T
have you tried compiling directly with puyapy?
I exclusively use algokit compile and algokitgen-py, not sure if there's an alternative for the former now
try puyapy instead of algokit compile
add the path in the end the same
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```
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
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
It works for me
Interesting
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
which alogkit version do you have?
...
Why does it always install the oldest version
The doctor outpus says you have 2.9.1?
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"
This happens to me at least three times a year
I never remember what the steps were to fix
Did you update Python to 3.14 before this error?
No
So the error is independent of Python 3.14?
Cause the guy yesterday also had Python 3.14
It is probably 3.14 issue
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
Yeah, that means it needs to be less than 3.14
Pip install is just for your project’s virtual environment isn’t it?
Does globally installing with pipx have the same issue?
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~

did you do the algokit init for this contract/project?
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
.toml***
Still nothing
gabe, does compiling work for you normally?
yeah algokit compile py works fine for me
With just a single file with some contract code?
Or with algokit init => algokit compile py
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
What's with people installing algokit and it gives them version 1.11.0?
for that i have no idea
never seen that before, does that happen to you too?
might be someone messed up the registries? haven't heard anything tho
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
gabe, did you know .toml stands for Tom's Obvious Minimal Language?
just a quick tidbit for the audience
I did not haha TIL
@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
Yeah likewise I’m being chastised for being on my phone
wsl
No
I live in NY 😂 but yes Brazilians don’t really celebrate
This happens when you have a version of Python installed that isn’t supported I think
?
Windows power shell
But let me connect remotely and try it
Same error
You’re running this via WSL?
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
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
Nice there you go
So I just don't optimize ever again :P?
Seems like an optimization bug, weird that it pops up inconsistently
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
It was due to a change in behaviour of a downstream dependency, will have a release out today with a fix https://github.com/algorandfoundation/puya/pull/606
Working now @inner jay Thank you!
Gave +1 Rep to @inner jay (current: #23 - 16)
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
lies
jk lol
Pls help tho when you get a chance, ty king
what does algokit compile py --version give?
well there is your problem, fix is in 5.5.0
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
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
Thank you again! @inner jay
Gave +1 Rep to @inner jay (current: #22 - 17)
You should probably use poetry to handle any dependency updates that fall within algokit as puyapy does
@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
It should work, what error do you get?
error: free functions must be annotated with @algopy.subroutine
and on call/invoke, error: Cannot invoke smart_contracts.contract.my_subroutine as it is not decorated with algopy.subroutine
it only applies to methods that are part of a Contract, not functions at the global scope
Ah, so for subroutines within the contract itself?
yeah
what's the difference?
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")
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
@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)
Ah, ok. So if the function isn't decorated with subroutine, the compiler doesn't have any way of knowing if it can be used within algorand python and not just some generic python function with incompatible code
yep
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
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
if not explicitly specified, does this get decided by the compiler on its own?
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
Ok, thanks for the explanation. Also, the FixedBytes was a nice addition in this release
Gave +1 Rep to @inner jay (current: #21 - 18)
yeah its nicer than having to use arc4.StaticArray
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
nice!
Because FixedArray didn't allow me to construct an instance of itsself fromBytes, none of the arrays did except arc4.StaticArray
oh yeah that would have been awkward
Getting key error again
algokit 2.10.2
algokit-utils 4.2.3
algorand-python 3.0.0
py-algorand-sdk 2.11.1
what optimization level is your compile script set to?
Went out for dinner sorry for the late reply — whatever the default is
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