VS Code 代码运行器不适用于 virtualenvs [英] VS Code Code Runner doesn't work with virtualenvs

查看:16
本文介绍了VS Code 代码运行器不适用于 virtualenvs的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法让 Code Runner 扩展与 virtualenvs 一起使用.每当我尝试运行导入仅安装在 virtualenv 而不是全局 Python 安装中的库的代码时,我都会收到导入错误.在终端中运行完全相同的代码.

I can't get Code Runner extension to work with virtualenvs. Whenever I try to run code that imports a library that is installed only in the virtualenv and not in the global Python installation I get an import error. Running the exact same code in terminal works.

我使用的是 Windows 10 并且安装了 Python 3.6.5.

I am on Windows 10 and I have Python 3.6.5 installed.

我得到的准确错误是:

ModuleNotFoundError: No module named 'bs4'

推荐答案

我也遇到了同样的问题.

I also faced same issue.

我发现最好的解决方案是将此行添加到您的用户或工作区设置(以适合您的项目为准):

solution which i found best is just add this line to your user or workspace settings(whichever is suits your projects):

"code-runner.executorMap": {
    "python": "C:\\Users\\adarsh_patel\\VisualCode\\env\\Scripts\\activate.bat && python -u",
}

您必须输入您的 virtualenv 路径,否则您可以使用.

you have to enter your virtualenv path or you could use.

"code-runner.executorMap": {"python":"$pythonPath $fullFileName"}

希望对你有帮助.

这篇关于VS Code 代码运行器不适用于 virtualenvs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆