我一直在从事一个项目,到目前为止只涉及构建一些云基础设施,现在我正在尝试添加一个 CLI来简化一些 AWS Lambda 的运行。不幸的是,使用构建的 sdist 和wheel 软件包poetry build似乎都不包含依赖项,因此我必须手动运行pip install所有这些软件包才能运行该命令。基本上我
poetry build在项目中运行,cd "$(mktemp --directory)",python -m venv .venv,. .venv/bin/activate,pip install /path/to/result/of/poetry/build/above, 进而此时可执行文件失败,因为pip没有安装任何包依赖项。如果我pip show PACKAGE该行Requires是空的。
Poetry 手册似乎没有指定如何将依赖项链接到构建的包,那么我该怎么办呢?
\n我正在使用一些可选的依赖项,这会干扰构建过程吗?需要明确的是,即使是非可选依赖项也不会显示在包依赖项中。
\npyproject.toml:
\n[build-system]\nrequires = ["poetry-core>=1.0.0"]\nbuild-backend = "poetry.core.masonry.api"\n\n[tool.black]\nline-length = 100\n\n[tool.coverage.report]\nexclude_lines = [\n \'if TYPE_CHECKING:\',\n \'if …Run Code Online (Sandbox Code Playgroud) 我有一个 WSL 实例 Ubuntu 20.04,并且我创建了另一个 Ubuntu 18.04 WSL 实例。
\n我在 20.04 上安装了 Poetry,没有出现任何问题。
\n我正在尝试使用命令在 Ubuntu 18.04 实例上安装 Poetry curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python3 -。
目前,我的 $HOME 环境变量指向/home/fromzeroedu.
然而,安装后,Poetry 已安装在我的 Windows 用户主目录中:
\n$ which poetry\n/mnt/c/Users/j/.poetry/bin/poetry\nRun Code Online (Sandbox Code Playgroud)\n如果我尝试获取版本,我会得到:
\n$ poetry --version\n/usr/bin/env: \xe2\x80\x98python\\r\xe2\x80\x99: Permission denied\nRun Code Online (Sandbox Code Playgroud)\nPOETRY_HOME我什至尝试在安装之前设置:
export POETRY_HOME=/home/fromzeroedu/.poetry/bin/poetry\nRun Code Online (Sandbox Code Playgroud)\n但 Poetry 仍然安装在 Windows 用户目录中。
\n有时候我很喜欢诗...
\n理解Python诗歌1
\n我遇到了一个奇怪的问题。\n一个小应用程序 - 字典,在命令行中工作:
\n$ lexi\nUsage: lexi word\n\n$ lexi zoo\n\xd0\xb7\xd0\xbe\xd0\xbe\xd0\xbf\xd0\xb0\xd1\x80\xd0\xba\n\n$ lexi qwerty\nThere\'s not word \'qwerty\' is in the lexicon\nRun Code Online (Sandbox Code Playgroud)\n项目结构:
\n.\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 poetry_test\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 __init__.py\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 data\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 lexicon.json # dictionary file\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 lexi.py\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 pyproject.toml\nRun Code Online (Sandbox Code Playgroud)\n词典.py:
\n#!/usr/bin/env python3\n \nimport sys\nimport json\n \nLEXICON_DB = "poetry_test/data/lexicon.json"\n \n \ndef main():\n args = sys.argv\n if len(args) != 2:\n print("Usage: lexi word")\n sys.exit(1)\n \n word = args[1]\n lexicon = json.load(open(LEXICON_DB))\n translation = lexicon.get(word)\n if translation:\n print(translation)\n else:\n print(f"There\'s not …Run Code Online (Sandbox Code Playgroud) 当我用诗歌添加tensoflow(诗歌添加张量流)时,我收到此错误:
Using version ^2.7.0 for tensorflow
Updating dependencies
Resolving dependencies... (0.8s)
SolverProblemError
The current project's Python requirement (>=3.6,<4.0) is not compatible with some of the required packages Python requirement:
- tensorflow-io-gcs-filesystem requires Python >=3.6, <3.10, so it will not be satisfied for Python >=3.10,<4.0
- tensorflow-io-gcs-filesystem requires Python >=3.6, <3.10, so it will not be satisfied for Python >=3.10,<4.0
- tensorflow-io-gcs-filesystem requires Python >=3.6, <3.10, so it will not be satisfied for Python >=3.10,<4.0
....
For tensorflow-io-gcs-filesystem, a possible solution …Run Code Online (Sandbox Code Playgroud) 我使用 IPython 和%bookmarkmagic 命令,但限制是我需要退出 IPython shell 才能激活虚拟环境,然后重新启动 IPython。
有没有办法内置到 IPython、第三方包或已知的 hack 中,让我在不退出 IPython shell 的情况下激活环境?
# within ipython shell
exit
# bash shell
cd path/of/my/project
poetry shell # or pipenv shell
ipython
Run Code Online (Sandbox Code Playgroud)
%cd -b demographics
# activate venv
import package # from that env
Run Code Online (Sandbox Code Playgroud) 我在我的旧笔记本电脑上设置了一个项目,并在本地安装了 Postgresql,并使用 Poetry 作为包管理器。现在我搬到另一台笔记本电脑上。在这一项上,我想使用 Docker 中的 Postgres,所以我没有安装它。但是当我运行poetry install从文件设置项目时poetry.lock,它无法安装 Psycopg2 并出现错误:
Error: pg_config executable not found.
Run Code Online (Sandbox Code Playgroud)
据我搜索,它需要在本地安装 Postgres。那么,如何使用 Docker 中的 Postgres 从锁定文件安装 Psycopg2?
我最近迁移到poetry我的依赖项管理,所以如果我的问题超出了poetry这里的范围,请原谅。
我的最终目标是创建一个RPM 包,其中包含一个virtualenv,其中安装了我的软件及其所有依赖项。然后,该 RPM 将提供与安装该软件的系统隔离的软件。
我在使用poetry install我的virtualenv. 一旦我的软件的源目录被删除,我的CLI就无法再工作。
我创建了一个简单的存储库来重现问题:https ://github.com/riton/python-poetry-venv
这是我正在使用的poetry:
#!/bin/bash -ex
VENV_DIR="/venv"
SRC_DIR="/src"
ALT_SRC_DIR="/src2"
USER_CACHE_DIR="~/.cache"
# Copy directory (cause we're mounting it read-only in the container)
# and we want to remove the source directory later on
cp -r $SRC_DIR $ALT_SRC_DIR
# We'll remove this directory to test if the soft is still working
# …Run Code Online (Sandbox Code Playgroud) 我在一个存储库中有两个 Python 项目,它们都依赖于共享实用程序包。我的目标是将这两个项目分别打包在一个软件分发包中(即一个.tzr.gz文件)
我目前正在使用以下方法完成此操作setuptools和setup.py文件来完成这项工作,但遇到了困难。我更愿意使用 Poetry 来分别管理和打包这两个项目。
请考虑我的问题的“最小重现”:
\nrepo\n project1/ \n __init__.py\n main_module.py\n pyproject.toml\n project2/ \n __init__.py\n main_module.py\n pyproject.toml\n util/\n __init__.py\n util_module.py\nRun Code Online (Sandbox Code Playgroud)\n我试图通过修改Poetryutil在构建时包含该包project1project.toml:
[tool.poetry]\nname = "project1"\nversion = "0.1.0"\ndescription = ""\nauthors = [""]\npackages = [\n { include = "../util/*.py" }\n]\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"\n\nRun Code Online (Sandbox Code Playgroud)\n当我跑步时poetry build我收到此错误:
Building project1 (0.1.0)\n - Building sdist\n\n ValueError\n\n \'C:\\\\repo\\\\util\\\\__init__.py\' is not in the …Run Code Online (Sandbox Code Playgroud) 我需要将我的版本降级poetry到 version 1.2.1。
目前,它是1.2.2.
>>> poetry --version
Poetry (version 1.2.2)
Run Code Online (Sandbox Code Playgroud)
我使用以下命令:
>>> curl -sSL https://install.python-poetry.org | POETRY_VERSION=1.2.1 python3 -
Retrieving Poetry metadata
The latest version (1.2.1) is already installed.
Run Code Online (Sandbox Code Playgroud)
但我听说1.2.1已经安装了。但诗版仍停留在原著之上。
>>> poetry --version
Poetry (version 1.2.2)
Run Code Online (Sandbox Code Playgroud)
这里给出的答案不起作用 ( poetry self update@1.2.1) =>The command "self" does not exist.
我在这里做错了什么?
我有一个使用 FastAPI 或 Django 等框架构建的 Web 应用程序,我的项目使用 Poetry 来管理依赖项。
我没有找到任何与此类似的主题。
问题是:我应该在生产 dockerfile 中安装诗歌并使用诗歌安装依赖项,还是应该导出requirements.txt并在我的 docker 映像中使用 pip?
实际上,我requirements.txt在部署应用程序之前将其导出到项目的根目录,然后在 docker 映像中使用它。
我的动机是,我不需要在 dockerfile 中使用诗歌的“复杂性”,因为它requirements.txt已经由诗歌生成,并且在图像中使用它将生成 docker 构建的新步骤,这可能会影响构建速度。
然而,我看到很多带有诗歌安装的 dockerfiles,这让我觉得我对该工具的使用很糟糕。
python-poetry ×10
python ×9
docker ×2
virtualenv ×2
ipython ×1
pip ×1
pipenv ×1
postgresql ×1
psycopg2 ×1
requirements ×1
sdist ×1
tensorflow ×1
ubuntu ×1
windows ×1
wsl-2 ×1