1

I'm developing an action in IBM-Clound functions, that is called in Watson Assistant dialog.This action has to make a SOAP petition to a WS. The problem is when I try to import the suds library because It is not in the default python libraries. How can I add the library?

Thanks in advance.

dgalan
  • 79
  • 7
  • Does this answer your question? https://stackoverflow.com/questions/51901638/ibm-cloud-functions-how-to-use-and-upload-own-libraries – Arlemi Jan 03 '19 at 11:05

1 Answers1

3

You can package Python dependencies by using a virtual environment, virtualenv. The virtual environment allows you to link additional packages that can be installed by using pip, for example.

To install dependencies, package them in a virtual environment, and create a compatible OpenWhisk action:

Create a requirements.txt file that contains the pip modules and versions to install.

Install the dependencies and create a virtual environment. The virtual environment directory must be named virtualenv. To ensure compatibility with the OpenWhisk runtime container, package installations inside a virtual environment must use the image that corresponds to the kind.

For kind python:2 use the docker image openwhisk/python2action.

For kind python:3.6 use the docker image ibmfunctions/action-python-v3.6.

For kind python:3.7 use the docker image ibmfunctions/action-python-v3.7.

docker run --rm -v "$PWD:/tmp" ibmfunctions/action-python-v3 bash  -c "cd tmp && virtualenv virtualenv && source virtualenv/bin/activate && pip install -r requirements.txt"

Package the virtualenv directory and any additional Python files. The source file that contains the entry point must be named main.py.

 zip -r helloPython.zip virtualenv __main__.py

Create the action helloPython.

ibmcloud fn action create helloPython --kind python-jessie:3 helloPython.zip

For more details, refer this link

Vidyasagar Machupalli
  • 2,737
  • 1
  • 19
  • 29