python - First time user of VS Code and Python
问题描述
First time user of Python in VS Code. My import is not being recognized, i.e. random?
I have run my code in Anaconda Jupyter, so I know my code works. It's a config issue.
import random
num = random.randint(1,2)
I expect no run-time errors.
But I get the following response in the console:
num = random.randint(1,2) Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'random' is not defined
解决方案
I think that you had not configured you python interpreter. You can select a Python interpreter by opening the Command Palette (Ctrl+Shift+P), start typing the Python: Select Interpreter command to search, then select the python interpreter you want to use for your current file.
If it still not working, you can refer to this VS Code document for more details.
推荐阅读
- python-3.x - 不明白为什么这个 python 代码不起作用
- c++ - 指向同一个地址的空指针
- java - AudioInputStream 在 8 位 WAV 声音 Mac OSX 结束时弹出声音 [Java 1.7+ 错误]
- reactjs - 从可重用组件传递 ref
- javascript - Vue.js select2 Wrapper 组件更改事件
- neo4j - 合并具有 apoc 和平均属性值的节点
- java - Java中的基本刽子手程序
- aws-sdk - 将 AWS Javascript SDK 与 NativeScript 结合使用
- android - com.amazonaws:aws-android-sdk-mobile-client:2.8.5() 的 Gradle 同步失败
- javascript - 为什么 15 > 10 > 5 是假的?