我使用 Poetry 作为依赖管理和打包工具开发了我的第一个 Python 包。
将我的工作发布到 PyPI 就像运行一样简单:
poetry publish --build
Run Code Online (Sandbox Code Playgroud)
现在,我想让我的包也可以在 conda 生态系统中使用。作为初步步骤,我尝试使用conda build.
这就是我的(匿名)meta.yaml文件的样子:
{% set version = "0.1.4" %}
package:
name: "<my-package-name>"
version: {{ version }}
source:
url: <URL-of-the-source-distribution-of-my-package-on-PyPI>.tar.gz
sha256: <SHA256-of-the-source-distribution-of-my-package-on-PyPI>
build:
noarch: python
script: python -m pip install .
requirements:
host:
- python
- pip
run:
- python
about:
license: MIT
license_familY: MIT
license_file: LICENSE
summary: "<Brief-project-description>"
Run Code Online (Sandbox Code Playgroud)
运行时conda build,出现以下异常:
ModuleNotFoundError: No module named 'poetry'
Run Code Online (Sandbox Code Playgroud)
紧接在这些行之后:
[...]
Processing $SRC_DIR
Preparing wheel …Run Code Online (Sandbox Code Playgroud) 我正在尝试在诗歌虚拟环境中使用 Jupyter Notebooks,但是ModuleNotFoundError在尝试导入已经由诗歌安装(和管理)的 python 包时出现问题。
我正在运行 python v3.8.5、poetry v1.1.13 和 PyCharm 2022.1.1。
我已经添加了jupyter和ipykernel作为依赖项,并且可以确认它们已添加到两者中pyproject.toml:
jupyter = "^1.0.0"
ipykernel = "^6.13.0"
Run Code Online (Sandbox Code Playgroud)
和poetry.lock:
[[package]]
name = "ipykernel"
version = "6.13.0"
description = "IPython Kernel for Jupyter"
category = "dev"
optional = false
python-versions = ">=3.7"
[[package]]
name = "jupyter"
version = "1.0.0"
description = "Jupyter metapackage. Install all the Jupyter components in one go."
category = "dev"
optional = false
python-versions = "*" …Run Code Online (Sandbox Code Playgroud) 我正在尝试为我的诗歌环境安装 Jupyter 内核,但似乎该内核获取了我的基本 conda 环境。这就是我正在尝试的:
poetry env list
>ENV_NAME-HASH-py3.9 (Activated)
poetry run which python
>/Users/myusername/Library/Caches/pypoetry/virtualenvs/ENV_NAME-HASH-py3.9/bin/python
poetry run ipython kernel install --name=ENV_NAME
>Installed kernelspec ENV_NAME in /Users/myusername/Library/Jupyter/kernels/ENV_NAME
Run Code Online (Sandbox Code Playgroud)
然后,如果我打开带有此内核的 Jupyter,我不会获得应安装的库。检查我得到的Python版本:
!which python
/Users/myusername/opt/anaconda3/bin/python
Run Code Online (Sandbox Code Playgroud)
任何帮助表示赞赏!
我在这里使用 Python 3.10.4,并在使用 pyproject.toml 的 Poetry 1.1.13 项目中使用 .pre-commit-config.yaml 文件
这是我的 .pre-commit-config.yaml 的样子
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
# /sf/ask/4545491891/
default_language_version:
python: python3.10
default_stages: [commit, push]
repos:
- repo: local
hooks:
# https://github.com/pre-commit/pre-commit-hooks#check-ast
- id: check-ast
description: Simply checks whether the files parse as valid python.
entry: check-ast
name: Check python syntax
language: system
types: [python]
# https://github.com/pre-commit/pre-commit-hooks#check-added-large-files
- id: check-added-large-files
description: prevents giant files from being committed.
entry: check-added-large-files
name: Check added …Run Code Online (Sandbox Code Playgroud) 我正在尝试将其发布到 TestPypi 的 python 库中。到目前为止,发布我的诗歌作品还没有出现任何问题。
对于上下文,作为初学者,我来自这些网站:
出现的唯一问题是,使用 pip install 安装软件包时,未考虑 pyproject.toml 中列出的依赖项。
我尝试过更新setuptools,pip但没有成功。
我的目标是进行干净的依赖安装,而不会出现版本控制错误。
这是我尝试过的主要解决方案。
我隐藏了我的真实姓名。
[tool.poetry]
name = "package-name"
version = "0.1.0"
description = "<desc>"
authors = ["<myname> <myemail>"]
license = "MIT"
[tool.poetry.dependencies]
python = "^3.10"
beautifulsoup4 = {version = "4.11.1", allow-prereleases = true}
recurring-ical-events = {version = "1.0.2b0", allow-prereleases = true}
requests = {version = "2.28.0", allow-prereleases = true}
rich = {version = "12.4.4", allow-prereleases = …Run Code Online (Sandbox Code Playgroud) poetry install自从我从 Python 3.8 迁移到 Python 3.10 以来,我在任何 GitHub 运行器上的 CI/CD 管道(Github Actions)中使用时都遇到问题。
Installing dependencies from lock file\n\nPackage operations: 79 installs, 0 updates, 0 removals\n \xe2\x80\xa2 Installing pyparsing (3.0.9)\n \nJSONDecodeError\n \nExpecting value: line 1 column 1 (char 0)\n at /opt/hostedtoolcache/Python/3.10.0/x64/lib/python3.10/json/decoder.py:355 in raw_decode\n 351\xe2\x94\x82 """\n 352\xe2\x94\x82 try:\n 353\xe2\x94\x82 obj, end = self.scan_once(s, idx)\n 354\xe2\x94\x82 except StopIteration as err:\n \xe2\x86\x92 355\xe2\x94\x82 raise JSONDecodeError("Expecting value", s, err.value) from None\n 356\xe2\x94\x82 return obj, end\n 357\xe2\x94\x82 \nError: Process completed with exit …Run Code Online (Sandbox Code Playgroud) 我想删除一个环境(请参阅此问题)
\n当我发出
\n/progetti/project_blah$ poetry env remove ./.venv\nRun Code Online (Sandbox Code Playgroud)\n我明白了
\n/bin/sh: 1: ./.venv: Permission denied\n\n EnvCommandError\n\n Command ./.venv -c "import sys; print(\'.\'.join([str(s) for s in sys.version_info[:3]]))" errored with the following return code 126, and output: \n \n\n at ~/.local/share/pypoetry/venv/lib/python3.9/site-packages/poetry/utils/env.py:625 in remove\n 621\xe2\x94\x82 shell=True,\n 622\xe2\x94\x82 )\n 623\xe2\x94\x82 )\n 624\xe2\x94\x82 except CalledProcessError as e:\n \xe2\x86\x92 625\xe2\x94\x82 raise EnvCommandError(e)\n 626\xe2\x94\x82 \n 627\xe2\x94\x82 python_version = Version.parse(python_version.strip())\n 628\xe2\x94\x82 minor = "{}.{}".format(python_version.major, python_version.minor)\n 629\xe2\x94\x82 \nRun Code Online (Sandbox Code Playgroud)\n这是什么 ?
\n我正在尝试使用该命令更新具有另一个依赖项的现有项目poetry add,但是当我这样做时,它会删除块中的所有数据[metadata.files]。
我已经浏览了文档,但无法找到将此信息保留/添加回poetry.lock文件中的方法。
任何帮助,将不胜感激!
默认情况下,poetry 在项目 root 之外创建虚拟环境。例如,在 mac 上,它在~/Library/Caches/pypoetry.
但是,我发现了以下建议:
# Configure poetry to create virtual environments inside the project's root directory
poetry config virtualenvs.in-project true
Run Code Online (Sandbox Code Playgroud)
另外,诗歌文档本身指出了这两个选项:
默认情况下,poetry 在 {cache-dir}/virtualenvs(Windows 上为 {cache-dir}\virtualenvs)中创建一个虚拟环境。您可以通过编辑诗歌配置来更改缓存目录值。此外,您可以使用 virtualenvs.in-project 配置变量在项目目录中创建虚拟环境。
在项目目录内或外部创建项目虚拟环境有什么好处?
使用Artifactory(https://cloud.google.com/artifact-registry)我打算添加对诗歌的依赖(https://python-poetry.org/docs/repositories/)。
我可以使用命令安装:(pip install --index-url https://us-central1-python.pkg.dev/<PROJECT_ID>/<SOME_LIB_REPO>/simple/ <PACKAGE_NAME>使用 keyrings.google-artifactregistry-auth 进行身份验证)
我打算使用 POETRY 来管理我的依赖项。我不知道使用诗歌是否会增加这种依赖性。poetry add --source <PACKAGE_NAME> https://us-central1-python.pkg.dev/<PROJECT_ID>/<SOME_LIB_REPO>我收到此错误:
poetry update
Updating dependencies
Resolving dependencies... (0.9s)
RepositoryError
401 Client Error: Unauthorized for url: https://us-central1-python.pkg.dev/<PROJECT_ID>/<SOME_LIB_REPO>/simple/pytest/
Run Code Online (Sandbox Code Playgroud)
我的 pyproject.toml
...
[[tool.poetry.source]]
name = "SOME_LIB"
url = " https://us-central1-python.pkg.dev/<PROJECT_ID>/<SOME_LIB_REPO>/simple/"
secondary = true
Run Code Online (Sandbox Code Playgroud)
这里有如何使用 PIP/VIRTUALENV 进行配置的详细信息:https://cloud.google.com/artifact-registry/docs/python/authentication但没有有关 Poetry 的详细信息。
您对此有什么建议吗?
python python-packaging python-poetry google-artifact-registry
python-poetry ×10
python ×6
conda-build ×1
conda-forge ×1
dependencies ×1
ipython ×1
jupyter ×1
pip ×1
pre-commit ×1
pypi ×1
python-3.10 ×1
python-3.x ×1
python-venv ×1
virtualenv ×1