【发布时间】:2020-09-17 20:50:10
【问题描述】:
我按照https://code.visualstudio.com/docs/python/python-tutorial 的说明下载了 Visual Studio Code 并安装了 Python。
当我在 Visual Studio Code 中选择 Python 扩展时,开始安装,但之后它告诉我不支持系统安装。因此我使用Homebrew 安装它。
首先,我似乎没有上面安装教程中显示的绿色“运行”按钮。在那里我只能通过右键单击和“在 Python 终端中运行选择/行”来运行代码。
一个简单的print('Hello, World!') 似乎可以正常运行,但是当我尝试运行一个包含多行(即多条指令)的程序时,我收到了多个错误消息,这些错误消息是我之前使用Anaconda 时没有得到的.
对于上下文:我目前正在学习使用 Python 进行编程,并遵循“使用 Python 自动化无聊的东西”一书。
我尝试运行的代码是:
#! python3
# mclip.py - A multi-clipboard program.
TEXT = {'agree': """Yes, I agree. That sounds fine to me.""",
'busy': """Sorry, can we do this later this week or next week?""", 'upsell': """Would you consider making this a monthly donation?"""}
import sys, pyperclip
if len(sys.argv) < 2:
print('Usage: py mclip.py [keyphrase] - copy phrase text')
sys.exit()
keyphrase = sys.argv[1] # first command line arg is the keyphrase
if keyphrase in TEXT:
pyperclip.copy(TEXT[keyphrase])
print('Text for ' + keyphrase + ' copied to clipboard.')
else:
print('There is no text for ' + keyphrase)
为了澄清:
Traceback (most recent call last): File "/Users/XXX/Desktop/Python Projects/Ex.py", line 7, in <module> import sys, pyperclip ModuleNotFoundError: No module named 'pyperclip'
是我得到的错误。
我只是想正确使用 Visual Studio Code,但我真的不知道为什么它不工作或者我在安装它时做错了什么。 (例如,为什么我错过了绿色的“运行”按钮?!)
【问题讨论】:
-
你遇到了什么错误?
-
I get multiple error messages——比如...? -
例如:无法导入“pyperclip”。我是否安装了“lint”,这似乎是一个 PATH 问题。
-
我自己已经解决了。还是谢谢!