Sublime Forum

Can't import packages

#1

I am VERY new to programming and just started learning about importing modules/packages in Python.

I seem to have the Python Standard Library installed, but I can’t seem to call it from Sublime in my programs (I get the error “AttributeError: ‘module’ object has no attribute ‘randint’”).

I have a feeling something is wrong in my settings and I have no idea how to fix it…the “Settings” option in Preferences looks very technical and overwhelming. Can anyone tell me how to fix this?

Please speak simply. I’m very new and have limited skills with this stuff.

Thanks in advance!

0 Likes

#2

Hi @bethhayden, can you provide the code ?

0 Likes

#3

Yep. I’m just running tiny programs, so here goes:

import random

random_list =[]

random_list = [random.randint(1,100) for i in range(101)]

The error I get is "AttributeError: ‘module’ object has no attribute ‘randint’

0 Likes

#4

is your file named random.py ? or is there another file in the same directory named random.py ?

0 Likes

#5

Yes. Does that make a difference? I’m trying to import the function from the Python Standard Library.

0 Likes

#6

Sorry, just realized I only answered the first part of your question. Yes, there are other files with the same name in that folder, but they have different extensions. I’ll try deleting them and run it again.

0 Likes

#7

Still got the same error when I deleted the other files.

0 Likes

#8

no need to delete them if they have other (non python) extensions, you just have to change the name of your current file to something other than random.py, because python searches for modules in the current directory before falling back to the standard library, and since you have no function named randint in your current file it’ll give that error.

0 Likes