python - 带有 AWS codebuild : why the deactivate command is not found? 的 Virtualenv python

标签 python python-3.x amazon-web-services virtualenv aws-codebuild

我使用 AWS Codebuild 将 Python 代码从 GitHub 存储库上传到 AWS Lambda。因此,我使用 virtualenv 设置了虚拟 python 环境。

这是我的buildspec.yml:

version: 0.2
phases:
 install:
   commands:
     - echo "install step"
     - apt-get update
     - apt-get install zip -y
     - apt-get install python3-pip -y
     - pip install --upgrade pip
     - pip install --upgrade awscli
     # Define directories
     - export HOME_DIR=`pwd`
     - cd $HOME_DIR
     - export PREPROCESSING_DIR=$HOME_DIR/preprocessing
     - export COMPARE_DIR=$HOME_DIR/compareHilightGood
     - export NLTK_DATA=$HOME_DIR/nltk_data
 pre_build:
   commands:
     - echo "pre_build step"
     # Configure preprocessing virtual environement
     - cd $PREPROCESSING_DIR
     - virtualenv venv_preprocessing
     - . venv_preprocessing/bin/activate
     #  Install modules
     - pip install -U requests
     - pip install -U nltk
     #  NLTK download
     - python -m nltk.downloader -d $NLTK_DATA wordnet stopwords punkt
     - pip freeze > requirements.txt
     #  zip everything
     - mv $VIRTUAL_ENV/lib/python3.6/site-packages/* .
     - sudo zip -r9 preprocessing.zip .
     - source deactivate
     # Configure compare virtual environement
     - cd $COMPARE_DIR
     - virtualenv venv_compare
     - . venv_compare/bin/activate
     # install modules
     - pip install -U gensim
     - pip install -U pandas
     - pip freeze > requirements.txt
     # zip everything
     - mv $VIRTUAL_ENV/lib/python3.6/site-packages/* .
     - sudo zip -r9 compare.zip .
     - source deactivate
 build:
   commands:
     - echo 'build step'
     # preprocessing
     - cd $PREPROCESSING_DIR
     - aws s3 cp --recursive --acl public-read ./preprocessing.zip s3://lambda-preprocessing/
     - aws lambda update-function-code --function-name arn:aws:lambda:eu-west-3:671560023774:function:preprocessing --s3-bucket lambda-preprocessing --s3-key preprocessing.zip
     - aws lambda update-function-configuration --function-name arn:aws:lambda:eu-west-3:671560023774:function:preprocessing --environment 'Variables={NLTK_DATA=/var/task/nltk_data}'
     # compare
     - cd $COMPARE_DIR
     - aws s3 cp --recursive --acl public-read ./compare.zip s3://lambda-comparehilightgood/
     - aws lambda update-function-code --function-name arn:aws:lambda:eu-west-3:671560023774:function:preprocessing --s3-bucket lambda-comparehilightgood --s3-key compare.zip
 post_build:
   commands:
     - echo "post_build step"

pre_build 步骤中,我在两个 virtualenv 之间切换。因此,我使用 deactivate(或 source deactivate)。 但在这两种情况下,我都会收到此错误:

[Container] 2019/03/17 09:07:54 Running command source deactivate
/codebuild/output/tmp/script.sh: 4: /codebuild/output/tmp/script.sh: source: not found
 [Container] 2019/03/17 09:07:54 Command did not exit successfully source deactivate exit status 127
[Container] 2019/03/17 09:07:54 Phase complete: PRE_BUILD Success: false
[Container] 2019/03/17 09:07:54 Phase context status code: COMMAND_EXECUTION_ERROR Message: Error while executing command: source deactivate. Reason: exit status 127

无论如何,似乎没有找到命令sourcedeactivate。你知道为什么吗?

最佳答案

deactivate 不是一个可以sourced 的脚本,它是 在当前shell 环境中创建的一个shell 函数。 venv/bin/激活。因此,请尝试在不使用 source 的情况下仅使用 deactivate

关于source本身的错误,请注意命令。 venv/bin/activate 工作因此 shell 理解命令 . 但不是 source.

关于python - 带有 AWS codebuild : why the deactivate command is not found? 的 Virtualenv python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55205998/

相关文章:

amazon-web-services - 多个 API Gateway 实例,一个 lambda 函数

python - 如何组合数据框行

python - 查找 numpy 数组的所有 n 组(对、三元组、四元组等)

python - 在Python中匹配一大组(x,y)指向另一组具有异常值的点

python-3.x - 无法用 map 替换 pandas 数据框列中的值

amazon-web-services - 属性安全组的值必须是字符串列表类型

python - 为什么 AudioSegment 不读取 'mp3' ?

python - 将整数字符串拆分为所有可能的数字列表

python-3.x - 使用 lambda 中的 boto3 从 s3 读取和写入 excel 文件

amazon-web-services - 如何使用多个索引查询 AWS DynamoDB?