Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

Pushkar Kadam
Pushkar Kadam
3,823 Points

AttributeError: module 'random' has no attribute 'randint'

I've been trying to use import random in pycharm. When I type import random, import doesn't highlight first (import random remains grey all the time unlike the way it looks in workspaces). It only gets highlighted when I type randint.

When I run it, it shows me the following error:

AttributeError: module 'random' has no attribute 'randint'

I am not able to know what's wrong with it, because the same code works properly on workspaces where I am able to import random and use randint very properly.

Please help me know how I can fix it.

1 Answer

Haider Ali
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Haider Ali
Python Development Techdegree Graduate 24,728 Points

Hi there, this error could be occuring because you have another module somewhere named random that pycharm is accessing instead of actually accessing the pe-included random module. This could be because you have another file named 'random.py'. If this is the case, rename the file to something else and the import should work fine.

Thanks, Haider