How to Add Python to XAMPP?

8 minutes read

To add Python to XAMPP, follow these steps:

  1. Download and install XAMPP from the official Apache Friends website.
  2. Download and install Python from the official Python website.
  3. Open the XAMPP installation folder (usually located in C:\xampp).
  4. Locate the "xampp-control" executable file and double-click it to launch the XAMPP Control Panel.
  5. Start the Apache web server by clicking the "Start" button next to it in the XAMPP Control Panel.
  6. Create a new Python file with the .py extension (e.g., using a text editor or an Integrated Development Environment (IDE).
  7. Write your Python code within the created file.
  8. Save the Python file in the XAMPP htdocs directory. By default, it is located in the XAMPP installation folder under "htdocs" (e.g., C:\xampp\htdocs).
  9. Open a web browser and navigate to "localhost/" to run your Python script in XAMPP.
  10. Ensure that your Python file contains the necessary HTTP headers (e.g., Content-Type header) for the web browser to interpret it correctly.
  11. You can now execute Python code within XAMPP and see the script's output in the web browser.

Remember to stop the Apache server from the XAMPP Control Panel when you are not using it to prevent any security or performance issues.

Best Cloud Hosting Providers in 2024


Rating is 5 out of 5


  • Ultra-fast Intel Core
  • High Performance and Cheap Cloud Dedicated Servers
  • 1 click install Wordpress
  • Low Price and High Quality
Digital Ocean

Rating is 5 out of 5

Digital Ocean

  • Active Digital Community
  • Simple Control Panel
  • Starting from 5$ per month

Rating is 5 out of 5



Rating is 5 out of 5


How to run Python scripts within XAMPP?

To run Python scripts within XAMPP, you can follow these steps:

  1. Install XAMPP: Download and install XAMPP from the official Apache Friends website.
  2. Start the Apache server: Launch the XAMPP control panel and start the Apache server by clicking on the "Start" button next to Apache.
  3. Locate the htdocs folder: By default, XAMPP creates a folder named "htdocs" in the installation directory. This is the folder where you will place your Python script.
  4. Create a new folder: Inside the htdocs folder, create a new folder for your Python project. For example, you can create a folder named "python_project".
  5. Write your Python script: Create a new file inside the newly created folder with a ".py" extension, and write your Python code in that file. For example, create a file named "" inside the "python_project" folder.
  6. Enable CGI in Apache: Open the "httpd.conf" file located in the "apache" folder of your XAMPP installation directory. Look for the following line: "#LoadModule cgi_module modules/". Remove the "#" at the beginning of the line to enable CGI.
  7. Configure Apache to run Python scripts: In the same "httpd.conf" file, search for the "..." block that references the htdocs folder. Within that block, add the following lines:
AddHandler cgi-script .cgi .py
Options +ExecCGI

  1. Save the changes and restart Apache: Save the modifications to the "httpd.conf" file and restart Apache from the XAMPP control panel.
  2. Run the Python script: To access your Python script through a web browser, open a browser and enter the following URL: "http://localhost/python_project/". Replace "python_project" with the name of your project folder, and "" with the name of your Python script file.

Your Python script will now execute, and its output will be displayed in the browser.

What is XAMPP and why is it used with Python?

XAMPP stands for Cross-Platform (X), Apache (A), MariaDB/MySQL (M), PHP (P), and Perl (P). It is a free and open-source web server solution that enables users to develop and deploy web applications by providing the necessary server stack environment.

XAMPP is commonly used with Python primarily to create a local development environment for Python-based web applications. It allows developers to easily set up an Apache web server, MySQL database, and PHP interpreter, along with other necessary tools, on their own computer.

Python web frameworks like Django and Flask can be run on XAMPP for local development and testing purposes. It provides a convenient way to simulate the production environment locally before deploying the application to a remote server. By using XAMPP with Python, developers can work on their projects in a controlled and isolated environment without the need for a live internet connection.

How to troubleshoot issues related to Python integration in XAMPP?

  1. Ensure that Python is installed correctly and the correct version is being used. Check the Python installation path and confirm that it is added to the environment variables on your computer.
  2. Check if the necessary Python modules are installed and properly imported in your Python script. Use the pip command to install any missing modules and double-check the import statements in your code.
  3. Verify that XAMPP is correctly configured to use Python. Open the XAMPP control panel and ensure that the Apache server is running. Check the Apache configuration files (httpd.conf or php.ini) to confirm that the appropriate modules for Python integration are enabled.
  4. Check if the XAMPP installation directory contains the Python binding libraries. Navigate to the XAMPP installation folder and locate the apache or php directory. Check if the required Python binding libraries (mod_wsgi for Apache or php_python for PHP) are present.
  5. If you are using Apache, ensure that the httpd.conf file is configured properly for Python integration. Open the httpd.conf file and check if the following lines are present and uncommented: LoadModule wsgi_module modules/ AddHandler wsgi-script .wsgi
  6. Restart the Apache server after making any changes to the configuration files. Use the XAMPP control panel to stop and start the Apache server.
  7. Test the Python integration by running a simple Python script. Create a new Python file with a basic "Hello, World!" script and save it in the XAMPP htdocs directory. Access the script through a web browser by typing http://localhost/ and check if the page displays the expected output.
  8. Check the Apache error log if you encounter any issues. The error log can be found in the XAMPP installation directory under the apache/logs folder. Look for any error messages related to Python integration and investigate the cause based on the provided information.
  9. Consult online forums, discussion groups, or official documentation specific to the web framework you are using (e.g., Flask, Django) for additional troubleshooting steps.

What is the compatibility of Python versions with XAMPP?

Python itself is not directly compatible with XAMPP since XAMPP is a software stack that includes Apache, MySQL, PHP, and Perl, whereas Python is a programming language. However, you can integrate Python and XAMPP together by configuring XAMPP to work with Python.

To do this, you can use mod_wsgi, a module that allows Apache to serve Python web applications. Here is the compatibility between different Python versions and XAMPP:

  1. Python 2: Mod_wsgi supports Python 2.7.x versions which can be integrated with XAMPP.
  2. Python 3: Mod_wsgi also supports Python 3.x versions. However, there are separate packages for Python 2 and Python 3. Make sure you install the appropriate mod_wsgi package for your Python version.

Once you have installed the mod_wsgi package that matches your Python version, you need to configure Apache to use it. You can find documentation and tutorials on how to configure mod_wsgi with XAMPP on the official mod_wsgi website or other online resources.

Note that XAMPP primarily focuses on PHP development, so integrating Python may require additional work and configuration. Alternatively, if you wish to work with Python web development, it is recommended to use a dedicated web server framework for Python such as Flask or Django. These frameworks have built-in web servers and do not require XAMPP.

Facebook Twitter LinkedIn Telegram Whatsapp Pocket

Related Posts:

Starting the XAMPP control panel is a simple process. After installing XAMPP on your computer, follow these steps:Open the XAMPP installation folder on your computer. The default installation location is usually "C:\xampp" on Windows or "/Applicati...
To create a simple PHP file and run it in XAMPP, follow these steps:Install XAMPP: Download and install XAMPP from the Apache Friends website ( Choose the appropriate version for your operating system. Start XAMPP: Lau...
To run ASP.NET in XAMPP, you need to follow these steps:Install XAMPP: Go to the Apache Friends website and download the latest version of XAMPP. Follow the installation instructions prompted by the installer. Enable Apache modules: Once XAMPP is installed, op...