Can't run a project with both pygame and numpy

Hi,

If I create a pygame project and add numpy as a package, the console executes “python3 - m poetry add numpy”. I then get an error that ‘NoneType’ object is not subscriptable at venv/lib/python3.8/site-packages/poetry/repositories/pypi_repository.py: 282 in _get_release_info (Line 278: cache_version = str(self.CACHE_VERSION),

If instead I create a python project and I add pygame and numpy as packages, when I run my program I get a runtime error “pygame.error: No available video device”.

Is there some way I can run my program in replit that uses both pygame and numpy?

Hi!

I think the error is with the code rather than numpy.

Could you share the repl link so I can take a better look? Thanks

Hi, the current code is here:

https://replit.com/@12bcs1/Pygame-Tile-Match-Solution-Solution#main.py

I can replicate the error by having this single line of code in main.py:
import pygame,numpy

Context: This is a project from tes.com that I am loading into Replit.

The project uses numpy for 2-D arrays (only), so I think I can work around the issue by using python 2-D arrays rather than numpy 2-D arrays.

I can’t seem to access the repl for some reason, I think it’s because it’s on an educational account. Could you paste the code that’s generating the error here?

Also, the error NoneType is not subscriptable means you are trying to use the subscript operator [] on a variable that has None type. You can only use the subscript operator on certain types like arrays or tuples.

A common way this error can occur is through sorting a list incorrectly:

my_list = [ 7, 6, 5 ]

# incorrect
my_list = my_list.sort()
# correct
my_list.sort()

print(my_list[0])

Hi,

The following code triggers the error:

import pygame,numpy

The error occurs when executing the command:

python3 -m poetry add numpy

This error is generated in the following repl, which has the above line of code (only):

@PageStarr/CapitalAquamarineCalculators#main.py

I created my own Pygame repl and tried to use Numpy, but I got the same issue. I think the error ‘NoneType’ object is not subscriptable is actually a bug with the Pygame repl, since the error appears before the main.py file is interpreted. I submitted a bug report.

In the meantime, you could manually install the package. Go to the Shell (it’s next to the console) and type:

pip install numpy

You would still need to have import numpy in your main.py file. And there might be some error messages in the console, but if your code works then just ignore them. You could also clear the console at the beginning of your code so you don’t have to see them:

import numpy, os
clear = lambda: os.system('clear')

# this function will clear the console
clear()

# rest of the code...

Hopefully that works!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.