我有一个PythonFlask 应用程序,我想将其部署到Azure Web应用程序.

For some reason the venv that gets created during the build is not keeping the packages that get installed and I don't understand why. As an example, the requirements.txt has openai==1.12.0 in it.
The build job prints Successfully installed [...] openai-1.12.0 [...]. That sounds like it should be fine.

然后,部署成功后,我在Web应用程序的Azure shell中运行pip list(antenv虚拟环境处于活动状态)以查看已安装的内容并获得没有openai的列表.如果我列出venv文件夹的内容,它将包含我想要安装的所有包.

这是构建作业(job)的yaml:

          - script: |
              sudo apt-get install python3.11-dev portaudio19-dev
              ls
              python -m venv antenv
              source antenv/bin/activate
              python -m pip install --upgrade pip
              pip install -r ./requirements.txt
            workingDirectory: "$(projectRoot)"
            displayName: "Install requirements"

I also tried to change the pip install line to
pip install --target="./.python_packages/lib/site-packages" -r ./requirements.txt
with no luck, the packages are in that folder but not in use by the venv.
Am I doing anything obviously wrong? Any tips?

编辑: 这是我完成pip install步后的pip list分:


h11                    0.14.0
httpcore               1.0.3
httpx                  0.26.0
idna                   3.6
isodate                0.6.1
itsdangerous           2.1.2
Jinja2                 3.1.3
langdetect             1.0.9
MarkupSafe             2.1.5
msrest                 0.7.1
numpy                  1.26.4
oauthlib               3.2.2
openai                 1.12.0
openpyxl               3.1.2
pandas                 2.2.0
pip                    24.0
PyAudio                0.2.14
pydantic               2.6.1
pydantic_core          2.16.2
python-dateutil        2.8.2
python-dotenv          1.0.1
pytz                   2024.1
requests               2.31.0
requests-oauthlib      1.4.0
setuptools             65.5.0
six                    1.16.0
sniffio                1.3.0
SpeechRecognition      3.10.1
tqdm                   4.66.2
typing_extensions      4.9.0
tzdata                 2024.1
urllib3                2.2.0
waitress               3.0.0
Werkzeug               3.0.1
WTForms                3.1.2

这是在Azure SSH shell的venv中运行pip list的结果:

Package              Version
-------------------- -------
appsvc-code-profiler 1.0.0
blinker              1.7.0
click                8.1.7
debugpy              1.8.1
distlib              0.3.8
filelock             3.13.1
Flask                3.0.2
gunicorn             21.2.0
itsdangerous         2.1.2
Jinja2               3.1.3
markdown-it-py       3.0.0
MarkupSafe           2.1.5
mdurl                0.1.2
objprint             0.2.3
orjson               3.8.10
packaging            24.0
pip                  24.0
platformdirs         4.2.0
psutil               5.9.8
Pygments             2.17.2
rich                 13.7.1
setuptools           69.1.0
subprocess32         3.5.4
virtualenv           20.25.1
vizplugins           0.1.3
viztracer            0.15.6
Werkzeug             3.0.1
wheel                0.42.0

推荐答案

事实证明,Azure ssh shell中似乎缺少包. 我的问题是Azure没有找到我的入口点,我必须指定它才能运行我的应用程序. 尽管pip list看起来没有所有包,但实际的应用程序正在安装正确的包来运行.

Python相关问答推荐

使用子字符串动态更新Python DataFrame中的列

Plotly Dash函数来切换图形参数-pPython

pyramid 内部数组中的连续序列-两极

机器人与Pyton Minecraft服务器状态不和

使用Python Cerberus初始化一个循环数据 struct (例如树)(v1.3.5)

将轨迹优化问题描述为NLP.如何用Gekko解决这个问题?当前面临异常:@错误:最大方程长度错误

如何在Python中使用io.BytesIO写入现有缓冲区?

如何在msgraph.GraphServiceClient上进行身份验证?

通过Selenium从页面获取所有H2元素

如何制作10,000年及以后的日期时间对象?

如何从在虚拟Python环境中运行的脚本中运行需要宿主Python环境的Shell脚本?

如果值发生变化,则列上的极性累积和

计算每个IP的平均值

导入...从...混乱

改进大型数据集的框架性能

Python脚本使用蓝牙运行在Windows 11与raspberry pi4

numpy.unique如何消除重复列?

巨 Python :逆向猜谜游戏

通过追加列表以极向聚合

如何在Great Table中处理inf和nans