Setting Up a Simple Local Server Using Python in Windows

Bojitha Piyathilake
4 min readFeb 4, 2021

--

Aren’t you tired of plugging in your USB drive every single time you want to copy something from one device to another? Well there is a simple trick to setting up a local server which will let you share files between your various devices be it desktop, laptop or mobile. In this blog I will lay out the steps to set up a local python server to share files between devices connected to the same router. The commands included are for Windows. So if you are using a Mac, you will have to look elsewhere.

Below are the steps you need to go through to setup a simple python server;

  1. Installing Python
  • First, we need to check if you have python installed on your device.
  • Open up a command prompt by clicking on the windows key and typing in cmd and clicking enter.
  • Now type in python -V . If you have python successfully installed on your device it should show you the version number.
Checking python version
  • If it doesn't not show you the version number then you will have to download and install python on your device. Also note that it is only necessary to have python installed on the device which you want to host the server. Python can be downloaded from; https://www.python.org/downloads/
  • Installing python is quite simple. Select the location you want to install it or keep it default. Keep all the other settings default as well and click next until it is done.

2. Running the Server

  • Open up a terminal by typing cmd after clicking the windows button.
  • Navigate to the folder in which you will store the files that you wan to share. To do this in windows, copy the directory and paste it after cd command in the terminal;
Navigating to the required directory
  • To start the server run;

For Python 2;

python -m SimpleHTTPServer 8000

For Python 3;

python -m http.server 8000

Here 8000 refers to the port number the server will run on. It can be anything you want, however, numbers below 1024 may give you errors.

Executing the command to run the server

And that’s all there is to it. Now you’ve got a local server running on your machine.

Checking out your server;

  • In the same machine, open a web browser and search for http://localhost:8000/ . If your server is up and running it should show all the files in the folder which you have set up as the directory of the web server. Mine looks something like;
Files on my Python Server
  • Okay, now that’s all good, but what if you want to access these files from another device? Using localhost in this situation will create an issue. Instead you need to find the IP Address of the device which is hosting the server. In order to find it simply type in ipconfig into the terminal, scroll down to the bottom and note down the IPV4 address. It will typically be something like 192.168.x.x
Locating your IPV4 address
  • Now from whatever device you want to access the server, simply type in [IP address of the server machine]:8000

Troubleshooting;

  • If the above step causes your browser to keep on loading and doesn’t display the files or gives an error message, then you may need to allow Private and Public access for Python through your firewall for the host machine.
  • Simply go into firewall settings and select “Allow an app or feature through Windows Defender Firewall” available on the left tab. Search for Python and grant private and public access. And that should get your remote access working.

And that's all there is to it. A very simple workaround for those who have to constantly share data between devices. Hope this helps.

--

--

Bojitha Piyathilake
Bojitha Piyathilake

Written by Bojitha Piyathilake

I am an undergraduate at the University of Moratuwa following a degree in Information Technology and Management.

No responses yet