简体   繁体   English

Pycharm 无法导入数学模块

[英]Pycharm cannot import math module

我无法在 pycharm 中导入标准数学模块,出现错误:“没有名为 math 的模块”,我可以从 python shell 导入它,这是什么原因造成的?

Check that you are pointing to the correct python file within Settings > Project > Project Interpreter.检查您是否在设置 > 项目 > 项目解释器中指向正确的 python 文件。

When I've had this problem in the past my interpreter was pointing at python3.6 and not python within the bin folder of my venv.当我过去遇到这个问题时,我的解释器指向我的 venv 的 bin 文件夹中的python3.6而不是python I simply dropped the interpreter and added it again pointing to the venv-name/bin/python我只是删除了解释器并再次添加它指向 venv-name/bin/python

File >> Settings >> Project interpreter.文件>>设置>>项目解释器。 You should see a list of currently installed packages/libraries.您应该会看到当前安装的软件包/库的列表。 If the module is not specified in there click the plus sign and look for your module in there.如果那里没有指定模块,请单击加号并在那里查找您的模块。 Also make sure you specify it correctly when you import it.还要确保在导入时正确指定它。

I had a similar issue and was able to fix it by creating a new Python system interpreter.我有一个类似的问题,并且能够通过创建一个新的 Python 系统解释器来修复它。 Project Interpreter -> Add Local -> System Interpreter -> /usr/local/bin/python3 Project Interpreter -> Add Local -> System Interpreter -> /usr/local/bin/python3

import math -> 而不是使用 "print(sqrt(25))" 使用 "print(math.sqrt(25))" (这里 sqrt 仅用于 exp.)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM