Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

May I ask why "'type' object is not subscriptable" appears when running the code? #2

Open
growlsls opened this issue Feb 28, 2023 · 5 comments

Comments

@growlsls
Copy link

May I ask why "'type' object is not subscriptable" appears when running the code?

@Phoenix-Shen
Copy link
Owner

May I ask why "'type' object is not subscriptable" appears when running the code?

@Phoenix-Shen
Copy link
Owner

This is caused by python3.8 or previous versions, I wrote the code using python3.9. You can upgrade the python to 3.9.

Here is an example:

def func(li:list[str])->list[str]: # this will cause error in python 3.8 , but is right in 3.9

@Phoenix-Shen
Copy link
Owner

Phoenix-Shen commented Feb 28, 2023

May I ask why "'type' object is not subscriptable" appears when running the code?

I have explained the cause of the error. The easiest way is to create a new python environment and install the dependencies under my repository.

run this command

conda create -n rl python=3.9
pip install -r requirements.txt

Or, you must modify all

def func(li:list[str])->list[str]:

to

def func(li):

I write the code in such a way that I can know what the type of each variable is.
I hope my answer is helpful =-=.

@growlsls
Copy link
Author

thanks you. Can you give me an example? For example, "def sample(self) -> tuple[np.ndarray, t.ensor, t.ensor, t.ensor, t.ensor, t.ensor, t.ensor]: "What to change to

@Phoenix-Shen
Copy link
Owner

thanks you. Can you give me an example? For example, "def sample(self) -> tuple[np.ndarray, t.ensor, t.ensor, t.ensor, t.ensor, t.ensor, t.ensor]: "What to change to

Just delet all the return values!

def sample(self): 

@Phoenix-Shen Phoenix-Shen reopened this Feb 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants