You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Alexa Skill Kit SDK时如何导入Python第三方库(如numpy)?

Fixing import numpy Runtime Error in Alexa Skill Development

Hey there, let's clear up the confusion here! While it might feel like this issue has nothing to do with the Alexa Skill Kit (ASK), the root cause is actually tied to where your skill code runs—AWS Lambda, which is the default backend execution environment for ASK skills. Lambda's base Python environment doesn't come pre-installed with numpy (or most third-party libraries), so trying to import it directly will throw a runtime error.

Here's a step-by-step fix that's more straightforward than uploading numpy source code:

  • Set up a local virtual environment to isolate your skill's dependencies

    1. Create a virtual environment: python -m venv alexa-skill-env
    2. Activate it:
      • Windows: alexa-skill-env\Scripts\activate
      • Mac/Linux: source alexa-skill-env/bin/activate
    3. Install both numpy and the ASK SDK: pip install numpy ask-sdk-core
  • Package your code and dependencies together

    1. Navigate to the site-packages folder inside your virtual environment (this is where numpy and other libraries are installed):
      • Windows: alexa-skill-env\Lib\site-packages
      • Mac/Linux: alexa-skill-env/lib/python3.x/site-packages (replace 3.x with your Python version)
    2. Copy all files and folders from site-packages into the same directory as your skill's main code file (usually lambda_function.py)
    3. Select your skill code file + all the copied dependency files, then zip them up directly (don't put everything inside a nested folder—Lambda needs the files at the root of the ZIP)
  • Upload the ZIP to Lambda

    1. Open the AWS Lambda console and find the function linked to your Alexa skill
    2. Go to the "Code" tab, click "Upload from" > ".zip file"
    3. Upload your packaged ZIP, save the function, and test your skill again

The reason you found solutions mentioning uploading numpy source code is that Lambda needs access to the library files to run your code—packaging the installed version (not raw source) is just a more reliable way to do this. ASK handles the skill's voice interaction logic, but your custom code (including numpy usage) runs on Lambda, so the two are connected behind the scenes.

内容的提问来源于stack exchange,提问作者Quynh Vo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 08:26:53