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

Not able to use import random in pycharm

I've been using pycharm to code on my windows and have installed python 3. while I type 'import random' , it doesn't highlight anything like the way it does in workspaces and that line turns into grey. Do I need to make some changes in the settings in pycharm in order to solve this or should I proceed with the same even though 'import' is not being highlighted.

In fact, import highlights when I type 'import' but as soon as I type 'random', everything becomes grey.

Does your code get executed?

2 Answers

Michael Nock
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Michael Nock
Android Development Techdegree Graduate 16,018 Points

Pushkar Kadam, if you created a new file, make sure that you are running the new file and not your previous file. Press Alt + Shift + F10 (or select Run from the Run menu) and then select your new file. In addition, make sure your file isn't named random.

Also here is maybe a solution from someone with the same problem... http://stackoverflow.com/questions/19885821/how-do-i-import-modules-in-pycharm

BTW: for such small test scripts, Pycharm is a little bit over the top...but what ever

Pushkar Kadam
Pushkar Kadam
3,823 Points

My code is not getting executed. I am receiving the following error message.

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

and as soon as I wrote randint, the import got highlighted (which I mentioned earlier that it wasn't getting highlighted).

I checked out some forums online and there they mentioned to not name the file random.py So, I ensured that I created new file in pycharm with different name. But, it is giving me the same error.