Azure ImportError: Unable to import required dependencies: numpy - python

I've build a Function in Azure and deployed it via VS.
The function is running locally well, the build process when uploaded to the cloud is successfull but when it's trying to run (with the blob trigger) I get the next error:
ImportError: Unable to import required dependencies: numpy
I'm using pandas library that needs numpy.
I downloaded all of the packeges and dependencies,I've tried to uninstall and install again ,I even tried to upgrade every library especially numpy, nothing.
The function is written in Python 3.7.5 and running on Linux env(Azure runtime).
my imports:
import logging
import openpyxl
import pymysql
import pymysql.cursors
import pandas as pd
import xlrd
import re
from itertools import islice
import azure.functions as func

You need to have all your dependencies in requirements.txt before you publish. This way (using the new tools), after publish all your application dependencies will be downloaded for you as part of your function app content.
In this case, please make sure you have pandas, numpy or whatever is required by your application in the requirements.txt file.
Here's more information on how to publish and what to expect -- https://learn.microsoft.com/en-us/azure/azure-functions/functions-reference-python#publishing-to-azure

Please check if your deployed azure function content is correct. You can do that with App Service Editor in the portal.

Related

why python modules used in power BI desktop not working in power BI service

I have a python visual code which is working when ran in power BI desktop.
but when i published the same to power BI service and try to run, its throwing "Modlue Not found" error.
What might be the reason and how to overcome this error.
I'm importing below modules in my script
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import json
import xml.etree.ElementTree as ET
import os
import glob
import time
from time import sleep
import requests
from itertools import product
I tried installing requests again but it says
but still it throwing ModuleNotFoundError: No module named 'requests' error
The official documentation has a list of packages that are supported in the online service:
Python packages that are supported in Power BI.
You can request support for a new package here:
Power BI Ideas
what might be the reason
Because your code is run in a multi-tenant SaaS service and so must run in a strict security sandbox. Allowing arbitrary packages, and in particular allowing outbound network access with the requests package, makes the security of this sandbox harder to enforce.

Cannot import: "from trello import TrelloClient" py-trello and trello packages (replit)

To be simple, I couldn't import py-trello bcs there is also a package named trello.
when I run
from trello import TrelloClient
replit thinks that I'm working on python trello package and installs trello package. And then my code gives error like "cannot import TrelloClient". But actually I'm trying to work on py-trello
I tried to add a requirements.txt file to my workspace but when I run the main.py file it automatically downloads the trello package.
How can I import py-trello package instead of trello package?
It works perfectly fine on my local workspace because I only have py-trello. So it's importing py-trello.
But the automatic download system of replit does not let me import py-trello.
What should I do?
import trello #upm package(py-trello)
When you add a package by importing, we attempt to guess what package
you want based on the modules you are importing. In most languages
this is a direct correspondence, but in Python sometimes we can get it
wrong. You can directly request a package by specifying the package
directly on the import line.
Read in documentation

How to install Pandas to a specific python installation

I am trying to install Pandas in a version of Python that is bundled with an API. In an IDE bundled with the API I run the following:
Code
import sys
type(sys.path)
for path in sys.path:
print(path)
Output
C:\Users\priper\AppData\Local\Programs\Python\Python37\python37.zip
C:\Users\priper\AppData\Local\Programs\Python\Python37\DLLs
C:\Users\priper\AppData\Local\Programs\Python\Python37\Lib
C:\Users\priper\AppData\Local\Programs\Python\Python37
C:\Users\priper\AppData\Local\Programs\Python\Python37\Lib\site-packages
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\
C:\Users\priper\Desktop\HF_AutoCal
I have pointed the API to a version of Python3.7, now when I try to import pandas it says error. When I try and install pandas it says it is already satisfied as Pandaas is installed in Python3.8. I cannot point the API to Py3.8 as the API won't work with it, is there a way I can get Pandas and Numpy into the Python3.7?

AWS Lambda : Original error was: cannot import name multiarray

Hi i deployed an application with lambda aws (using Serverless Framework).
but i receive the error when i run a test
START RequestId: 5bcf988a-2064-11e8-8d1e-c5a0129510f Version: $LATEST
Unable to import module 'handler':
Importing the multiarray numpy extension module failed. Most
likely you are trying to import a failed build of numpy.
If you're working with a numpy git repo, try `git clean -xdf` (removes all
files not under version control). Otherwise reinstall numpy.
Original error was: cannot import name multiarray
I removed the numpy package folder multiple times and reinstalled but, still not working
So do you have any solution for this problem ?
for the code :
import sys
import os
sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)),'env','Lib','site-packages'))
import numpy as np
import pandas as pd
import boto3
import csv
import psycopg2
def hello(event, context):
s3 = boto3.resource('s3')
return "test"
Thank you in advance
I resolved the problem by changing the environnement.
I didn't know that python is not portable.
I developed the lambda function in my Windows environment, but lambda is usually run in a Linux environment in AWS, and that's why my lambda was not working.
So the solution is to change the environnement, and use Linux instead of windows
I compiled my code on MACOSX environment and was caught in the same problem these days, and even I put my code on ec2 and installed all the dependencies in linux or ubuntu environment, the error is the same.
https://docs.aws.amazon.com/lambda/latest/dg/current-supported-versions.html docs here gave me the hint that the current lambda execution environment is Public Amazon Linux AMI version (AMI name: amzn-ami-hvm-2017.03.1.20170812-x86_64-gp2),please pay attention to the specific version of AMI, even you use Amazon Linux as your ec2 instance, the newer or older version can make problem.
So after I changed the version of my ec2 instance, recompiled my code on it and store the zipped files on s3, than the AWS lambda run successfully.

Import 3rd party libraries in GAE with setup.py requirements

How do you install a third party library that has other dependencies? I am trying to import Urban Airship into my python based Google App Engine project. I understand that the basic premise is that I do something like
import sys
sys.path.insert(0, 'libs')
from urbanairship import *
So I cloned urbanairship from their GitHub account. As an aside, the folder urbanairship actual is under another folder which was originally python-library. Through my several attempts at getting this working I have tried imports like
from python-library.urbanairship import *
from python-library.urbanairship import core
from urbanairship import *
from urbanairship import core
and then tried renaming python-library to pythonlibrary
from pythonlibrary.urbanairship import *
from pythonlibrary.urbanairship import core
A more core issue is that urbanairship has a setup process which installs other dependency libraries. So I ran:
sudo python setup.py install
That installed the requests dependency on my local machine which wasn't available in GAE, so I cloned the Requests package from Github also which had its own setup.py file to install more dependencies. Things still didn't work and I thought - this can't be the right way to do this which is why I'm not reaching out to SO for help. What is the proper way to do this?
You only need to copy the packages to your root directory (alongside app.yaml), which will put them in the global namespace for your app, and thus make them available in your code as if they were installed in the system.
As far as I can tell, in your case, you only need to copy the urbanairship and requests folder/package, and then import them as usual. If some other requirement arises, just rinse & repeat.
Just to make it clear, the rest of the code you see on the github repo includes docs, tests, and other files to make setup work properly, but you're only interested in the folder (urbanairship, requests) itself.

Categories

Resources