Cannot import PublicKey from solana.publickey

1.7k views Asked by At

I'm developing a tracking script using Python and the Solana.py, installed via pip. The script uses websocket subscriptions to notify me when something happens on the Solana blockchain. My first approach was to watch a specific account:

await websocket.account_subscribe(PublicKey('somekeyhere'))

But when doing ...

from solana.publickey import PublicKey

I get the following error:

from solana.publickey import PublicKey
ModuleNotFoundError: No module named 'solana.publickey'

Solana.py is the latest version (0.31.0). I'm on Ubuntu 22.04 LTS and using Python 3.10.12.

I found a workaround, just using another subscription method, that does not need any parameters:

await websocket.logs_subscribe()

Then I analyze the output to my needs. That means, that I'm dealing with every single log on the Solana blockchains. It works, but it does not "feel right". And I would love to understand, what is going wrong when using the websocket.account_subscribe method.

Any suggestions? Regards Kurt

2

There are 2 answers

2
Brian - RGY Studio On BEST ANSWER

Based on their github, it looks like what you need is Pubkey, not Publickey, taken from solders rather than solana. Have you tried this instead?

from solders.pubkey import Pubkey

I haven't used their SDK before, so this might not solve your issue, but it was something I noted given your issue.

Ref: solana.py Github

3
Clickbait Fish On

Are you having any issues when importing:

from solders.pubkey import Pubkey

I am trying to import solders but keep getting "could not resolve module not found" even though I have installed solders and solana

how did you overcome this?