import argparse
import os
from flask import Flask, jsonify, make_response
!pip install flask_cors
!pip install flask_swagger_ui
from flask_cors import CORS
from flask_swagger_ui import get_swaggerui_blueprint
!pip install routes
from routes import request_api
this is the whole code I tried it in colab but the last import keeps failing
I got code from https://github.com/Sean-Bradley/Seans-Python3-Flask-Rest-Boilerplate/blob/master/app.py
You should add the module on your own.
try to open https://github.com/Sean-Bradley/Seans-Python3-Flask-Rest-Boilerplate/tree/master/routes
and copy those modules to your folder.
Related
No module named 'openpyxl' when trying to import it from flask app , pointing that the module is installed in "/home/ubuntu/.local/lib/python3.8/site-packages/" and it works fine in other scripts
here what i am using
from flask import Flask, render_template, request
app = Flask(__name__)
#app.route('/upload_file', methods=['GET','POST'])
def upload_file():
try :
import sys
sys.path.append('/home/ubuntu/.local/lib/python3.8/site-packages/')
import openpyxl
except Exception as e:
return render_template('index.html',msg=str(e))
return render_template('index.html',msg=request.method)
i've seen a lot of questions about how to import a module in flask since i've found it as a common error , so i've tried to create a module that does nothing but import openpyxl but no luck either i had the same error
I am using ubuntu 20.04 python3.8
Thanks in advance
I found two solutions :
1 .
Install the module manually in /usr/local/lib/python3.8/dist-packages using python3 -m pip3 install openpyxl in that directory
2 .
change the directory where the modules are installed using pip by creating the config file ~/.config/pip/pip.conf , the content must be your desired install location like this :
[global]
target = /usr/local/lib/python3.8/dist-packages
I hope this help someone with the same need
Here is my current directory stucture
My FLASK_APP environment variable is set to app.py
and on that app.py I have this import variables
from flask import Flask
from flask import request
from flask import jsonify
from dataproviders import provider
from usecase import useCases
However, upon running the flask run I always end up getting this error.
File "C:\Users\USER\projects\project\lambda\app.py", line 5, in <module>
from dataproviders import provider
ModuleNotFoundError: No module named 'dataproviders'
The issue can be fixed by doing
from .dataproviders import provider
from .usecase import useCases
But is there anyway for us to import it using
from dataproviders import provider
from usecase import useCases
Without encountering any error like ModuleNotFoundError?
I have an import error while coding a flask web application. Here are my imports:
from flask import Flask
from flask import session, request
from flask import render_template, redirect
from flask_sqlalchemy import sqlalchemy
Although the last line of code gives me the error:
from flask_sqlalchemy import sqlalchemy
I have successfully installed Flask, SQLAlchemy, and Flask-SQLAlchemy using pip, and I have checked whether these are installed on the system using
python -c "import Flask"
etc. These checks resulted in a 0, meaning that it was correctly installed. NOTE: I have already read other posts, and tried flask.ext.sqlalchemy, flaskext_sqlalchemy, etc. as import variations. Here are the installed packages in the sitepackages directory for python 2.7.
Flask_OAuth-0.12.dist-info httplib2
Flask_SQLAlchemy-2.3.2.dist-info httplib2-0.10.3.dist-info
SQLAlchemy-1.2.0.dist-info oauth2
flask_oauth.py oauth2-1.9.0.post1.dist-info
flask_oauth.pyc sqlalchemy
flask_sqlalchemy tests
I have also structured my files, so the imports are in the init.py file. My other files included views.py, config.py, run.py, and a templates folder containing html files.
What am I doing wrong here, and how is my problem different from others?
Module imports are indeed case sensitive.
The way to check this is to first confirm if it's possible to:
import flask_sqlalchemy
If that succeeds, the package is installed correctly. Once the package is confirmed to be installed correctly, then this should succeed.
from flask_sqlalchemy import SQLAlchemy
PEP8 suggests that:
Imports should be grouped in the following order:
standard library imports
related third party imports
local application/library specific imports
You should put a blank line between each group of imports.
I am using Flake8Lint which Sublime Text plugin for lint Python files.
My code as below:
import logging
import re
import time
import urllib
import urlparse
from flask import Blueprint
from flask import redirect
from flask import request
from flask.ext.login import current_user
from flask.ext.login import login_required
from my_application import one_module
it will show the warning as below:
import statements are in the wrong order, from my_application should be before from from flask.ext.login
but flask is the third party library, it should before my my_application import. This is why? How to fix it?
The flake8-import-order plugin needs to be configured to know which names should be considered local to your application.
For your example, if using a .flake8 ini file in your package root directory, it should contain:
[flake8]
application_import_names = my_application
Alternatively you can use only relative imports for application local imports:
from __future__ import absolute_import
import os
import sys
import requests
from . import (
client
)
...
I gave my friends a project. and I use lots of 3rd part packages among the scripts.
How could I generate all the necessary packages automatically.
Otherwise,
my friend should run my script and catch the exception and install the missing package, again and again.
By the way, is it possible to install all the necessary packages at once ?
# -*- coding: utf8 -*-
from flask import request, url_for
from flask import json
from flask import Response
from flask import Flask, request, jsonify
from flask_request_params import bind_request_params
import datetime
import pandas as pd
import pymongo
import pdb
from webargs import Arg
from webargs.flaskparser import use_args, use_kwargs
import urlparse
from mongo import Mongo
import yaml
import time, functools
from functools import wraps
from pdb import set_trace
from flask import g
from pandas_helper import PandasHelper
import errors
That’s what requirement files in pip are for:
"Requirements files" are files containing a list of items to be installed using pip install
Basically they document your dependencies, so when you do a pip install later, pip will get all the required dependencies to run your script.