【问题标题】:First time user of VS Code and Python第一次使用 VS Code 和 Python
【发布时间】:2018-12-24 16:09:56
【问题描述】:

第一次在 VS Code 中使用 Python。我的导入未被识别,即随机?

我已经在 Anaconda Jupyter 中运行了我的代码,所以我知道我的代码可以正常工作。是配置问题。

import random
num = random.randint(1,2)

我希望没有运行时错误。

但我在控制台中得到以下响应:

num = random.randint(1,2)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'random' is not defined

【问题讨论】:

    标签: python python-3.x visual-studio-code


    【解决方案1】:

    我认为你没有配置你的 python 解释器。您可以通过打开命令面板 (Ctrl+Shift+P) 来选择 Python 解释器,开始输入 Python:选择要搜索的解释器命令,然后选择要用于当前文件的 Python 解释器。

    如果还是不行,可以参考这个 VS Code document 了解更多详情。

    【讨论】:

    • 感谢您的回复!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-02-13
    • 2021-03-21
    • 1970-01-01
    • 2020-08-14
    • 2019-02-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多