MartinSahlen/cloud-functions-python

Unable To Install Pandas on Cloud Function

SushantVarshney opened this issue · 5 comments

Hi ,
I am trying to run my code over cloud-function which has a dependency of pandas in it.But after deploying the function and triggering it,facing the following error:

ImportError: C extension: No module named timedeltas not built. If you want to import pandas from the source directory, you may need to run 'python setup.py build_ext --inplace --force' to build the C extensions first. Failed to execute script main

I am using
Python version 2.7
Pandas Version 0.22.0

and running below cmd:

sudo py-cloud-fn test-flask-bigquery1 http --python_version 2.7 -p -f main.py && cd cloudfn/target && gcloud beta functions deploy test-flask-bigquery1 --trigger-http --stage-bucket <bucketname> --memory 2048MB && cd ../..

Please provide the solution for this.

This seems to be an error with C extensions and building them for the cloud function. It might be an easy task, it might not but I don't currently have a solution for you, unfortunately. I would recommend cloning the repository and fiddling about with the source code. Maybe there are some options in pyinstaller you can use? Also, as per the readme, there might be some more modules that must be added explicitly for import.

@MartinSahlen Can you tell me which file is used to install any dependency on Cloud Function?

@MartinSahlen
Found some links to solve the above mentioned issues,but don't know how to use it inside your code

1) https://github.com/pyinstaller/pyinstaller/issues/3015
2) https://github.com/pyinstaller/pyinstaller/pull/2998/commits/017b247064f9bd51a620cfb2172c05d63fc75133

Can you do the above changes or tell me how to do changes?

Thanks, I should be able to get that into an update. I also have some other issues that seems mostly related to hidden imports - it seems that just updating pyinstaller version should fix this issue if the links you are referring to are correct.

@SushantVarshney I think this Hooks: Add hook-pandas.py to fix issue should help you resolve the issue

Just add '--hidden-import', 'pandas._libs.tslibs.timedeltas', inside cloud-functions-python/cloudfn/cli.py build function, then BUILD INSTALL the cloud-function-python

You should be able to solve it