Last modified: Jun 01, 2025 By Alexander Williams

Install Bottle Web Framework for Python

Bottle is a fast and lightweight Python web framework. It is perfect for small projects and APIs. This guide will help you install and set it up.

Prerequisites

Before installing Bottle, ensure you have Python installed. You can check by running:

 
python --version


Python 3.8.5

If Python is not installed, download it from the official website. For more details, see our guide on installing Python packages on Raspberry Pi.

Install Bottle Using pip

The easiest way to install Bottle is using pip, Python's package manager. Run the following command:

 
pip install bottle


Successfully installed bottle-0.12.23

This will install the latest version of Bottle. If you encounter issues, ensure pip is up to date.

Verify Installation

To confirm Bottle is installed, run:

 
python -c "import bottle; print(bottle.__version__)"


0.12.23

If the version number appears, Bottle is ready to use.

Create a Simple Bottle App

Let's create a basic web app. Save the following code in a file named app.py:

 
from bottle import route, run

@route('/')
def home():
    return "Hello, Bottle!"

run(host='localhost', port=8080, debug=True)

This code defines a route for the homepage. The run function starts the server.

Run the Application

Execute the script using Python:

 
python app.py


Bottle v0.12.23 server starting up (using WSGIRefServer())...
Listening on http://localhost:8080/
Hit Ctrl-C to quit.

Open your browser and visit http://localhost:8080. You should see "Hello, Bottle!" displayed.

Install Bottle in a Virtual Environment

For better dependency management, use a virtual environment. Create one with:

 
python -m venv myenv

Activate the environment:

 
source myenv/bin/activate  # Linux/Mac
myenv\Scripts\activate     # Windows

Now install Bottle inside the virtual environment:

 
pip install bottle

This keeps your project dependencies isolated. For more on virtual environments, check our guide on installing Python packages in Heroku.

Common Issues and Fixes

If you face errors, ensure pip is updated:

 
pip install --upgrade pip

Permission issues can be resolved by using --user:

 
pip install --user bottle

For more complex setups, refer to our guide on installing Caffe for Python.

Conclusion

Bottle is a simple yet powerful web framework for Python. With this guide, you can install and start using it quickly. Happy coding!