47

python、pipなどのLinuxバージョンをWindowsで「ネイティブに」実行するのは素晴らしいことですが、適切なIDEを使用して実行したいと思います。SSHD 互換はまだ実装されていないので、PyCharm に Linux python をローカル インタープリターとして認識させようとしています。

Windows Linux サブシステムをインストールした後、次のように入力します。

bash -c python

Windows コマンド ラインから を実行すると、Python シェルにドロップされます。

bash -c "echo \"print 'hello world'\" | python" 

同様に機能し、Windows シェルの出力として "hello world" を生成します!

これを .bat ファイルとしてラップし、ローカル インタープリターとして PyCharm に提示しようとしています。

python.bat:

C:\Windows\System32\bash.exe -c "echo %1 | python" 

しかし、私が試したどのバリエーションでも「sdkが無効のようです」というメッセージが表示され続けます。SDKを「検証」するためにPyCharmが何をしているのか正確にはわからないため、これを克服するのは困難です。

4

7 に答える 7

5

さて、私は醜い実用的なハックを作成することができました. 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 の出力をパイプすると、エラーが発生します。

お役に立てれば。

更新: ひどいパイプ処理エラーを回避するために、「bash」への呼び出しを「START」でラップしました ( https://wpdev.uservoice.com/forums/266908-command-prompt-console-bash-on-ubuntu-onを参照) -windo/suggestions/13425768-allow-windows-programs-to-spawn-bash )

于 2016-05-03T12:58:28.480 に答える
4

リモート int 経由でサポートされます。最後のコメントを参照してください: https://youtrack.jetbrains.com/issue/PY-19129

于 2016-06-14T20:26:18.433 に答える