python - 将 Python Flask Web API 部署到 Azure 门户时出现依赖关系问题

标签 python pip azure-web-app-service azureportal

我正在尝试将python Flask Web api部署到azure门户,但遇到依赖项安装问题,如下图所示。 enter image description here

我已经将扩展 -Python 3.5.4 x64 添加到我的 Azure Web 应用程序中,并且还对所有依赖项使用最新版本,如您在requirements.txt 文件中看到的那样。

enter image description here 有人可以帮忙吗?

我也尝试过从 Azure Kudu DebugConsole 安装/升级安装工具,但这会导致访问被拒绝的问题。

Kudu Remote Execution Console
Type 'exit' then hit 'enter' to get a new CMD process.
Type 'cls' to clear the console

Microsoft Windows [Version 10.0.14393]
(c) 2016 Microsoft Corporation. All rights reserved.

D:\home>pip install -U setuptools
'pip' is not recognized as an internal or external command,
operable program or batch file.

D:\home>python -m pip install -U setuptools
Downloading/unpacking setuptools from https://files.pythonhosted.org/packages/e7/16/da8cb8046149d50940c6110310983abb359bbb8cbc3539e6bef95c29428a/setuptools-40.6.2-py2.py3-none-any.whl#sha256=88ee6bcd5decec9bd902252e02e641851d785c6e5e75677d2744a9d13fed0b0a
Installing collected packages: setuptools
  Found existing installation: setuptools 2.1
    Uninstalling setuptools:
Cleaning up...
Exception:

Traceback (most recent call last):
  File "D:\Python34\lib\site-packages\pip\basecommand.py", line 122, in main
    status = self.run(options, args)
  File "D:\Python34\lib\site-packages\pip\commands\install.py", line 283, in run
    requirement_set.install(install_options, global_options, root=options.root_path)
  File "D:\Python34\lib\site-packages\pip\req.py", line 1431, in install
    requirement.uninstall(auto_confirm=True)
  File "D:\Python34\lib\site-packages\pip\req.py", line 598, in uninstall
    paths_to_remove.remove(auto_confirm)
  File "D:\Python34\lib\site-packages\pip\req.py", line 1836, in remove
    renames(path, new_path)
  File "D:\Python34\lib\site-packages\pip\util.py", line 295, in renames
    shutil.move(old, new)
  File "D:\Python34\lib\shutil.py", line 535, in move
    os.unlink(src)
PermissionError: [WinError 5] Access is denied: 'd:\\python34\\lib\\site-packages\\__pycache__\\easy_install.cpython-34.pyc'

Storing debug log for failure in D:\home\pip\pip.log

最佳答案

在 Azure WebApps 上,您无权在除 D:\home 之外的路径 D:\ 下执行任何写入操作。因此,当您想为 D:\Python34 中的默认 python 运行时安装 pip 时,会导致错误 PermissionError Access is returned

唯一的方法是通过 Kudo 安装 Python 站 pip 扩展并配置 web.config 以使用它而不是默认的扩展。有一个现有 SO 线程的答案 Why is the azure app service django deploy keep failing?里面介绍了安装方法,您可以引用解决。

现在,我看到你已经安装了这个扩展,但是你调用的 python 命令仍然是默认的。解决办法如下。

  1. 通过命令 set PATH=D:\home\Python34;%PATH% 更改环境变量 path 以覆盖默认变量。
  2. 在 Kudo DebugConsole 中更改当前目录并移动到路径 D:\home\Python34 中,然后就可以直接调用新安装的 python 了。

希望有帮助。

关于python - 将 Python Flask Web API 部署到 Azure 门户时出现依赖关系问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53500358/

相关文章:

python - 因为我持有十六进制格式的字符串而不对字符串进行编码?

python - 按字符串分组和组合

python - 从源代码构建 mmh3 包

python - IMDBPy 安装 mysqlclient 失败 - Python 2.7 Windows

asp.net - Azure Web 应用服务之间的行为差​​异

python重试包-韧度: How to log the root cause of exception?

Python Beautiful Soup - 雅虎财经数据,年度与季度

azure - 迁移到应用服务移动应用程序后进行身份验证 : uid vs sid

python - pip 未与 python 一起安装,并且它不会自行安装

php - 如何在 Azure 应用程序服务 -> Web 应用程序 (Linux) 中启用 php 扩展