Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การแก้ไขปัญหา >> ข้อผิดพลาด Windows

แก้ไข: Python is not recognized as an internal or external command

ด้วยความนิยมของ Python ที่เพิ่มขึ้น เข้าใจได้ว่าผู้ใช้หลายรายพยายามรันคำสั่ง Python จาก Windows Command Prompt แต่ปัญหาคือ หากคุณไม่ระบุ full path ของ Python สำหรับแต่ละคำสั่ง คุณจะได้ข้อผิดพลาดว่า 「Python is not recognized as an internal or external command, operable program or batch file.」

แก้ไข: Python is not recognized as an internal or external command

สาเหตุของข้อผิดพลาด Python is not recognized as an internal or external command

ข้อผิดพลาดนี้เกิดขึ้นเพราะผู้ใช้ไม่ได้ระบุ full path ของ Python distribution สำหรับคำสั่งให้สำเร็จในสถานะปัจจุบัน ผู้ใช้จะต้องระบุ full path ของ Python distribution ภายในคำสั่ง

หากคุณต้องการรันคำสั่ง Python โดยไม่ต้องเพิ่ม full path ของ Python ทุกคำสั่ง คุณต้องเพิ่ม Python ลงใน Windows Path ด้วยตนเอง การทำอย่างนี้อาจสับสนหากคุณไม่เคยทำมาก่อน

เพื่อทำให้ง่ายขึ้น เราสร้างคู่มือขั้นตอนที่จะพาคุณผ่านกระบวนการเพิ่ม Python path ลงใน Windows environment

เพิ่ม Python ลงใน Windows PATH

เพื่อให้ขั้นตอนนี้สำเร็จ คุณต้องแน่ใจว่า Python distribution ติดตั้งถูกต้องบนเครื่องของคุณ

อัปเดต: Windows installer ของ Python 3.3 (หรือใหม่กว่า) รวมตัวเลือกที่จะเพิ่ม python.exe ลงใน system search path อัตโนมัติ การใช้วิธีติดตั้งนี้จะประหยัดคุณจากขั้นตอนด้านล่าง คุณสามารถดาวน์โหลดเวอร์ชัน web installer ล่าสุดของ Python จากลิงก์นี้ (ที่นี่) คุณจะต้องดาวน์โหลดและรัน x86 หรือ x64 Windows Executable installer ที่เหมาะสม ขึ้นอยู่กับ CPU architecture ของคุณ

แก้ไข: Python is not recognized as an internal or external command

หากคุณติดตั้ง Python ไว้แล้ว ขั้นตอนด้านล่างจะแสดงวิธีเพิ่ม Python ลงใน Windows path การทำสำเร็จจะทำให้คุณรันคำสั่ง Python จาก Command Prompt ได้โดยไม่ต้องระบุ full path ของ Python ทุกคำสั่ง ขั้นตอนต่อไปนี้เข้ากันได้กับ Windows 7, Windows 8 (8.1) และ Windows 10

  1. กด Windows key + Pause key เปิดเมนู System Properties หรือคลิกขวา Computer (This PC) ในเมนู Start เลือก Propertiesแก้ไข: Python is not recognized as an internal or external command
  2. ในเมนู System Properties คลิกลิงก์ Advanced system settings ใช้ sidebar ด้านซ้ายแก้ไข: Python is not recognized as an internal or external command
  3. ในเมนู System Properties ไปที่แท็บ Advanced คลิกปุ่ม Environment Variables (ส่วนล่างของหน้าจอ)แก้ไข: Python is not recognized as an internal or external command
  4. ในเมนู Environment Variables เลือก entry Path ในส่วน System variables แล้วกดปุ่ม Editแก้ไข: Python is not recognized as an internal or external command
  5. กดปุ่ม New เพิ่ม path ของ Python ที่ท้ายรายการ โปรดทราบว่าคุณสามารถแยกหลาย path ด้วย semicolons
    แก้ไข: Python is not recognized as an internal or external command
  6. กด Ok บันทึกการเปลี่ยนแปลง แล้วลองรันคำสั่ง Python จาก Command Prompt หากขั้นตอนข้างต้นทำถูกต้อง คุณจะไม่มีปัญหาในการป้อนคำสั่งโดยไม่ต้องระบุ full Python path