

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How can I import modules for a Python Azure Function?
As of writing this, Python support for Azure Functions is experimental. So right now there is no way to directly get a module from a package manager to be installed on your instance. You'll need to bring your own modules with code. No modules are available by default on Azure Functions. You can add them by uploading it via the portal UX or kudu (which is handy for lots of files).
If you don't mind using virtualenv, there is an alternative.
Create your python script on Azure Functions.
Open a Kudu console and cd to your script location.
Create a virtualenv in this folder (python -m virtualenv myvenv)
Load this venv (cd myvenv/Scripts and call activate.bat). Now your shell should be prefixed by (myvenv).
Update pip (python -m pip install -U pip)
Install your dependencies using pip. (python -m pip install django)
Now wherever you need to import scripts, append the sys.path variable with this env. For example,
import sys, os.path sys.path.append(os.path.abspath(os.path.join(os.path.dirname( __file__ ), 'myvenv/Lib/site-packages')))
- Related Questions & Answers
- Can we iteratively import python modules inside a for loop?
- How we can import Python modules in Jython?
- How we can import Python modules without installing?
- How I can dynamically import Python module?
- Python import modules from Zip archives (zipimport)
- How can I get a list of locally installed Python modules?
- How to install and import Python modules at runtime?
- How to use multiple modules with Python import Statement?
- How to import the tags in Azure?
- How to import a single function from a Python module?
- How we can bundle multiple python modules?
- How to import Python modules by default at the time of program starts?
- How do I import all the submodules of a Python namespace package?
- How can a Python function return a function?
- How do I get IntelliJ to recognize common Python modules?