当运行Linux版本的python,pip等。在windows上“原生”是很神奇的,我想用一个合适的IDE来做。由于SSHD兼容性尚未实现,我正在尝试让PyCharm将Linux python识别为本地解释器。
安装Windows Linux子系统后,键入
bash -c python从windows命令行会把你放到python shell中。
bash -c "echo \"print 'hello world'\" | python" 同样有效,在windows shell中生成"hello world“作为输出!
我正在尝试将其包装为.bat文件,并将其作为本地解释器呈现给PyCharm。
python.bat:
C:\Windows\System32\bash.exe -c "echo %1 | python" 但是对于我尝试的任何变体,我总是收到“sdk似乎无效”的提示。因为我不确定PyCharm正在做什么来“验证”SDK,这是很难克服的。
发布于 2018-10-21 08:58:19
我尝试了大多数的解决方案,但是主要的问题是我不能像JetBrains推荐的那样将Windows上的OpenSSH降级到7.5以下。
幸运的是他们已经为我们解决了这个问题!我已经下载了Pycharm 2018.3的早期访问版本
https://blog.jetbrains.com/pycharm/2018/10/pycharm-2018-3-eap-7/

但是,这仅在专业版本中可用。
发布于 2017-08-03 18:58:33
我想补充一下bmjjr的答案,说明这是只在PyCharm专业版中提供的。正如我遗憾地发现的那样,Community Edition不提供远程解释器功能:
仅在专业版中支持
https://www.jetbrains.com/pycharm/features/editions_comparison_matrix.html
发布于 2016-05-03 20:58:28
好吧,我已经成功地创造了一个丑陋的工作黑客。您必须在Linux子系统下手动安装python-setuptools和pip。请务必使用PyCharm提供的pip版本,您将在类似如下的路径中找到它:
C:\Program Files (x86)\JetBrains\PyCharm 2016.1.2\helpers\pip-7.1.0.tar.gz
然后在"c:\Python“下将以下脚本设置为"python.bat”,并将PyCharm指向该脚本作为解释器:
@echo off
@setlocal enableextensions enabledelayedexpansion
:: Requiers pip and setuptools to already be installed on linux subsystem
Set "Pattern= "
Set "Replace=\ "
Set "cdrive=C:"
Set "linpath=/mnt/c"
:: Iterate over arguments, convert paths to linux format and concatinate
set argCount=0
for %%x in (%*) do (
set /A argCount+=1
set arg=%%x
:: Backward slash to forward slash
SET arg=!arg:\=/!
:: C drive to /mnt/c/ - default linux subsystem mount point
SET arg=!arg:%cdrive%=%linpath%!
:: Space to escaped space
SET arg=!arg:%Pattern%=%Replace%!
:: Parethesis to escaped parenteses
SET arg=!arg:^(=\^(!
SET arg=!arg:^)=\^)%!
:: Deqoute voodoo via http://ss64.com/nt/syntax-dequote.html
SET arg=###!arg!###
SET arg=!arg:"###=!
SET arg=!arg:###"=!
SET arg=!arg:###=!
if "!args!"=="" (
set args=!arg!
) else (
set args=!args! !arg!
)
)
:: Dump it to the interpreter
:: Output is piped inside the Linux subsys, as windows piping for bash seems broken
START "Terrible hack to avoid pipe error" /W /MIN C:\Windows\System32\bash.exe -c "python !args! > /mnt/c/Python/test"
:: Output resulr from piped file
type c:\Python\test
:: echo !args!
EXIT /B > NUL请原谅糟糕的编码风格,因为我以前从未真正开发过windows批处理文件。
您可能需要调整目录结构以匹配您的系统。还要注意,Python.bat调用的任何python脚本的输出都通过管道传输到linux子系统下的一个临时文件,然后在windows下重新输入。由于某些原因,通过windows管道传输bash.exe的输出会导致错误。
希望这能有所帮助。
更新:使用"START“包装对"bash”的调用,以避免可怕的管道处理错误(c.f.https://wpdev.uservoice.com/forums/266908-command-prompt-console-bash-on-ubuntu-on-windo/suggestions/13425768-allow-windows-programs-to-spawn-bash)
https://stackoverflow.com/questions/37000166
复制相似问题