How to use an unlisted Python Package with 'pyproject.toml' file in Google Colab

I am trying to use an Unofficial Twitter API using python library called RedGalaxy on Google Colab. This package is not yet available on Pypi platform.

I have tried to build the package in Google colab itself but wasn’t able to use it there.

!git clone https://github.com/Ristellise/RedGalaxy.git
!pip install -e ./RedGalaxy/.

Output:

Successfully built RedGalaxy
Successfully installed RedGalaxy-0.1.0 h11-0.14.0 httpcore-0.16.3 httpx-0.23.3 rfc3986-1.5.0

When I try to import library:

Code:

from RedGalaxy import TwitterUser

Output:

ImportError                               Traceback (most recent call last)
<ipython-input-3-2f6c640e0abc> in <cell line: 3>()
      1 import asyncio
      2 
----> 3 from RedGalaxy import TwitterUser
      4 
      5 

ImportError: cannot import name 'TwitterUser' from 'RedGalaxy' (unknown location)

>Solution :

It seems like there is an issue with the import statement. Here are a few things you can try:

  1. Ensure that the package is installed properly by running !pip freeze command in a separate cell on Colab. This will show all the installed packages along with their versions. Check if RedGalaxy package is listed there.

  2. Try importing the package using the following statement instead:

    from RedGalaxy.twitteruser import TwitterUser

This assumes that the TwitterUser module is present in the twitteruser sub-package.

  1. Check if there are any naming conflicts with other modules that you may have imported. Sometimes, there may be a name collision with another module, which causes the import statement to fail.

  2. Ensure that you are using the correct version of Python. RedGalaxy may be written for a specific version of Python. You can check the required Python version in the README file of the package repository.

If none of the above methods work, you may try to contact the package maintainer or developer for further assistance.

Leave a Reply