There is no library called math

3

Because when I import sqrt of the math bookstore it says that there is no bookstore called math , but still the code works?

Does not give error works fine, but that underlies in math and sqrt . To "heal" while I do not find the answer I'm using cmath which would be for more complete numbers correct?

Why is it underlined that math does not exist because the code works the same?

    
asked by anonymous 06.12.2017 / 05:00

3 answers

4

If you use

import math

is making the math module available for your application to use. So you need to call the function inside the module, like this:

math.sqrt(9)

But if you use

from math import sqrt

You are bringing the sqrt function that is in math into the scope of your code. So the function is available right there and you do not need, and can not, call the original module, it's like a function you wrote right there, like this:

sqrt(9)

Just be careful not to import this way using * to not pollute the namespace with all functions you probably will not use. If you are going to import some functions from the module, you should prefer the first one.

    
06.12.2017 / 09:51
1

I discovered yesterday what happened, I mind correct and I know that I care math I should use math.sqrt but what happened is that yesterday I had an update on pycharm that is my idle and I discovered that there was an error in this att then What I did was to install an older one to fix it. I already reported it to the pycharm dev, I discovered that it was in the idle of the python itself and there was no such error. Thanks for replying anyway

    
06.12.2017 / 20:21
0

Follow these steps, in pycharm:

1) Access: File > Settings.

2) In the side menu click: Project: "Project name" > Project Interpreter.

3) In the upper right corner click the gear and then "Add location ..."

4) In the window that will appear select the "Inherit global site-packages" and "Make available to all projects" and click "OK", wait for loading.

5) Close PyCharm and re-open and test!

    
19.04.2018 / 04:41