OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Cannot import PublicKey from solana.publickey

  • Thread starter Thread starter Kurt
  • Start date Start date
K

Kurt

Guest
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:

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

But when doing ...

Code:
from solana.publickey import PublicKey

I get the following error:

Code:
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:

Code:
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
<p>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:</p>
<pre><code>await websocket.account_subscribe(PublicKey('somekeyhere'))

</code></pre>
<p>But when doing ...</p>
<pre><code>from solana.publickey import PublicKey

</code></pre>
<p>I get the following error:</p>
<pre><code>from solana.publickey import PublicKey
ModuleNotFoundError: No module named 'solana.publickey'

</code></pre>
<p>Solana.py is the latest version (0.31.0). I'm on Ubuntu 22.04 LTS and using Python 3.10.12.</p>
<p>I found a workaround, just using another subscription method, that does not need any parameters:</p>
<pre><code>await websocket.logs_subscribe()

</code></pre>
<p>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.</p>
<p>Any suggestions?
Regards
Kurt</p>
 
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:

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

But when doing ...

Code:
from solana.publickey import PublicKey

I get the following error:

Code:
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:

Code:
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
<p>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:</p>
<pre><code>await websocket.account_subscribe(PublicKey('somekeyhere'))

</code></pre>
<p>But when doing ...</p>
<pre><code>from solana.publickey import PublicKey

</code></pre>
<p>I get the following error:</p>
<pre><code>from solana.publickey import PublicKey
ModuleNotFoundError: No module named 'solana.publickey'

</code></pre>
<p>Solana.py is the latest version (0.31.0). I'm on Ubuntu 22.04 LTS and using Python 3.10.12.</p>
<p>I found a workaround, just using another subscription method, that does not need any parameters:</p>
<pre><code>await websocket.logs_subscribe()

</code></pre>
<p>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.</p>
<p>Any suggestions?
Regards
Kurt</p>
It seems like you're encountering a module import issue with Solana.py. Here are a few suggestions to troubleshoot and potentially resolve the problem:

1. **Check Installation**: Ensure that Solana.py is correctly installed in your Python environment. You can verify this by running `pip show solana` to see the installed version and location.

2. **Module Structure**: In some cases, the module structure might have changed between different versions of Solana.py. For version 0.31.0, the import should generally be correct as `from solana.publickey import PublicKey`.

3. **Python Path**: Sometimes, the Python interpreter might not be able to find the module due to the path configuration. Ensure that your Python environment (especially if using virtual environments) includes the directory where Solana.py is installed (`/usr/local/lib/python3.10/dist-packages` based on your previous example).

4. **Version Compatibility**: Check if there are any specific version compatibility issues between Solana.py and Python 3.10. While Python 3.10 should generally be supported, it's worth checking the Solana.py documentation or GitHub repository for any known issues.

5. **Community and Documentation**: If the issue persists, it might be helpful to consult the Solana.py documentation or community forums (like GitHub discussions or Stack Overflow) to see if others have encountered similar issues or if there are specific workarounds or updates.

6. **Alternative Approach**: Since you've found a workaround using `websocket.logs_subscribe`, continue using that if it meets your current needs. You can periodically check for updates to Solana.py or revisit the `account_subscribe` method in future releases.

By following these steps, you should be able to diagnose and potentially resolve the issue with importing `PublicKey` from Solana.py. If you need further assistance or encounter specific error messages, feel free to provide more details!
 
Top