Start Simple Web Server on Python 3 on Mac

Check tutorial of How to Start a Simple Web Server in Python 3 on Mac

So after a lot of requests from our users here is a guide about How to Start a Simple Web Server in Python 3 on Mac.

If you’re a Python user, you may already be familiar with the handy trick which allows you to instantly create a simple web server using a simple command string entered at the Mac OS command line. But if you are a Mac Python user who has installed Python 3 or updated to Python 3, then you will find that the traditional command string from the earlier Python versions does not work to start the web server in new Python 3.x + releases.

Don’t worry, the simple web server Python trick still works in Python 3 for Mac (and of course for Linux and Windows, but we’ll cover macOS of course), it’s that the command syntax is slightly different. We’ll show you how to start a simple web server with Python 3 by using the new Python 3.0+ equivalent of the python -m SimpleHTTPServer command.

How to Start a web HTTP server in Python 3.0+

We assume you have already installed Python 3.0+ on the Mac or updated to Python 3.0+, this variant of the command requires Python 3.0 or newer.

From the command line, enter the following syntax exactly *:

python -m http.server

OR (depending on how Python 3.x is installed and called):

python3 -m http.server

Hit Return and Python 3 will immediately start a simple HTTP server from the directory where the command was executed.

The http.server in Python 3 will run in the terminal, if there is no web file in the directory, the directory index itself will be shown.

You can test this directly by opening the following URL in any web browser on the computer:

http://0.0.0.0:8000

All web server activity, such as opening individual files, folders, directories, etc., is shown live in the active Python terminal window as it happens, a bit like retrieving web logs on an Apache or Nginx server.

* Important note: If you have installed python and python3 simultaneously, you may need to slightly change the syntax to refer to python3 and python2 or another python version. This depends on how you updated to Python 3 on the Mac, but a well-known example is using the ‘python3’ command:

python3 -m http.server

Just like before, hit return and the active directory will be converted to a web server.

The simple web server from Python3 with HTTP

What is the Python3 equivalent of python -m CGIHTTPServer?

Another very common trick is to use the Common Gateway Interface (CGI) server in Python for CGI scripts in python or perl. So if you need to run the python3 equivalent of the “python -m CGIHTTPServer” command for CGI, it would be like this:

python3 -m http.server -cgi

Alternatively, if Python 3 is installed and called python, the command would simply be:

python -m http.server -cgi

In either case, you need the –cgi flag to start the CGI HTTP server in Python 3.

I get an error “/ usr / bin / python: no module named http” what now?

If you see a “/ usr / bin / python: No module named http” error when you try to run the python -m http.server command string, you are probably not running Python 3, or using the wrong one command for python3 (i.e. python vs python3, depending on what the version is called and how it’s installed or updated on the Mac). It is also possible that Python may not be installed on the computer at all, although that is less likely for Macs as Python2 is installed by default on Mac OS, although users will need to manually install the updated Python 3.x on the Mac, thereby keeping the original Python 2.x release version remains. Usually this is achieved with Homebrew.

Change the syntax as mentioned above, or if you are using an earlier Python version, try the “python -m SimpleHTTPServer” command from Python 2 and earlier.

Of course, Python’s simple web servers are not intended for production environments and are really just the best for a fast notepad or test environment. If you want to run a web server that is publicly targeted or just more robust in general, you’d want to use something like Apache or Nginx, although configuring those separately on a Mac requires some installation. An easier option for a full web server environment on the Mac is to use MAMP, which makes the setting up and launching a full Apache, MySQL, PHP environment on the Mac as easy as it gets.

Do you know of another interesting Python tips or tricks? Do you know of any other useful python command strings for starting http servers or otherwise? Share it with us in the comments below!

How to Start a Simple Web Server in Python 3 on Mac Guide is free?

Starting from: Free
This guide is a free model
Free Trial: May be included, please check on the official site, we mentioned above.
The How to Start a Simple Web Server in Python 3 on Mac tutorial price is Free or Freemium. This means you can truly enjoy the How to Start a Simple Web Server in Python 3 on Mac guide.

The How to Start a Simple Web Server in Python 3 on Mac guide gives you an easy-to-use and efficient management and How to Start a Simple Web Server in Python 3 on Mac allows you to focus on the most important things. It’s friendly guide to use maybe you will love it and How to Start a Simple Web Server in Python 3 on Mac tutorial can be used on Linux, Windows or android devices.

How to Start a Simple Web Server in Python 3 on Mac: benefits

  • The How to Start a Simple Web Server in Python 3 on Mac tutorial is free .
  • Helps many users follow up with interest in a timely manner.
  • The price of the How to Start a Simple Web Server in Python 3 on Mac guide is free.

How to Start a Simple Web Server in Python 3 on Mac: FAQ

Tutorial Summary: How to Start a Simple Web Server in Python 3 on Mac

In this guide, we told you about How to Start a Simple Web Server in Python 3 on Mac; please read all steps so that you understand How to Start a Simple Web Server in Python 3 on Mac in case if you need any assistance from us, then contact us.

How this tutorial helping you?

So in this guide, we discuss the How to Start a Simple Web Server in Python 3 on Mac, which undoubtedly helps you.

What is actual time in which this method complete?

The time to complete the How to Start a Simple Web Server in Python 3 on Mac tutorial is 10+ minutes.

What are the supported Device?

Apple

What are the supported Operating system?

mac OS


How to Start a Simple Web Server in Python 3 on Mac Tutorial: final note

For our visitors: If you have any queries regards the How to Start a Simple Web Server in Python 3 on Mac, then please ask us through the comment section below or directly contact us.
Education: This guide or tutorial is just for educational purposes.
Misinformation: If you want to correct any misinformation about the guide “How to Start a Simple Web Server in Python 3 on Mac”, then kindly contact us.
Want to add an alternate method: If anyone wants to add the more methods to the guide How to Start a Simple Web Server in Python 3 on Mac, then kindly contact us.
Our Contact: Kindly use our contact page regards any help. You may also use our social and accounts by following the Whatsapp, Facebook, and Twitter for your questions. We always love to help you. We answer your questions within 24-48 hours (Weekend off).
Channel: If you want the latest software updates and discussion about any software in your pocket, then here is our Telegram channel.

Compsmag
Logo