使用WSL解释器在VScode中使用AREPL

时间:2019-07-22 21:03:35

标签: visual-studio-code python-venv

我有一个运行python和venv的WSL环境。 除此之外,我还使用AREPL在Windows中运行了VSCode

使用VSCode终端访问我的python venv(包括pip模块)没有问题。但是,AREPL似乎无法识别我的pip插件。我的猜测是AREPL正在使用Windows Python版本立即运行代码。但是,WSL python venv不会生成python.exe,我可以将AREPL解释器指向它。

所以我的问题是:

我可以在Windows VSCode上运行AREPL来验证需要在Windows中未安装但在venv中的WSL上安装了PIP模块的代码。

我尝试过将AREPL Python路径更改为Python venv,WSL或Windows Python:

"D:\Scripting\Python\venvs\automation\bin\python"
"C:\Windows\System32\wsl.exe" (nothing happens as I type)
"C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.1264.0_x64__qbz5n2kfra8p0\python.exe" (generates error)

使用venv位置时出错:

Error in the AREPL extension!
Error running python with command:           D:\Scripting\Python\venvs\automation\bin\python -u C:\Users\user\.vscode\extensions\almenon.arepl-1.0.16\node_modules\arepl-backend\python\python_evaluator.py
Error: spawn D:\Scripting\Python\venvs\automation\bin\python ENOENT
    at Process.ChildProcess._handle.onexit (internal/child_process.js:232:19)
    at onErrorNT (internal/child_process.js:407:16)
    at process._tickCallback (internal/process/next_tick.js:63:19)

Are you sure you have installed python 3 and it is in your PATH?
            You can download python here: https://www.python.org/downloads/

使用WSL时出错:

Nothing happens

使用Windows python时出错:

Traceback (most recent call last):
  line 1, in <module>
ModuleNotFoundError: No module named 'requests'

1 个答案:

答案 0 :(得分:0)

AREPL的制造商在这里!抱歉,直到最近我才看到此消息,希望对您有所帮助。要在Windows vscode中使用WSL python,可以将pythonpath设置为wsl,将pythonoptions设置为["python3", "-u"]。当您打开它时,您会得到......

一个错误。 ang

问题是我使用的python-shell库使用path.join,它使用Windows路径分隔符将路径连接到arepl执行程序文件,在WSL中不起作用。

我建议不要安装remote-wsl,打开WSL vscode,在其中安装python和arepl扩展名并使用它,而不是尝试通过Windows vscode运行WSL python。我对其进行了测试,并验证了它是否有效。