How to Install CherryPy: A Comprehensive Beginner’s Guide
CherryPy is a fast, simple, and minimalistic Python web framework used for building web applications. Its easy installation and straightforward REST API make it a favorite among developers who want to quickly start web development using Python. This tutorial will guide you through the process of installing CherryPy from scratch, verify the installation, and provide troubleshooting tips for common issues.
Prerequisites
- Basic knowledge of command line or terminal usage
- Python installed on your system (version 3.6 or higher recommended). You can download Python from the official Python website (Official site).
- Internet access to download CherryPy package
Step 1: Verify Python Installation
Before installing CherryPy, ensure Python is properly installed and accessible from your command line.
python --version
# or sometimes
python3 --version
If this returns the installed Python version (e.g., Python 3.10.x), you’re ready. If not, install Python and add it to your system PATH.
Step 2: Install Pip Package Manager (usually bundled with Python)
Pip allows easy installation of Python packages like CherryPy. Check if pip is installed:
pip --version
# or
pip3 --version
If not found, refer to the official Python documentation to install pip (Official site).
Step 3: Install CherryPy
Use pip to install CherryPy. Run the following command in your terminal or command prompt:
pip install CherryPy
# or if you need to use pip3
pip3 install CherryPy
This downloads and installs the latest CherryPy package from the Python Package Index (PyPI).
Step 4: Verify CherryPy Installation
Confirm CherryPy is installed by running a simple version check in Python:
python
>>> import cherrypy
>>> print(cherrypy.__version__)
# You should see the installed CherryPy version printed out
If no errors appear, CherryPy is correctly installed.
Step 5: Simple CherryPy Application Test
Create a simple CherryPy app file to test the setup.
import cherrypy
class HelloWorld:
@cherrypy.expose
def index(self):
return "<h1>Hello, CherryPy!</h1>"
if __name__ == '__main__':
cherrypy.quickstart(HelloWorld())
Save this as app.py and run:
python app.py
Open a browser and visit http://127.0.0.1:8080. You should see “Hello, CherryPy!” displayed.
Troubleshooting Common Issues
- Command Not Found Errors: Ensure Python and pip are added to your system PATH.
- Permission Denied: Use
pip install --user CherryPyto install locally without admin rights. - Version Conflicts: Use a Virtual Environment to isolate dependencies. Create one with
python -m venv env, activate it, then install CherryPy. - Firewall/Network Issues: Check your internet connection and firewall settings if pip fails to download packages.
Summary Checklist
- Verified Python and pip installations
- Installed CherryPy via pip
- Tested CherryPy import and version
- Created and ran a CherryPy Hello World app
- Troubleshot common installation problems
For further learning, consider checking out related guides such as how to install other Python web frameworks which may expand your web development skills.
With CherryPy installed, you can now explore building REST APIs, web services, or full web applications using this lightweight, powerful Python framework. Happy coding!
