Importing library in python

Asked

Viewed 3,426 times

2

I am unable to import any library in python using pycharm. When I type, for example, the command import time, the words turn gray and bring nothing.

  • And you used the module time somewhere in the code?

  • It has a picture of what happens Rafael?

  • Usually this is a graphic way of pycharm saying that you did not use this import... If you do not use the time package in the file . py in question, it will remain 'gray'.

2 answers

1

When the import gets gray, it’s because you’re not using it.

What I suspect you’re doing is this:

import time
sleep(2)

It doesn’t work because you’re only importing the name time. To use the library, you need to access its functions like this:

import time
time.sleep(2)

Or, importing all module names, as follows:

from time import *
sleep(2)

0

As @Haynesss commented, Pycharm indicates every time a variable or even an import is not used. It’s good practice.

Anyway, as a bonus, it is always interesting to define which python interpreter you are using in Pycharm.

Take a look in the Pycharm documentation for python interpreter configuration. It’s English, but it’s a starting point.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.