
- Python 3 Basic Tutorial
- Python 3 - Home
- What is New in Python 3
- Python 3 - Overview
- Python 3 - Environment Setup
- Python 3 - Basic Syntax
- Python 3 - Variable Types
- Python 3 - Basic Operators
- Python 3 - Decision Making
- Python 3 - Loops
- Python 3 - Numbers
- Python 3 - Strings
- Python 3 - Lists
- Python 3 - Tuples
- Python 3 - Dictionary
- Python 3 - Date & Time
- Python 3 - Functions
- Python 3 - Modules
- Python 3 - Files I/O
- Python 3 - Exceptions
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 Articles
- 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?
- How to use multiple modules with Python import Statement?
- How to install and import Python modules at runtime?
- Python import modules from Zip archives (zipimport)
- How can I get a list of locally installed Python modules?
- How to import the tags in Azure?
- How to import Python modules by default at the time of program starts?
- How to import a single function from a Python module?
- How we can bundle multiple python modules?
- How do I import all the submodules of a Python namespace package?
- How do I get IntelliJ to recognize common Python modules?
- How do I share global variables across modules in Python?
