我在将依赖项安装到我的 Poetry 项目中时遇到问题。如果我运行(如https://python-poetry.org/docs/basic-usage/poetry new中所述),我可以创建一个新项目:
$ poetry new scipy-test\nCreated package scipy_test in scipy-test\nRun Code Online (Sandbox Code Playgroud)\n删除本次复制不需要的一些文件后,我的项目结构如下所示:
\n$ tree .\n.\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 pyproject.toml\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 scipy_test\n \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 __init__.py\n\n1 directory, 2 files\nRun Code Online (Sandbox Code Playgroud)\n我的pyproject.toml文件如下所示:
[tool.poetry]\nname = "scipy-test"\nversion = "0.1.0"\ndescription = ""\nauthors = ["Your Name <you@example.com>"]\n\n[tool.poetry.dependencies]\npython = "^3.9"\n\n[tool.poetry.dev-dependencies]\npytest = "^5.2"\n\n[build-system]\nrequires = ["poetry-core>=1.0.0"]\nbuild-backend = "poetry.core.masonry.api"\nRun Code Online (Sandbox Code Playgroud)\n当我运行时poetry add scipy,它会尝试安装最新版本的 SciPy,目前是 1.8.1。我收到以下错误:
$ poetry add scipy\nCreating virtualenv scipy-test-4EDXm154-py3.9 in /home/mattwelke/.cache/pypoetry/virtualenvs\nUsing version ^1.8.1 for scipy\n\nUpdating dependencies\nResolving dependencies... (0.1s)\n\n SolverProblemError\n\n The current …Run Code Online (Sandbox Code Playgroud) 我正在尝试在 VS Code 中设置本地开发环境,在其中我可以获得 Cloud Composer/Apache Airflow 使用的包的代码完成。到目前为止,我已经成功地使用了虚拟环境(使用 创建python -m venv .venv)和一个非常小的requirements.txt文件,该文件仅包含安装到本地环境中的 Airflow 包。
该文件是这样的:
apache-airflow==1.10.15
Run Code Online (Sandbox Code Playgroud)
我可以pip install -r requirements.txt在 VS Code 中激活我的虚拟环境后运行,将其安装到我的虚拟环境中,之后我在 VS Code 中获得其文档中快速入门 DAG 的代码完成,即BashOperator:

随着我学习更多教程,我希望获得更多代码补全。例如,按照KubernetesPodOperator教程(https://cloud.google.com/composer/docs/how-to/using/using-kubernetes-pod-operator),我收到此错误,并且 VS Code 无法识别导入:
无法解析导入“airflow.providers.cncf.kubernetes.operators.kubernetes_pod”Pylance(reportMissingImports)
我认为下一步最好是将与在 Cloud Composer 环境中运行的完全相同的 PyPI 包安装到我的虚拟环境中。我使用页面https://cloud.google.com/composer/docs/concepts/versioning/composer-versions来查看安装了哪些软件包:
所以我的requirements.txt文件看起来像这样:
absl-py==1.0.0
alembic==1.5.7
amqp==2.6.1
apache-airflow==1.10.15+composer
apache-airflow-backport-providers-apache-beam==2021.3.13
apache-airflow-backport-providers-cncf-kubernetes==2021.3.3
apache-airflow-backport-providers-google==2022.4.1+composer
apache-beam==2.37.0
apispec==1.3.3
appdirs==1.4.4
argcomplete==1.12.2
astunparse==1.6.3
attrs==20.3.0
Babel==2.9.0
bcrypt==3.2.0
billiard==3.6.3.0
cached-property==1.5.2
cachetools==4.2.1
cattrs==1.1.2
celery==4.4.7
certifi==2020.12.5
cffi==1.14.5
chardet==4.0.0
click==6.7 …Run Code Online (Sandbox Code Playgroud) python pip google-cloud-platform airflow google-cloud-composer
在Ruby on Rails中,我意识到它本质上是同步的,并且开发人员可以异步地执行同步事务.在我做的一些Web开发中,我开始有多个操作,比如对外部API的GET请求,我希望它们同时启动,因为一个不依赖于另一个的结果.我找到了似乎运行良好的concurrent-ruby库.通过将它混合到您创建的类中,类的方法具有在后台线程上运行的异步版本.这导致我编写如下代码,其中FirstAsyncWorker和SecondAsyncWorker是我编码的类,其中我混合了Concurrent :: Async模块,并编码了一个名为"work"的方法,它发送了一个HTTP请求:
def index
op1_result = FirstAsyncWorker.new.async.work
op2_result = SecondAsyncWorker.new.async.work
render text: results(op1_result, op2_result)
end
Run Code Online (Sandbox Code Playgroud)
但是,控制器将在操作方法执行结束时隐式呈现响应.因此,响应在op1_result和op2_result获取值之前发送,并且发送到浏览器的唯一内容是"#".
到目前为止,我的解决方案是使用Ruby线程.我写的代码如下:
def index
op1_result = nil
op2_result = nil
op1 = Thread.new do
op1_result = get_request_without_concurrent
end
op2 = Thread.new do
op2_result = get_request_without_concurrent
end
# Wait for the two operations to finish
op1.join
op2.join
render text: results(op1_result, op2_result)
end
Run Code Online (Sandbox Code Playgroud)
我不使用互斥锁,因为两个线程不访问相同的内存.但我想知道这是否是最佳方法.有没有更好的方法来使用concurrent-ruby库或其他更适合这种情况的库?
我有以下代码:
template<typename T>
bool validate(const T& minimum, const T& maximum, const T& testValue)
{
return testValue >= minimum && testValue <= maximum;
}
template<>
bool validate<const char&>(const char& minimum, const char& maximum, const char& testValue)
{
// Allows comparisons with char arguments, ignoring case
// Localize by calling previously defined function
return validate(toupper(minimum), toupper(maximum), toupper(testValue));
}
Run Code Online (Sandbox Code Playgroud)
第一个模板用于任何输入的类型,专门化用于文字字符.代码编译并运行main.cpp来测试它,但经过测试,我发现没有调用特化.它调用主模板.我无法弄清楚为什么.
我正在尝试将 Protobuf 与 Google 的官方 Gradle 插件、Gradle、VS Code 和小型 Java 应用程序一起使用来测试工作流程。
我无法让 VS Code 识别生成的 Java 源代码,并且在终端中,当我尝试使用 Gradle 构建应用程序时,也无法让 Gradle 识别代码。
当我尝试引用生成的代码时,VS Code 显示此信息:
当我尝试构建时,Gradle 显示以下错误:
> Task :app:compileJava FAILED
/home/mattgbi/vscode-gradle-protobuf-repro/app/src/main/java/vscode/gradle/protobuf/repro/App.java:14: error: cannot find symbol
System.out.println(Person.class);
^
symbol: class Person
location: class App
1 error
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:compileJava'.
> Compilation failed; see the compiler error output for details.
* Try:
> Run with --stacktrace option to get the …Run Code Online (Sandbox Code Playgroud) java protocol-buffers gradle gradle-plugin visual-studio-code