如何使用诗歌开始一个新的 Django 项目?
使用 virtualenv 很简单:
virtualenv -p python3 env_name --no-site-packages
source env_name/bin/activate
pip install django
django-admin.py startproject demo
pip freeze > requirements.txt
Run Code Online (Sandbox Code Playgroud)
使用 Poetry 与此等效的是什么?
当尝试使用 Poetry 安装 Python 依赖项时,出现以下错误:
$ poetry install
The currently activated Python version 2.7.15 is not supported by the project (>=3.6).
Trying to find and use a compatible version.
Using python3 (3.7.4)
Skipping virtualenv creation, as specified in config file.
Updating dependencies
Resolving dependencies... (1.7s)
[SolverProblemError]
The current project's Python requirement (>=3.6) is not compatible with some of the required packages Python requirement:
- pre-commit requires Python >=3.6.1
Because no versions of pre-commit match >2.2.0,<3.0.0
and pre-commit (2.2.0) requires Python …Run Code Online (Sandbox Code Playgroud) 一些背景:
我正在从事的项目使用python-ldap库。由于我们是一个混合操作系统开发团队(一些使用 Linux,一些使用 macOS 和一些 Windows),我试图让项目在所有环境中构建。不幸的是,python-ldapWindows 没有正式支持,但有由 Christoph Gohlke 维护的非官方轮子。我已经测试了轮文件,它工作正常。
问题:我如何告诉 Poetry 在 Windows 上使用轮子以及python-ldap在 Linux 和 macOS 上使用官方包?
我尝试了多种方法,包括使用多个约束依赖项和标记:
python-ldap = [
{ markers = "sys_platform == 'linux'", version = "*" },
{ markers = "sys_platform == 'win32'", path="lib/python_ldap-3.2.0-cp36-cp36m-win_amd64.whl" }
Run Code Online (Sandbox Code Playgroud)
......但是,从判断poetry.lock文件,似乎再标记合并,只是确定是否库应安装在所有:
[[package]]
category = "main"
description = "Python modules for implementing LDAP clients"
marker = "sys_platform == \"linux\" or sys_platform == \"win32\""
name = …Run Code Online (Sandbox Code Playgroud) 我最近开始尝试使用 Poetry 进行包和依赖管理,并且我仍在适应它与我使用 setuptools 的经验之间的差异。具体来说,我希望能帮助您理解如何处理以下场景。
我有一个数据文件,我想将其与存储在包子目录中的包捆绑在一起。使用 setup.py,我将在 setup.py 文件中指定文件和目录名称,然后使用 pkg_resources API 访问代码中的文件。
使用 Poetry 和 pyproject.toml 的等效方法是什么?
我正在将 Poetry 与 VSCode 一起使用,并且在运行此命令时遇到错误
\nimport apache_beam as beam\nfrom apache_beam.options.pipeline_options import PipelineOptions\n\nwith beam.Pipeline(options=PipelineOptions()) as p:\n pass # build your pipeline here\nRun Code Online (Sandbox Code Playgroud)\n错误是
\nTraceback (most recent call last):\n File "/path/to/pipeline.py", line 2, in <module>\n import apache_beam as beam\nImportError: No module named apache_beam\nRun Code Online (Sandbox Code Playgroud)\n我的pyproject.toml是
[tool.poetry.dependencies]\npython = "^3.7"\npytest = "^5.4.3"\napache-beam = "^2.23.0"\nRun Code Online (Sandbox Code Playgroud)\n当我跑步时poetry install,我只得到这个
\xe2\x9e\x9c poetry install\nInstalling dependencies from lock file\n\nNo dependencies to install or update\nRun Code Online (Sandbox Code Playgroud)\n这让我认为apache-beam安装正确。
我使用 …
如果你不小心在诗歌中安装了一个依赖作为主要依赖(即poetry add ...),有没有办法快速将它转移到开发依赖(即poetry add --dev ...),或者你必须卸载它并重新安装poetry add --dev?
我有一个 python 包,我想包含子模块中的一些特定文件,而不包含整个包,因此结构如下所示:
foo_project
|
+-- submodule_files
+-- bar.json
+-- other_stuff
+-- foo
+-- __init__.py
+-- foo.py
+-- <symlink to bar.json>
Run Code Online (Sandbox Code Playgroud)
诗歌 toml 文件有
packages = [
{ include = "foo" }
]
Run Code Online (Sandbox Code Playgroud)
使用 创建轮子时poetry build,会复制链接的文件,但不会复制链接本身
foo_wheel
|
+-- submodule_files
+-- bar.json
+-- foo
+-- __init__.py
+-- foo.py
Run Code Online (Sandbox Code Playgroud)
(为简洁起见,省略了wheel中的信息目录)
因此,一旦安装,python 包就缺少额外的文件
诗歌无法完成任何install或add不抛出EnvCommandError与无法找到一个setup.py“for”有关的事情soupsieve。
它查找版本“2020.12.21.3-lambda”,我不明白为什么它没有像其他依赖项一样使用普通版本从远程源加载依赖项。
\n$ poetry update\nUpdating dependencies\nResolving dependencies... (54.1s)\n\nWriting lock file\n\nPackage operations: 59 installs, 0 updates, 0 removals\n\n \xe2\x80\xa2 Installing soupsieve (2020.12.21.3-lambda): Failed\n\n EnvCommandError\n\n Command ['/home/git/my-project/.venv/bin/pip', 'install', '--no-deps', 'file:///home/Library/Caches/pypoetry/artifacts/22/36/ca/c8aae41f80011be881aa337cc80abc25ffd8542471c325e4410afa86c8/authorities-deployer-2020.12.21.3-lambda.zip'] errored with the following return code 1, and output: \n Looking in indexes: ... # censored proxy\n Processing /home/Library/Caches/pypoetry/artifacts/22/36/ca/c8aae41f80011be881aa337cc80abc25ffd8542471c325e4410afa86c8/authorities-deployer-2020.12.21.3-lambda.zip\n ERROR: Command errored out with exit status 1:\n command: /home/git/my-package/my-package/.venv/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/q6/xjd92kc90zsds149_rx08cy40000gp/T/pip-req-build-40kngare/setup.py'"'"'; __file__='"'"'/private/var/folders/q6/xjd92kc90zsds149_rx08cy40000gp/T/pip-req-build-40kngare/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\\r\\n'"'"', …Run Code Online (Sandbox Code Playgroud) 我正在尝试将SQLAlchemy 1.4 beta与 Poetry 一起使用。它在 PyPi 上发布。
Poetry 无法识别以下位置的 beta 包pyproject.toml:
[tool.poetry.dependencies]
SQLAlchemy = "^1.4.0b3"
Run Code Online (Sandbox Code Playgroud)
[tool.poetry.dependencies]
SQLAlchemy = "^1.4.0b3"
Run Code Online (Sandbox Code Playgroud)
Installing dependencies from lock file
Warning: The lock file is not up to date with the latest changes in pyproject.toml. You may be getting outdated dependencies. Run update to update them.
SolverProblemError
Because ... depends on SQLAlchemy (1.4.0b3) which doesn't match any versions, version solving failed.
Run Code Online (Sandbox Code Playgroud)
我如何告诉 Poetry 获取该包的 beta 版本?
poetry add numpy当我尝试在 Python 3.9.0 虚拟环境中使用 Python Poetry 1.1.4 包管理器 ( ) 安装 Numpy 1.20.2 模块时,我得到:
ERROR: Failed building wheel for numpy
Failed to build numpy
ERROR: Could not build wheels for numpy which use PEP 517 and cannot be installed directly
Run Code Online (Sandbox Code Playgroud)
我读了一些像这样的帖子,但从那时起,最新的 Numpy 版本似乎应该能够使用 3.9 构建(请参阅此官方 Numpy 发行文档和此答案)。我错过了什么?
编辑:使用 pip 21.0.1 (最新)
python-poetry ×10
python ×5
python-3.x ×3
django ×1
numpy ×1
pip ×1
python-ldap ×1
python-wheel ×1
virtualenv ×1