简体   繁体   English

AWS-CDK 无法在 Python 中导入核心

[英]AWS-CDK cannot import core in Python

I have recently been asked to learn the AWS-CDK module in Python to handle deployments and following the examples on in the AWS-CDK documentation I am getting an error that indicates it cannot import 'core'我最近被要求学习 Python 中的 AWS-CDK 模块来处理部署,并按照 AWS-CDK 文档中的示例进行操作,我收到一个错误,表明它无法导入“核心”

I have created a virtual environment that is using Python 3.6.6 and am running CDK version 1.16.2 (build 5893301) all running on a Windows 10 64-bit machine in VSCode我创建了一个使用 Python 3.6.6 的虚拟环境,并且正在运行 CDK 版本 1.16.2(内部版本 5893301),所有这些都在 VSCode 中的 Windows 10 64 位机器上运行

from aws_cdk import core

I would expect this to just load the constructor but it just returns the error:我希望这只会加载构造函数,但它只会返回错误:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name 'core'

I have searched and searched and I cannot seem to find what I am doing wrong or anything that contradicts the documentation on the CDK site.我进行了搜索和搜索,但似乎找不到我做错了什么或任何与 CDK 网站上的文档相矛盾的东西。 Any insight would be appreciated.任何见解将不胜感激。

This worked for me.这对我有用。 Might be related to conda / venv interactions.可能与 conda / venv 交互有关。

pip3 install -r requirements.txt --user

Is aws_cdk.core installed in your environment?您的环境中是否安装了 aws_cdk.core? I have this:我有这个:

pip list|grep core
aws-cdk.core                        1.68.0

I noticed that the cdk.json "app" value can also generate this error.我注意到 cdk.json "app" 值也会产生这个错误。
Example of the cdk.json file which used to generate the error:用于生成错误的 cdk.json 文件示例:

{
  "app": "python3 app.py",
  "context": {
    ...
  }
}

Changing the app value from python3 to python resolved the problem for me.将应用程序python3更改为python为我解决了这个问题。 Like this:像这样:

{
  "app": "python app.py",
  "context": {
    ...
  }
}

I am not entirely sure why this happens as I am using python 3.8 and I can see a python.exe in the python path/environment variables.我不完全确定为什么会发生这种情况,因为我使用的是 python 3.8,我可以在 python 路径/环境变量中看到 python.exe。 If I deactivate the virtual env, and I have cdk installed globally, this problem goes away regardless of whether I use python or python3 for the app value.如果我停用虚拟环境,并且全局安装了 cdk,则无论我使用 python 还是 python3 作为应用程序值,这个问题都会消失。 Therefore, I suspect it's got to do something with environment paths.因此,我怀疑它与环境路径有关。

aws-cdk-lib==2.34.0
constructs>=10.0.0,<11.0.0
aws-cdk.aws-kinesisfirehose-alpha
aws_cdk.aws-kinesisfirehose-destinations-alpha
aws_cdk.core

pip list|grep core

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM