Debug School

rakesh kumar
rakesh kumar

Posted on • Updated on

Python framework error and solution

1.download and install pycharm then create project(reference.
2.activate virtual environment.

3.install existing dependencies.

4.perform crud operationreference.

5.run project

How to run project in different frame work
How to install existing dependencies in different framework
How to Activate Virtual Environment in different framework
ERROR: If psycho module not installed

How to run project in different frame work

FAST API:
Install Dependencies:
Ensure that you have FastAPI and a server like uvicorn installed:

pip install fastapi[all]
Enter fullscreen mode Exit fullscreen mode

Run the Project:
You typically run a FastAPI project using uvicorn:

uvicorn main:app --reload
Enter fullscreen mode Exit fullscreen mode

main is the name of the Python file (e.g., main.py).
app is the name of the FastAPI instance in that file (app = FastAPI()).
--reload is an optional flag that automatically reloads the server when you make changes to the code.

Image description

Image description

Image description

USING GUI

GO main menu click 3 bar===>RUN===>run fast api project
Enter fullscreen mode Exit fullscreen mode

FLASK:

flask run
Enter fullscreen mode Exit fullscreen mode

Image description

Image description

GO main menu click 3 bar===>RUN===>rerun flask server project
Enter fullscreen mode Exit fullscreen mode

another way

Image description

another way

right click python file--> click run util.py option
Enter fullscreen mode Exit fullscreen mode

Install Flask

Install Flask:
Make sure Flask is installed:

pip install flask
Enter fullscreen mode Exit fullscreen mode

Set the Flask App Environment Variable:
You need to tell Flask which file to run. For example, if your main file is app.py:

On Windows:

set FLASK_APP=app.py
Enter fullscreen mode Exit fullscreen mode

On macOS/Linux:

export FLASK_APP=app.py
Enter fullscreen mode Exit fullscreen mode

Django:

python manage.py runserver
Enter fullscreen mode Exit fullscreen mode

To run the server on a different port, specify it after the runserver command:

python manage.py runserver 8080
Enter fullscreen mode Exit fullscreen mode

How to install existing dependencies in different framework

pip list: Gives an overview of all installed packages in a summarized list.

Image description

pip show: Provides detailed information for a specific package.

pip show <package_name>
pip show Flask
Enter fullscreen mode Exit fullscreen mode

Image description

FAST API:

first run command pip list

Image description

To install the listed dependencies, you can create a requirements.txt file with the specific versions of the packages and then use pip to install them.

  1. Create a requirements.txt file First, create a requirements.txt file in your project directory and add the following content:

Package Version


annotated-types 0.7.0
anyio 4.4.0
blinker 1.8.2
click 8.1.7
colorama 0.4.6
fastapi 0.112.1
Flask 3.0.3
Flask-SQLAlchemy 3.1.1
greenlet 3.0.3
h11 0.14.0
idna 3.7
itsdangerous 2.2.0
Jinja2 3.1.4
MarkupSafe 2.1.5
pip 23.2.1
psycopg2 2.9.9
psycopg2-binary 2.9.9
pydantic 2.8.2
pydantic_core 2.20.1
sniffio 1.3.1
SQLAlchemy 2.0.32
starlette 0.38.2
typing_extensions 4.12.2
uvicorn 0.30.6
Werkzeug 3.0.3

  1. Install the Dependencies Once you have created the requirements.txt file, you can install all the dependencies by running the following command in your terminal:
pip install -r requirements.txt
Enter fullscreen mode Exit fullscreen mode

This command will install all the listed packages with the specified versions.

  1. Verify Installation After the installation, you can verify that the packages are installed by running:
pip list
Enter fullscreen mode Exit fullscreen mode

This should display all the installed packages along with their versions, matching those specified in the requirements.txt file.

Additional Notes:

  1. Ensure that you are working within the correct Python environment (e.g., a virtual environment) when installing these packages to avoid conflicts with other projects.
  2. If any package installation fails, you might need to resolve specific dependencies or install them individually .

FLASK:
Same process follow in what i followed in fastapi

Package           Version
----------------- -------
annotated-types   0.7.0
anyio             4.4.0
blinker           1.8.2
click             8.1.7
colorama          0.4.6
fastapi           0.112.1
Flask             3.0.3
Flask-SQLAlchemy  3.1.1
greenlet          3.0.3
h11               0.14.0
idna              3.7
itsdangerous      2.2.0
Jinja2            3.1.4
MarkupSafe        2.1.5
pip               23.2.1
psycopg2          2.9.9
psycopg2-binary   2.9.9
pydantic          2.8.2
pydantic_core     2.20.1
sniffio           1.3.1
SQLAlchemy        2.0.32
starlette         0.38.2
typing_extensions 4.12.2
uvicorn           0.30.6
Werkzeug          3.0.3
Enter fullscreen mode Exit fullscreen mode

Django:
Same process follow in what i followed in fastapi

C:\Users\rakes\PycharmProjects\djangoProject>pip list
Package           Version
----------------- -------
annotated-types   0.7.0
anyio             4.4.0
blinker           1.8.2
click             8.1.7
colorama          0.4.6
fastapi           0.112.1
Flask             3.0.3
Flask-SQLAlchemy  3.1.1
greenlet          3.0.3
h11               0.14.0
idna              3.7
itsdangerous      2.2.0
Jinja2            3.1.4
MarkupSafe        2.1.5
pip               23.2.1
psycopg2          2.9.9
psycopg2-binary   2.9.9
pydantic          2.8.2
pydantic_core     2.20.1
sniffio           1.3.1
SQLAlchemy        2.0.32
starlette         0.38.2
typing_extensions 4.12.2
uvicorn           0.30.6
Werkzeug          3.0.3
Enter fullscreen mode Exit fullscreen mode

How to Activate Virtual Environment in different framework

Fast Api

Image description

.venv\Scripts\activate
Enter fullscreen mode Exit fullscreen mode
C:\Users\rakes\PycharmProjects\flaskProject>.venv\Scripts\activate
(.venv) C:\Users\rakes\PycharmProjects\flaskProject>pip install flask_sqlalchemy
Enter fullscreen mode Exit fullscreen mode

Flask
Same process follow in what i followed in fastapi

Django
Same process follow in what i followed in fastapi

ERROR: If psycho module not installed

step1:uninstall package

pip uninstall psycopg
pip uninstall psycopg2
pip uninstall psycopg2-binary
Enter fullscreen mode Exit fullscreen mode

step2:install package

pip install psycopg
Enter fullscreen mode Exit fullscreen mode

Top comments (0)