Unable to import AWS SDK boto3 in Python 3.6.5 - python

I'm trying to use boto3 within a pipenv with Python 3.6.5.
So I installed it with
pipenv install boto3
So for testing purposes I'm using a single Flask app, and add at the beginning of the file:
import boto3
However without even running the program, PyLint warns me that E0401:Unable to import 'boto3', and the auto-completion only proposes botocore.
If I try to run the flask app or to deploy it to Lambda (cause it's the purpose of this app), I get an error 500.
However, the strange is that if I use the REPL within the pipenv and in the same directory and type
>> import boto3
Well it's successful, and I can use all the other commands of boto3. So in my opinion it is installed but for I reason I can't think of, my Python file can't load it.
I heard of file naming conflicts, but honestly I doubt that this is the reason since even if I rename the file and the Flask app with a weird name it still can't load.
Any thoughts about it? Thanks a lot

Related

How can I deploy a Flask app containing a Kik bot to Heroku? (Python)

Silly newb question, it seems I can't use git to install content I need in the Heroku console, but my app/bot is dependent on content I normally use that for. I know very little about how git and pip work, or the right terminology to ask a question like this, so bare with me!
I have a bot made with Tomer8007's Kik Bot API that I've embedded in Flask and want to deploy to Heroku. I've deployed Flask sites there before, they work like a charm, but because I import everything to Heroku via git using the Heroku CLI I can't import this one which is already using git.
I normally use these two commands to fetch and install the dependencies I need for that project:
git clone -b new https://github.com/tomer8007/kik-bot-api-unofficial
pip install ./kik-bot-api-unofficial
I tried manually downloading and installing the API without git, but then it throws this error when I tried to run it: "TypeError: Couldn't build proto file into descriptor pool: duplicate file name (google/protobuf/descriptor.proto)", wheras it works perfectly fine when I use the two above commands instead. (This is locally btw).
I also made an attempt to import to heroku before using those commands and instead using them in the heroku console, but it throws a bunch of errors when I try. I also can't import it after using those commands locally, because I already used git. (I'm not sure how that works though, that's why I'm here.)
Everything in procfile.txt, requirements.txt, runtime.txt, etc is fine, the only issue is getting the API for the Kik bot. I've no idea what's going haywire when I attempt to manually download it instead of using git clone, or what alternative options I have. Any pointers?
Apparently, the duplicate file name (google/protobuf/descriptor.proto) error was caused by a breaking change in the protobuf package in versions greater than 4.
This is now fixed, and should also work on Python 3.9+.

ModuleNotFoundError: No module named 'icalendar' google Cloud

I'm getting "ModuleNotFoundError: No module named 'icalendar' " after running google app deploy on Gcloud, I have installed the icalendar module using pip but to my surprise i'm getting an error when I try to deploy the app. I have spent hours on this your help will be much appreciated.
According to the official documentation :
Specifying Dependencies
Dependencies for Python applications are declared in a standard
requirements.txt
For example:
Flask==0.10.1
icalendar
Therefore I created a requirements.txt and included icalendar module. Then I deploy to App Engine gcloud app deploy and everything worked as expected.
You can follow this tutorial for better understanding the concept:
Quickstart for Python 3 in the App Engine Standard Environment
Pls. check pip list to see if that has been installed properly. If yes, pls. check that import statement in the python terminal.
If that works, then use which python and ensure that it is the same virtual environment where you are installing and running from.

Installing Google API to AWS Cloud9: "No module named 'google.api_core'"

I am trying to install the Google API Python client to AWS Cloud9 so that I can use them in a Lambda function.
I was able to install the API's using pip install well enough but when I paste the sample code from Google's setup page and run it, I get an error saying Unable to import module 'lambda_function': No module named 'google.api_core'
I have installed the client to the working directory as per this video and tried upgrading the google_api_core module as per this post
If anyone's able to provide any help or point me in the right direction, that would be a massive help.
I was able to solve this by manually uploading all of the google modules. In the Cloud9 console go to file->Upload Local Files and find the modules you need. It's a bit tedious finding all of the correct files, but it should work.

Gremlin operation using python in Azure functions

Is was trying to create Azure function using Python(Http trigger) to fetch data from the gremlin graph.
I used
from gremlin_python.driver import client as clientDriver
to import the libraries and it was working fine locally.
When i deploy the same code to the Azure portal and ran the code, am getting 500 internal error.
After trying some changes, i could see "from gremlin_python.driver import client as clientDriver" import statement is not working(When i remove this piece the code works)
When we run the code in VSCode, we are creating a virtual env and installing the gremlin packages, so it was working in local and not in Azure portal.
Could someone help me in resolving this issue.
For this problem, we need to make sure the requirements.txt is all right. And if you just do the import module by the line
from gremlin_python.driver import client as clientDriver
You need to add another line to import the gremlin_python.driver module explicitly.
import gremlin_python.driver
Hope it helps~

Importing mysql.connector into Azure Flask Project

I'm trying to deploy a Flask web app with mysql connectivity. It's my first time using Azure, and coming off Linux it all seems pretty confusing.
My understanding is that one includes within the requirements.txt to include the packages required. When I build the default Flask app from Azure the file looks like this:
Flask<1
At this stage the site loads fine.
If I then include an additional line
https://cdn.mysql.com/Downloads/Connector-Python/mysql-connector-python-2.1.14.tar.gz
As per this answer https://stackoverflow.com/a/34489738/2697874
Then in my views.py file (which seems to be broadly synonymous to my old app.py file) I include...import mysql.connector
I then restart and reload my site...which then returns the error The page cannot be displayed because an internal server error has occurred.
Error logging spits out a load of html (seems pretty weird way to deliver error logs - so I must be missing something here). When I save to html and load it up I get this...
How can I include the mysql.connector library within my Flask web app?
Per my experience, the resoure https://cdn.mysql.com/Downloads/Connector-Python/mysql-connector-python-2.1.14.tar.gz is for Linux, not for Azure WebApps based on Windows, and the link seems to be not available now.
I used the command pip search mysql-connector to list the related package. Then, I tried to use mysql-connector instead of mysql-connector-python via pip install, and tried to import mysql.connector in local Python interpreter that works fine.
So please use mysql-connector==2.1.4 instead of mysql-connector-python== in the requirements.txt file of your project using IDE, then re-deploy the project on Azure and try again. The package will be installed automatically as the offical doc said as below.
Package Management
Packages listed in requirements.txt will be installed automatically in the virtual environment using pip. This happens on every deployment, but pip will skip installation if a package is already installed.
Any update, please feel free to let me know.

Categories

Resources