有奖捉虫:云通信与企业服务文档专题,速来> HOT

Python 版本选择

目前支持的 Python 开发语言包括如下版本:
Python 3.10
Python 3.9
Python 3.7
Python 3.6
Python 2.7
您可以在函数创建时,选择您所期望使用的运行环境,Python 3.10、Python 3.9、Python 3.7、Python 3.6 或 Python 2.7。您可以在 这里 查看 Python 官方对 Python 2 或 Python 3 语言选择的建议。

相关环境变量

目前运行环境中内置的 Python 相关环境变量见下表:
环境变量 Key
具体值或值来源
PYTHONDONTWRITEBYTECODE
x
PYTHONPATH
/var/user:/opt
更多详细环境变量说明请参见 环境变量说明

已包含的库及使用方法

注意
Python 3.7 及之后版本,平台不再额外内置依赖库。代码运行所需依赖,请参考 依赖安装 进行安装。

COS SDK

云函数在 Python 3.6 和 Python 2.7 的运行环境中已集成了 COS SDK。您可以通过以下方式在代码中引入 COS SDK 并使用:
from qcloud_cos import CosConfig
from qcloud_cos import CosS3Client
有关 COS SDK 的详细使用说明,请参见 COS Python SDK 说明

内置的库列表

Python 3.6 云端运行时已支持的库如下表:
说明
若您需要使用表中尚未支持的库,请在本地安装并打包上传后使用。详情请参见 安装依赖库
库名称
版本
absl-py
0.2.2
asn1crypto
0.24.0
astor
0.7.1
bleach
1.5.0
certifi
2019.3.9
cffi
1.12.2
chardet
3.0.4
cos-python-sdk-v5
1.6.6
cryptography
2.6.1
dicttoxml
1.7.4
gast
0.2.0
grpcio
1.13.0
html5lib
0.9999999
idna
2.8
iniparse
0.4
Markdown
2.6.11
mysqlclient
1.3.13
numpy
1.15.0
Pillow
6.0.0
pip
9.0.1
protobuf
3.6.0
psycopg2-binary
2.8.2
pycparser
2.19
pycurl
7.43.0
PyMySQL
0.9.3
pytz
2019.1
qcloud-image
1.0.0
qcloudsms-py
0.1.3
requests
2.21.0
serverless-db-sdk
0.0.1
setuptools
28.8.0
six
1.12.0
tencentcloud-sdk-python
3.0.65
tencentserverless
0.1.4
tensorboard
1.9.0
tensorflow
1.9.0
tensorflow-serving-api
1.9.0
termcolor
1.1.0
urllib3
1.24.2
Werkzeug
0.14.1
wheel
0.31.1
Python 2.7 云端运行时已支持的库如下表:
库名称
版本
absl-py
0.2.2
asn1crypto
0.24.0
astor
0.7.1
backports.ssl-match-hostname
3.4.0.2
backports.weakref
1.0.post1
bleach
1.5.0
cassdk
1.0.2
certifi
2017.11.5
cffi
1.12.2
chardet
3.0.4
cos-python-sdk-v5
1.6.6
cryptography
2.6.1
dicttoxml
1.7.4
enum34
1.1.6
funcsigs
1.0.2
futures
3.2.0
gast
0.2.0
grpcio
1.13.0
html5lib
0.9999999
idna
2.6
iniparse
0.4
ipaddress
1.0.22
Markdown
2.6.11
mock
2.0.0
mysqlclient
1.3.13
nose
1.3.7
numpy
1.14.5
ordereddict
1.1
pbr
4.1.0
Pillow
6.0.0
pip
18
protobuf
3.6.0
psycopg2-binary
2.8.2
pyaml
2019.4.1
pycparser
2.19
pycurl
7.43.0.1
pygpgme
0.3
PyMySQL
0.9.3
pytz
2019.1
PyYAML
5.1
qcloud-image
1.0.0
qcloudsms-py
0.1.3
requests
2.18.4
serverless-db-sdk
0.0.1
setuptools
39.1.0
six
1.11.0
tencentcloud-sdk-python
3.0.65
tencentserverless
0.1.4
tensorboard
1.9.0
tensorflow
1.9.0
tensorflow-serving-api
1.9.0
termcolor
1.1.0
urlgrabber
3.10.2
urllib3
1.22
Werkzeug
0.14.1
wheel
0.31.1