Python Pyramid - Environment Setup
Last Updated :
10 Dec, 2023
Python Pyramid, often simply referred to as Pyramid, is an open-source web framework used for building web applications and web services in Python. Whether you're constructing a website, or a sophisticated web application Pyramid offers the resources and adaptability to complete the task effectively.
Environment Setup for Python Pyramid
To begin with, let's go through the step-by-step process of setting up a development environment for Python Pyramid.
Step 1: Install Python
If you haven't installed Python yet you can download the Python, for Windows from the Python website (https;//www.python.org/downloads/windows/). Remember to include Python in your system's PATH when installing it.
Step 2: Create a directory
Once Python is installed, create a new directory for your Pyramid project and navigate to it in the command prompt.
cd <pyramid_directory>
Step 3: Create and Activate Virtual Environment
Let's create and activate a virtual environment for your Pyramid project. we can create a virtual environment using Python's vene. It is a Python built-in module that stands for "virtual environment." It is used to create isolated Python environments in which you can install packages and dependencies independently of the system-wide Python installation. To create a virtual environment follow these steps.
Step 4: Install Pyramid
Once you've activated the environment, you can proceed to install Pyramid with version by using the following pip command".
>pip install "pyramid==2.0"
Note: It is not necessary to specify the version
Output
.png)
Step 5: Create a Pyramid Application
We are using Cookiecutter for creating the Pyramid application. Because it streamlines the process of generating a Pyramid project template with predefined configurations, folder structures, and sample code. Cookiecutter templates provide a consistent and efficient way to set up Pyramid projects by eliminating the need to manually create directories and files and configure settings from scratch.
Install cookiecutter if you don't have it installed using following command.
>pip install cookiecutter
Then, run the following command in command prompt for creating your Pyramid application.
>cookiecutter gh:Pylons/pyramid-cookiecutter-starter
Then it will ask following things
- project_name (Pyramid Scaffold): Give your own project name
- repo_name( project_name): Give repo name.
- Select template_language: Select one template language among follwing
- 1 - jinja2
- 2 - chaymeleon
- 3 - mako
- Select backend: Select One backend
- 1 - none
- 2 - sqlalchemy
- 3 - zodb
.png)
Step 6: Navigate to new Project
Change directory into your newly created project using following command
cd <project_name>
cd hello
Step 7: Install Required Dependencies
Install the project in required modules using command
pip install -e .
Step 9: Initialize and upgrade the database using Alembic
Run the following two commands for initializing and upgrade the database.
alembic -c development.ini revision --autogenerate -m "init"
alembic -c development.ini upgrade head
.png)
Step 10: Load data into DB
Load default data into the database using a script.
initialize_<project_name>_db development.ini
Step 12: Run your project
Run the command for start the Pyramid.
>pserve development.ini
Output
Starting server in PID 6264.
2023-10-25 17:27:02,347 INFOÂ [waitress:486][MainThread] Serving on http://[::1]:6543
2023-10-25 17:27:02,347 INFOÂ [waitress:486][MainThread] Serving on http://127.0.0.1:6543
The above command will start the pyramid server in localhost in 6543 port
Step 13: Access Your Pyramid Application
Open a web browser and go to http://localhost:6543 or the URL specified in the console. You should see your Pyramid application running.
Step 14: Stop server
Use the ctrl+c for stopping the pyramid server.
Output
.png)
Similar Reads
Python Falcon - Environment Setup Falcon is a Python library renowned for its proficiency in crafting indispensable REST APIs and microservices. Capable of accommodating both the WSGI (Web Server Gateway Interface) and ASGI (Asynchronous Server Gateway Interface) standards, Falcon has gained widespread recognition since its inceptio
3 min read
Environment Variables in Python Environment variables are key-value pairs that live in our system's environment. Python reads some of these variables at startup to determine how to behave, for example, where to look for modules or whether to enter interactive mode.If thereâs ever a conflict between an environment variable and a co
3 min read
Create virtual environment in Python A virtual environment is a self-contained directory that contains a Python installation for a particular version of Python, plus a number of additional packages. Using virtual environments is a common practice in Python development as it helps to manage dependencies for different projects, avoiding
3 min read
Managing Virtual environments in Python Poetry Poetry helps you declare, manage, and install dependencies of Python projects, ensuring you have the right stack everywhere. Poetry is a tool for dependency management and packaging in the PHP programming language that helps in managing project dependencies and creating virtual environments. Unlike
4 min read
What is setup.py in Python? Introduction In Python, setup.py is a module used to build and distribute Python packages. It typically contains information about the package, such as its name, version, and dependencies, as well as instructions for building and installing the package. This information is used by the pip tool, whic
3 min read
Access environment variable values in Python An environment variable is a variable that is created by the Operating System. Environment variables are created in the form of Key-Value pairs. To Access environment variables in Python's we can use the OS module which provides a property called environ that contains environment variables in key-va
3 min read
Python | os.environ object os.environ in Python is a mapping object that represents the userâs OS environmental variables. It returns a dictionary having the userâs environmental variable as key and their values as value.os.environ behaves like a Python dictionary, so all the common dictionary operations like get and set can
5 min read
Add packages to Anaconda environment in Python Let's see some methods that can be used to install packages in the Anaconda environment. There are many ways one can add pre-built packages to an anaconda environment. So, let's see how to direct the path in the anaconda and install them. Add packages to the Anaconda environment using the navigator
2 min read
Usage of __main__.py in Python Many of us have worked with creating their own custom module in Python and is well familiar with the candidate '__init__.py'. If you do not know then let's get a brief and short description of '__init__.py' before diving deep into the concerned topic. Actually, when we try to import a module to Pyth
3 min read
Setup SciPy on PyCharm SciPy is an open-source library in Python used for scientific and technical computing. It builds on the capabilities of the NumPy library and provides a wide range of tools and functions for various scientific and engineering tasks using Python. In this article, we will see how we can set up Scipy o
2 min read