unable to run flask app using another port - python-3.x

I am new to flask. After installing it in ubuntu-lts, I tried to change the port but was unable to run the flask app from another port as another user is using an existing port.
I get this error :
from flask import Flask, request
ImportError: No module named 'flask'
[INFO] Worker exiting (pid: 34455)
[INFO] Reason: Worker failed to boot.
Where is the mistake - installation or another problem? thank you.

My guess is that you are on wrong dev environment.
Ensure you are on right python version and Flask is installed for that version. Now, what I mean by this is, that, a normal pip install Flask would install Flask for python2.7, but you seem to have tagged python3 in the OP.
If you are intending to develop your Flask application on Python3, you might want to make a virtual environment using that will use Python3, then install flask inside that. Or else, you could tell Python to install Flask for python3 explicitly.
I agree that you might have installed Flask on your system, but I think the one you installed is for Python2 and you are trying to run the flask app in Python3 environment.
These are wild guesses as your question doesn't say exactly what environment setup you are on.

Related

Python container import error on k8s but not locally

ImportError: cannot import name 'Markup' from 'jinja2.utils' (/usr/local/lib/python3.8/site-packages/jinja2/utils.py)
This error started appearing after a recent deployment to K8s. However building the image and running the container locally(Both on Windows and Linux machines) using docker-compose produces no errors.
The image K8s uses is hosted in aws ECR, strangely I am unable to reproduce the error by pulling this image and running it locally. It works exactly as expected. There doesn't seem to be any issue with the image itself.
The code where jinjasql is used hasn't changed either.
I am at a loss as to how this is occurring, any ideas would be appreciated.
Python version is 3.8. Kubernetes 1.21.

Some AWS lambda functions stopped working with "No module named setuptools._distutils" error

I have an application with many serverless functions deployed to AWS lambda. These functions use Python 3.7 runtime environment. But yesterday after deploying some minor changes, few of these functions stopped working with the error.
[ERROR] Runtime.ImportModuleError: Unable to import module 'functions.graphql.lambda.user_balance': No module named 'setuptools._distutils'
The weird thing is that the functions which are throwing this error were not changed and other functions are working without any issues. No python module was added/removed.
Just to check if the code change has anything to do with this error, I tried deploying a previous version. But the error persists.
I used the serverless framework for deployment.
It looks like this is an issue that started happening for all Python users as of yesterday as the set up tools got updated, but PIP did not.
According to this GitHub issue there is a temporary workaround until this is actually fixed.
Setting environment variable SETUPTOOLS_USE_DISTUTILS=stdlib is a workaround, e.g.:
export SETUPTOOLS_USE_DISTUTILS=stdlib
pip3 install ....
My assumption would be that you could add this as an environment variable for the Lambda possibly through the serverless config?
This is the bug in setuptools https://github.com/pypa/setuptools/issues/2353. Follow the below temporary workaround.
Linux
export SETUPTOOLS_USE_DISTUTILS=stdlib
Windows
set SETUPTOOLS_USE_DISTUTILS=stdlib
After that, execute the pip command.
pip install XXXXX

Google App Engine: cv2 libSM.so.6 error on Flask app

I have a Flask app that I want to deploy on the Google App Engine. Everything checks out fine, the requirements file contains all the modules which get installed successfully. But towards the end I get this error:
from .cv2 import *
ImportError: libSM.so.6: cannot open shared object file: No such file or directory
I read on various blogs and other similar stackoverflow questions that you need to install libsm6 using:
sudo apt-get install libsm6
But even after I did that, I still get the same error. How do I solve this?
The App Engine runtime has a fixed set of system packages that are included in the runtime and unfortunately libsm6 is not one of them. In addition, it's not possible to install additional system packages.
However, this is an ideal use case for Cloud Run, which lets you define your own runtime via a Dockerfile. See the quickstart for an example: https://cloud.google.com/run/docs/quickstarts/build-and-deploy

Complete build package of "pdftotext" for deploying on AWS-Lambda with Python3.7

I am trying to deploy a small python 3.7 code which uses "pdftotext" on AWS-Lambda. I was able to run the code successfully on my local machine (Mac). Using virtual-environment as specified by AWS documentation, I created a deployment package of the code with pdftotext. However still I am getting module not found error in Lambda. If you have been able to create a complete build package for pdftotext with all its dependencies, can you share please. Thanks in advance.
Using virtual-environment as specified by AWS documentation, I created a deployment package of the code with pdftotext.
import pdftotext
Getting module not found error for pdftotext when testing in AWS-Lambda.
A bit late to the party on the answer to this question, but I asked a similar question here: Get pdftotext Python module running on Lambda
My problem was I was compiling the binary on Amazon Linux 1 when the Python 3.8 lambda runtime uses Amazon Linux 2 shared libraries.
Install the library on an Amazon Linux 2 EC2 instance or docker container, and the library will be usable in your lambda.
Posting this in case it helps someone that comes across this question.

Does pandas work on Openshift?

I am trying to get an application started on Openshift, using the Python cartridge 3.3. I've added my dependencies into the requirements.txt, but the application fail to load on pandas dependency. I've searched through the web and there's only one mention of issues related to pandas and numpy but cannot seem to help. I've attempted to install pandas via ssh and end up with the following message after a while
Installing collected packages: pandas
Running setup.py install for pandas
Connection to [app].rhcloud.com closed by remote host.
Connection to [app].rhcloud.com closed.
Has anyone already used pandas on Openshift? Is there potential issues due to C dependencies?
Thank you
I had the same problem. It seems that with OpenShift there's a problem compiling algos.cwhich is part of pandas.
By installing manually I was able to avoid OpenShift's closing of the connection:
See my answer to this similar question.

Resources