vscode ImportError: No module named xxx

VSCODE 点击右上角运行按钮,报错如下:

[Running] python -u "test.py"
Traceback (most recent call last):
  File "test.py", line 3, in <module>
    from PIL import Image, ImageEnhance
ImportError: No module named PIL

[Done] exited with code=1 in 0.231 seconds

直接命令行下运行,没有任何报错

python3 test.py

写个test_evn.py 测试python默认执行环境

#!/usr/local/bin/python3.6
import sys
print (sys.path)

结果:

[Running] python -u "/Users/your_name/test.py"
['/Users/your_name', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload', '/Library/Python/2.7/site-packages', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC']

[Done] exited with code=0 in 0.137 seconds

问题找到了,现在解决问题,找到vscode默认的执行配置文件
mac 组合键:command + shift + p
输入:setting
在这里插入图片描述

选择红框点击,进入 command+F 搜索 python -u
在这里插入图片描述
提前编辑好如下json格式

"code-runner.executorMap": {
	"python": "python3 -u",
}

继续 command + shift + p 搜索 setting
然后选择如下红框setting文件
在这里插入图片描述
把上边编辑好的json 放入到选择的文件 setting.json尾部:

{
	"editor.fontSize": 16,
	"fileheader.configObj": {
	  
	},
	"code-runner.executorMap": {
		"python": "python3 -u",
	}
}

再次执行之前的test.py 文件,成功了!

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值