Kudu Console中SSH与Bash安装Python(3.x)包的差异分析
Great question! This is a common gotcha with Azure App Service's Kudu tooling, since the two environments behave surprisingly differently even though they're both part of Kudu. Let's break this down:
Core Differences Between SSH and Kudu Bash
User & Environment Isolation
SSH connects you directly to your App Service's application user context—this is the same user that runs your web app. The Kudu built-in Bash console, however, runs under the Kudu service's system user instead. These are two separate security contexts, so their environment variables (likePATH,PYTHONPATH) and available resources are completely isolated.Python Environment Paths
In an SSH session, you're using the Python interpreter tied to your web app: this could be a virtual environment you set up in/home/site/wwwroot, or the user-level Python installed in/home/.local/bin. The Kudu Bash console uses a global Python instance that's part of the Kudu service itself, which lives outside your app's directory structure and isn't shared with your site.Package Installation Locations
When you runpip installvia SSH, packages are installed to your app user's Python environment (e.g.,venv/lib/pythonX.X/site-packagesor/home/.local/lib/pythonX.X/site-packages). Packages installed in Kudu Bash go to the Kudu service's global Python directories, which your web app can't access—and vice versa.
Why pip list in Bash Doesn't Show SSH-Installed Packages
This boils down to using completely separate Python environments. To confirm this, run these commands in both contexts:
- In SSH:
which pythonandwhich pip— you'll see paths pointing to your app's Python (e.g.,/home/site/wwwroot/venv/bin/pip) - In Kudu Bash:
which pythonandwhich pip— you'll get paths to Kudu's global Python (e.g.,/usr/bin/pip)
Since each pip command is tied to a different interpreter, they only show packages installed in their respective environments. If you want to see SSH-installed packages from Kudu Bash, you need to explicitly call your app's pip executable, like:
/home/site/wwwroot/venv/bin/pip list # Or if no virtual environment: /home/.local/bin/pip list
内容的提问来源于stack exchange,提问作者artifiedai

