このwikiHowでは、Windowsコンピューターに組み込まれているコマンドプロンプトプログラムを使用してPythonファイルを開く方法を説明します。ほとんどの場合、Python がインストールされていれば、これは簡単に実行できます。古いバージョンの Python をインストールした場合、またはカスタム インストールを使用していて、コンピューターの「PATH」変数リストに「Python」コマンドを追加しなかった場合、「コマンド プロンプト」から Python ファイルを実行する前に、Python を「PATH」変数リストに追加する必要があります。
ステップ パート1 パート 1/3: Pythonファイルパスを見つける {"smallUrl":"https:\/\/www.wikihow.com\/images_en\/thumb\/1\/1c\/Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-1.jpg\/v4-460px-Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-1.jpg","bigUrl":"https:\/\/www.wikihow.com\/i mages\/thumb\/1\/1c\/Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-1.jpg\/v4-728px-Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-1.jpg","smallWidth":460,"smallHeight":342,"bigWidth":728,"bigHeight":542,"licensing":"<div class=\"mw-parser-output\"><\/div>"} 1Python ファイルの場所に移動します。 コマンドプロンプトで開きたい Python ファイルを見つけます。開きたい Python ファイルのフォルダー パスが既にわかっている場合は、コマンド プロンプトでファイルを直接開きます。 {"smallUrl":"https:\/\/www.wikihow.com\/images_en\/thumb\/3\/3d\/Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-2.jpg\/v4-460px-Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-2.jpg","bigUrl":"https:\/\/www.wikihow.com\/i mages\/thumb\/3\/3d\/Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-2.jpg\/v4-728px-Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-2.jpg","smallWidth":460,"smallHeight":349,"bigWidth":728,"bigHeight":553,"licensing":"<div class=\"mw-parser-output\"><\/div>"} 2Python ファイルを選択します。 Python ファイルをクリックすると、フォルダー パスが表示されます。 {"smallUrl":"https:\/\/www.wikihow.com\/images_en\/thumb\/8\/80\/Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-3.jpg\/v4-460px-Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-3.jpg","bigUrl":"https:\/\/www.wikihow.com\/i mages\/thumb\/8\/80\/Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-3.jpg\/v4-728px-Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-3.jpg","smallWidth":460,"smallHeight":342,"bigWidth":728,"bigHeight":542,"licensing":"<div class=\"mw-parser-output\"><\/div>"} 3Python ファイルを右クリックします。 これにより、ドロップダウン メニューが表示されます。 {"smallUrl":"https:\/\/www.wikihow.com\/images_en\/thumb\/a\/a9\/Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-4.jpg\/v4-460px-Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-4.jpg","bigUrl":"https:\/\/www.wikihow.com\/i mages\/thumb\/a\/a9\/Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-4.jpg\/v4-728px-Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-4.jpg","smallWidth":460,"smallHeight":342,"bigWidth":728,"bigHeight":542,"licensing":"<div class=\"mw-parser-output\"><\/div>"} 4 「プロパティ」 をクリックします。 ドロップダウンメニューにあります。プロパティ ウィンドウが開きます。 {"smallUrl":"https:\/\/www.wikihow.com\/images_en\/thumb\/1\/1e\/Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-5.jpg\/v4-460px-Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-5.jpg","bigUrl":"https:\/\/www.wikihow.com\/i mages\/thumb\/1\/1e\/Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-5.jpg\/v4-728px-Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-5.jpg","smallWidth":460,"smallHeight":349,"bigWidth":728,"bigHeight":552,"licensing":"<div class=\"mw-parser-output\"><\/div>"} 5 「position」の値に注意してください。 Python ファイルが保存されているディレクトリに変更するときに、コマンド プロンプトの「場所」見出しの右側にフォルダー アドレス (または「パス」) を入力する必要があります。位置をハイライト表示し(マウスをクリックして位置の値の上にドラッグ)、 Ctrl + C を押すことで、位置をコピーできます。 広告する パート2 パート 2/3: Python ファイルの実行 {"smallUrl":"https:\/\/www.wikihow.com\/images_en\/thumb\/c\/c7\/Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-6.jpg\/v4-460px-Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-6.jpg","bigUrl":"https:\/\/www.wikihow.com\/i mages\/thumb\/c\/c7\/Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-6.jpg\/v4-728px-Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-6.jpg","smallWidth":460,"smallHeight":344,"bigWidth":728,"bigHeight":545,"licensing":"<div class=\"mw-parser-output\"><\/div>"} 1「スタート」を開く{"smallUrl":"https:\/\/www.wikihow.com\/images_en\/0\/07\/Windowsstart.png","bigUrl":"https:\/\/www.wikihow.com\/images\/thumb\/0\/07\/Windowsstart.png\/30px-Windowsstart.png","smallWidth":460,"smallHeight":460,"bigWidth":30,"bigHeight":30,"licensing":"<div class=\"mw-parser-output\"><\/div>"} . 画面の左下隅にある Windows ロゴをクリックします。スタートメニューがポップアップ表示されます。 {"smallUrl":"https:\/\/www.wikihow.com\/images_en\/thumb\/9\/9e\/Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-7.jpg\/v4-460px-Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-7.jpg","bigUrl":"https:\/\/www.wikihow.com\/i mages\/thumb\/9\/9e\/Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-7.jpg\/v4-728px-Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-7.jpg","smallWidth":460,"smallHeight":342,"bigWidth":728,"bigHeight":542,"licensing":"<div class=\"mw-parser-output\"><\/div>"} 2「コマンドプロンプト」を検索します。 cmd と入力するだけです。 {"smallUrl":"https:\/\/www.wikihow.com\/images_en\/thumb\/a\/ac\/Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-8.jpg\/v4-460px-Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-8.jpg","bigUrl":"https:\/\/www.wikihow.com\/i mages\/thumb\/a\/ac\/Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-8.jpg\/v4-728px-Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-8.jpg","smallWidth":460,"smallHeight":347,"bigWidth":728,"bigHeight":549,"licensing":"<div class=\"mw-parser-output\"><\/div>"} 3クリック{"smallUrl":"https:\/\/www.wikihow.com\/images_en\/6\/66\/Windowscmd1.png","bigUrl":"https:\/\/www.wikihow.com\/images\/thumb\/6\/66\/Windowscmd1.png\/36px-Windowscmd1.png","smallWidth":460,"smallHeight":383,"bigWidth":36,"bigHeight":30,"licensing":"<div class=\"mw-parser-output\"><\/div>"} “コマンド プロンプト”。 スタートメニューの上部にあります。コマンドプロンプトが開きます。 {"smallUrl":"https:\/\/www.wikihow.com\/images_en\/thumb\/9\/9f\/Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-9.jpg\/v4-460px-Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-9.jpg","bigUrl":"https:\/\/www.wikihow.com\/i mages\/thumb\/9\/9f\/Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-9.jpg\/v4-728px-Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-9.jpg","smallWidth":460,"smallHeight":343,"bigWidth":728,"bigHeight":543,"licensing":"<div class=\"mw-parser-output\"><\/div>"} 4 Python ファイルのディレクトリに切り替えます。 cd とスペースを入力し、Python ファイルの場所を入力して、 ↵ Enter を 押します。たとえば、デスクトップ上の「Files」というフォルダにある Python ファイルを開くには、ここでcd desktop/Files と入力します。 ファイル パスをコピーした場合は、 cd とスペースを入力してから、 Ctrl + V を押してパスを貼り付けます。 {"smallUrl":"https:\/\/www.wikihow.com\/images_en\/thumb\/8\/80\/Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-10.jpg\/v4-460px-Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-10.jpg","bigUrl":"https:\/\/www.wikihow.com\/i mages\/thumb\/8\/80\/Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-10.jpg\/v4-728px-Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-10.jpg","smallWidth":460,"smallHeight":342,"bigWidth":728,"bigHeight":541,"licensing":"<div class=\"mw-parser-output\"><\/div>"} 5「python」コマンドとファイル名を入力します。 python file.py と入力します。ここで、 file は Python ファイルの名前です。たとえば、Python ファイルの名前が「script」の場合、 「python script.py」 と入力します。 Python ファイルの名前に 1 つ以上のスペースが含まれている場合は、ファイル名と拡張子を引用符で囲む必要があります (例: python "my script.py" )。 {"smallUrl":"https:\/\/www.wikihow.com\/images_en\/thumb\/7\/70\/Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-11.jpg\/v4-460px-Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-11.jpg","bigUrl":"https:\/\/www.wikihow.com\/i mages\/thumb\/7\/70\/Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-11.jpg\/v4-728px-Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-11.jpg","smallWidth":460,"smallHeight":342,"bigWidth":728,"bigHeight":541,"licensing":"<div class=\"mw-parser-output\"><\/div>"} 6 ↵ Enter を 押します。 こうすると、コマンドが実行され、コンピューターにインストールされている Python プログラムで Python ファイルが開きます。 Enter キー を押した後に「python」が内部コマンドまたは外部コマンド'python' is not recognized as an internal or external command
ないというエラーが表示される場合は、python を PATH リストに追加して再試行する必要があります。 広告する パート 3パート 3/3: PATHリストにPythonを追加する {"smallUrl":"https:\/\/www.wikihow.com\/images_en\/thumb\/8\/80\/Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-12.jpg\/v4-460px-Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-12.jpg","bigUrl":"https:\/\/www.wikihow.com\/i mages\/thumb\/8\/80\/Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-12.jpg\/v4-728px-Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-12.jpg","smallWidth":460,"smallHeight":348,"bigWidth":728,"bigHeight":550,"licensing":"<div class=\"mw-parser-output\"><\/div>"} 1隠しフォルダの表示を有効にします。 Python インストール フォルダーが配置されているフォルダーは非表示になっている可能性が高いため、続行する前に非表示を解除する必要があります。ファイルエクスプローラーを開きます。 [表示] タブをクリックします。 「隠しアイテム」ボックスをチェックします。 {"smallUrl":"https:\/\/www.wikihow.com\/images_en\/thumb\/3\/39\/Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-13.jpg\/v4-460px-Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-13.jpg","bigUrl":"https:\/\/www.wikihow.com\/i mages\/thumb\/3\/39\/Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-13.jpg\/v4-728px-Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-13.jpg","smallWidth":460,"smallHeight":348,"bigWidth":728,"bigHeight":551,"licensing":"<div class=\"mw-parser-output\"><\/div>"} 2 Python フォルダーを見つけます。 場合によっては、Python パスは「C:\Python27」ですが、デフォルト設定を使用して最新バージョンの Python をインストールした場合は、隠しフォルダーにあります。次の手順に従って正しいファイル パスをコピーできます。ファイルエクスプローラーの左側にある「このPC」 をクリックします。 [デバイスとドライブ] セクションでハード ディスクをダブルクリックします。 下にスクロールして、「Users」フォルダをダブルクリックします。 ユーザー名が含まれるフォルダーをダブルクリックします。 下にスクロールして「AppData」をダブルクリックします。 [ローカル]をダブルクリックします。 下にスクロールして、「プログラム」をダブルクリックします。 Python フォルダをダブルクリックします。 選択したバージョン番号 (たとえば、「Python36」) の Python フォルダーをダブルクリックします。 {"smallUrl":"https:\/\/www.wikihow.com\/images_en\/thumb\/3\/34\/Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-14.jpg\/v4-460px-Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-14.jpg","bigUrl":"https:\/\/www.wikihow.com\/i mages\/thumb\/3\/34\/Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-14.jpg\/v4-728px-Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-14.jpg","smallWidth":460,"smallHeight":345,"bigWidth":728,"bigHeight":546,"licensing":"<div class=\"mw-parser-output\"><\/div>"} 3 Python フォルダーへのパスをコピーします。 ファイル エクスプローラーの上部にあるアドレス バーをクリックしてその内容を強調表示し、 Ctrl + C を押して強調表示されたアドレスをコピーします。 {"smallUrl":"https:\/\/www.wikihow.com\/images_en\/thumb\/0\/0f\/Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-15.jpg\/v4-460px-Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-15.jpg","bigUrl":"https:\/\/www.wikihow.com\/i mages\/thumb\/0\/0f\/Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-15.jpg\/v4-728px-Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-15.jpg","smallWidth":460,"smallHeight":344,"bigWidth":728,"bigHeight":545,"licensing":"<div class=\"mw-parser-output\"><\/div>"} 4「スーパーユーザー」メニューを開きます。 スタート {"smallUrl":"https:\/\/www.wikihow.com\/images_en\/0\/07\/Windowsstart.png","bigUrl":"https:\/\/www.wikihow.com\/images\/thumb\/0\/07\/Windowsstart.png\/30px-Windowsstart.png","smallWidth":460,"smallHeight":460,"bigWidth":30,"bigHeight":30,"licensing":"<div class=\"mw-parser-output\"><\/div>"} アイコンを右クリックします。ポップアップ メニューが表示されます。 ⊞ Win + X を押してパワーユーザーポップアップメニューを開くこともできます。 {"smallUrl":"https:\/\/www.wikihow.com\/images_en\/thumb\/d\/d8\/Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-16.jpg\/v4-460px-Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-16.jpg","bigUrl":"https:\/\/www.wikihow.com\/i mages\/thumb\/d\/d8\/Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-16.jpg\/v4-728px-Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-16.jpg","smallWidth":460,"smallHeight":344,"bigWidth":728,"bigHeight":545,"licensing":"<div class=\"mw-parser-output\"><\/div>"} 5クリックシステム 。 ポップアップメニューにあります。クリックすると新しいウィンドウが開きます。 {"smallUrl":"https:\/\/www.wikihow.com\/images_en\/thumb\/c\/c8\/Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-17.jpg\/v4-460px-Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-17.jpg","bigUrl":"https:\/\/www.wikihow.com\/i mages\/thumb\/c\/c8\/Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-17.jpg\/v4-728px-Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-17.jpg","smallWidth":460,"smallHeight":346,"bigWidth":728,"bigHeight":547,"licensing":"<div class=\"mw-parser-output\"><\/div>"} 6 「システム情報」 をクリックします。 ウィンドウの右上隅にあるリンクです。これにより、システム情報ウィンドウが開きます。 {"smallUrl":"https:\/\/www.wikihow.com\/images_en\/thumb\/d\/d4\/Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-18.jpg\/v4-460px-Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-18.jpg","bigUrl":"https:\/\/www.wikihow.com\/i mages\/thumb\/d\/d4\/Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-18.jpg\/v4-728px-Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-18.jpg","smallWidth":460,"smallHeight":344,"bigWidth":728,"bigHeight":544,"licensing":" class=\"mw-parser-output\"><\/div>"} 7 「システムの詳細設定」 リンクをクリックします。 これはシステム情報ウィンドウの左上隅に表示されます。これにより、別のウィンドウがポップアップ表示されます。 {"smallUrl":"https:\/\/www.wikihow.com\/images_en\/thumb\/9\/9b\/Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-19.jpg\/v4-460px-Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-19.jpg","bigUrl":"https:\/\/www.wikihow.com\/i mages\/thumb\/9\/9b\/Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-19.jpg\/v4-728px-Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-19.jpg","smallWidth":460,"smallHeight":343,"bigWidth":728,"bigHeight":543,"licensing":"<div class=\"mw-parser-output\"><\/div>"} 8 「環境変数…」 をクリックします。 ポップアップウィンドウの右下隅にあります。 {"smallUrl":"https:\/\/www.wikihow.com\/images_en\/thumb\/4\/41\/Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-20.jpg\/v4-460px-Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-20.jpg","bigUrl":"https:\/\/www.wikihow.com\/i mages\/thumb\/4\/41\/Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-20.jpg\/v4-728px-Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-20.jpg","smallWidth":460,"smallHeight":348,"bigWidth":728,"bigHeight":551,"licensing":"<div class=\"mw-parser-output\"><\/div>"} 9 「ユーザー変数」ペインで「PATH」見出しを見つけます。 このペインは、環境変数ウィンドウの上部にあります。 PATH 変数を見つけるには、マウス カーソルを [ユーザー変数] ペインの上に置いて、上または下にスクロールする必要がある場合があります。 {"smallUrl":"https:\/\/www.wikihow.com\/images_en\/thumb\/8\/85\/Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-21.jpg\/v4-460px-Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-21.jpg","bigUrl":"https:\/\/www.wikihow.com\/i mages\/thumb\/8\/85\/Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-21.jpg\/v4-728px-Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-21.jpg","smallWidth":460,"smallHeight":341,"bigWidth":728,"bigHeight":540,"licensing":"<div class=\"mw-parser-output\"><\/div>"} 10 「PATH」見出しをダブルクリックします。 ポップアップウィンドウが開きます。 {"smallUrl":"https:\/\/www.wikihow.com\/images_en\/thumb\/4\/46\/Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-22.jpg\/v4-460px-Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-22.jpg","bigUrl":"https:\/\/www.wikihow.com\/i mages\/thumb\/4\/46\/Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-22.jpg\/v4-728px-Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-22.jpg","smallWidth":460,"smallHeight":348,"bigWidth":728,"bigHeight":551,"licensing":"<div class=\"mw-parser-output\"><\/div>"} 11 「新規」 をクリックします。 それはウィンドウの右側にあります。ウィンドウの中央にテキスト フィールドが開きます。 {"smallUrl":"https:\/\/www.wikihow.com\/images_en\/thumb\/a\/aa\/Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-23.jpg\/v4-460px-Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-23.jpg","bigUrl":"https:\/\/www.wikihow.com\/i mages\/thumb\/a\/aa\/Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-23.jpg\/v4-728px-Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-23.jpg","smallWidth":460,"smallHeight":347,"bigWidth":728,"bigHeight":549,"licensing":"<div class=\"mw-parser-output\"><\/div>"} 12コピーしたパスを貼り付けます。 実行するにはCtrl + V を押します。コピーしたパスは、ウィンドウの中央にあるテキスト フィールドに表示されます。 {"smallUrl":"https:\/\/www.wikihow.com\/images_en\/thumb\/8\/82\/Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-24-Version-2.jpg\/v4-460px-Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-24-Version-2.jpg","bigUrl":"https:\/\/www.wikihow.com\/i mages\/thumb\/8\/82\/Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-24-Version-2.jpg\/v4-728px-Use-Windows-Command-Prompt-to-Run-a-Python-File-Step-24-Version-2.jpg","smallWidth":460,"smallHeight":344,"bigWidth":728,"bigHeight":544,"licensing":"<div class=\"mw-parser-output\"><\/div>"} 13開いている 3 つのウィンドウで[OK] を クリックします。 これにより、変更が保存され、PATH ウィンドウ、環境変数ウィンドウ、およびシステム プロパティ ウィンドウが閉じます。 広告する