标签: python-poetry

诗:更改项目根文件夹名称时如何继续使用旧的虚拟环境?

我在一些 python 项目中使用 Poetry。在某个阶段我想重命名项目的根文件夹并不罕见。当我这样做并运行poetry shell诗歌时,会创建一个新的虚拟环境。但我不需要新的虚拟环境,我只想继续使用现有的虚拟环境。我知道我可以通过运行手动激活旧环境source {path to the old venv}/bin/activate,但随后我必须单独跟踪旧环境名称并避免使用poetry shell.

我能做点什么吗?再次开始安装依赖项、将 IDE 指向新环境并删除旧的虚拟环境是相当耗时的,只是因为您更改了根文件夹名称 - 这种情况可能会发生多次。这个问题表明该问题没有解决方案,但想确认这一点,因为对我来说这似乎是相当烦人的问题。

python python-poetry

7
推荐指数
1
解决办法
1万
查看次数

在 macOS 11.6/Xcode 13 上诗歌安装失败:dyld:未加载库:@executable_path/../Python3

使用官方安装程序在 macOS 11.6/Xcode 13 上安装新诗失败:

u@s-MacBook-Pro ~ % curl -sSL https://install.python-poetry.org | python3 -
Retrieving Poetry metadata

# Welcome to Poetry!

This will download and install the latest version of Poetry,
a dependency and package manager for Python.

It will add the `poetry` command to Poetry's bin directory, located at:

/Users/u/Library/Python/3.8/bin

You can uninstall at any time by executing this script with the --uninstall option,
and these changes will be reverted.

Installing Poetry (1.1.12): An error occurred. Removing partial environment. …
Run Code Online (Sandbox Code Playgroud)

python macos python-poetry

7
推荐指数
1
解决办法
3516
查看次数

如何通过 Poetry 安装最新的 PyTorch 预览版(每晚)

最新的预览版支持在 M1 MacBook Pro 上进行加速训练。目前仅最新预览版(每晚)版本支持此功能:

\n
\n

首先,只需在运行 macOS 12.3 或更高版本以及原生 Python 版本 (arm64) 的 Apple Silicon Mac 上安装最新的预览版(每晚)版本即可。

\n
\n

根据文档,这是通过以下方式安装最新预览版本的方法pip

\n
pip3 install --pre torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/nightly/cpu\n
Run Code Online (Sandbox Code Playgroud)\n

但我正在使用Poetry来管理我的 Python 项目依赖项。

\n

诗歌似乎不支持该--pre选项:

\n
$ poetry add --pre torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/nightly/cpu \n\n  Stack trace:\n\n  11  ~/.poetry/lib/poetry/_vendor/py3.9/clikit/console_application.py:123 in run\n      io = io_factory(\n\n  10  ~/.poetry/lib/poetry/console/config/application_config.py:221 in create_io\n      resolved_command = application.resolve_command(args)\n\n   9  ~/.poetry/lib/poetry/_vendor/py3.9/clikit/console_application.py:110 in resolve_command\n      return self._config.command_resolver.resolve(args, …
Run Code Online (Sandbox Code Playgroud)

python pip package-management pytorch python-poetry

7
推荐指数
1
解决办法
5737
查看次数

在 docker 容器中将 github repo 导入为诗歌中的依赖项

问题:\n我正在尝试使用 ssh 密钥作为 tool.poetry.dev.dependency 在我的 pyproject.toml 中添加 bitbucket 存储库,并通过 docker compose 将其安装在 docker 容器中。但是,我在构建容器时遇到以下错误(请参阅错误)。

\n

在 Docker 容器中安装诗歌期间,有什么我可能会忽略的事情和/或建议能够将 bitbucket 存储库作为依赖项拉出吗?

\n

我做了什么:

\n
    \n
  • 我知道 bitbucket 依赖性是问题所在,因为当我将其交换到 whl 文件的本地路径时,容器会正确构建。
  • \n
  • 我可以在本地安装依赖项
  • \n
  • 我可以在 docker 容器中克隆不同的存储库
  • \n
\n
\n

参考

\n

错误:\nHangupException

\n

远程服务器意外关闭了连接。

\n

在 /usr/local/lib/python3.10/site-packages/dulwich/protocol.py:220 中 read_pkt_line

\n
   216\xe2\x94\x82 \n   217\xe2\x94\x82         try:\n   218\xe2\x94\x82             sizestr = read(4)\n   219\xe2\x94\x82             if not sizestr:\n \xe2\x86\x92 220\xe2\x94\x82                 raise HangupException()\n   221\xe2\x94\x82             size = int(sizestr, 16)\n   222\xe2\x94\x82             if size == 0:\n   223\xe2\x94\x82                 if self.report_activity:\n   224\xe2\x94\x82                     self.report_activity(4, …
Run Code Online (Sandbox Code Playgroud)

bitbucket docker docker-compose python-poetry

7
推荐指数
1
解决办法
1294
查看次数

使用Poetry导出requirements.txt时如何省略依赖

我有一个 Python3 Poetry 项目,其中有一个pyproject.toml指定依赖项的文件:

[tool.poetry.dependencies]
python = "^3.10"
nltk = "^3.7"
numpy = "^1.23.4"
scipy = "^1.9.3"
scikit-learn = "^1.1.3"
joblib = "^1.2.0"

[tool.poetry.dev-dependencies]
pytest = "^5.2"
Run Code Online (Sandbox Code Playgroud)

requirements.txt使用命令将这些依赖项导出到文件中poetry export --without-hashes -f requirements.txt --output requirements.txt,生成以下文件requirements.txt

click==8.1.3 ; python_version >= "3.10" and python_version < "4.0"
colorama==0.4.6 ; python_version >= "3.10" and python_version < "4.0" and platform_system == "Windows"
joblib==1.2.0 ; python_version >= "3.10" and python_version < "4.0"
nltk==3.8.1 ; python_version >= "3.10" and python_version …
Run Code Online (Sandbox Code Playgroud)

python pip requirements.txt python-poetry

7
推荐指数
1
解决办法
6513
查看次数

使用诗歌解决 boto3 和 s3fs 上的依赖关系失败

我可以使用以下命令安装 boto3、s3fs 和 pandas:

pip install boto3 pandas s3fs
Run Code Online (Sandbox Code Playgroud)

但诗歌却失败了:

poetry add boto3 pandas s3fs
Run Code Online (Sandbox Code Playgroud)

这是错误:

Because no versions of s3fs match >2023.3.0,<2024.0.0
 and s3fs (2023.3.0) depends on aiobotocore (>=2.4.2,<2.5.0), s3fs (>=2023.3.0,<2024.0.0) requires aiobotocore (>=2.4.2,<2.5.0).
And because no versions of aiobotocore match >2.4.2,<2.5.0
 and aiobotocore (2.4.2) depends on botocore (>=1.27.59,<1.27.60), s3fs (>=2023.3.0,<2024.0.0) requires botocore (>=1.27.59,<1.27.60).
And because boto3 (1.26.91) depends on botocore (>=1.29.91,<1.30.0)
 and no versions of boto3 match >1.26.91,<2.0.0, s3fs (>=2023.3.0,<2024.0.0) is incompatible with boto3 (>=1.26.91,<2.0.0).
So, because engexploit-k8s-pod-operator-images …
Run Code Online (Sandbox Code Playgroud)

boto3 python-poetry python-s3fs

7
推荐指数
1
解决办法
3210
查看次数

警告:“news”是 pyproject.toml 中定义的入口点,但它没有作为脚本安装。你可能会得到不正确的 `sys.argv[0]`

    \n
  • 我正在尝试使用 docker compose 在 docker 中运行我的基于诗歌的 python 项目
  • \n
  • 当我运行该应用程序时,它可以工作,但它给了我这个警告
  • \n
\n
ch_news_dev_python          | Warning: 'news' is an entry point defined in pyproject.toml, but it's not installed as a script. You may get improper `sys.argv[0]`.\nch_news_dev_python          | \nch_news_dev_python          | The support to run uninstalled scripts will be removed in a future release.\nch_news_dev_python          | \nch_news_dev_python          | Run `poetry install` to resolve and get rid of this message.\n
Run Code Online (Sandbox Code Playgroud)\n

我的项目结构

\n
news\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 docker\n\xe2\x94\x82   \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 development\n\xe2\x94\x82   \xe2\x94\x82   \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 ...\n\xe2\x94\x82   \xe2\x94\x82   \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 python_server\n\xe2\x94\x82   \xe2\x94\x82 …
Run Code Online (Sandbox Code Playgroud)

python docker dockerfile python-packaging python-poetry

7
推荐指数
1
解决办法
4182
查看次数

Poetry Shell:如何缩短 bash 前缀

当激活诗歌 python shell 时,我在 bash 提示符中收到一个非常长的字符串:

(my-current-folder-pNzYm0GW-py3.8) (base) myusername@mycomputername>
Run Code Online (Sandbox Code Playgroud)

我希望它更短,也许像这样:

(py3.8) myusername@mycomputername>
Run Code Online (Sandbox Code Playgroud)

有谁知道这是怎么做到的吗?

(我猜这base来自于系统上也安装了 miniconda,我可以通过编辑我的 来修复它.bashrc

python pyenv python-poetry

6
推荐指数
1
解决办法
1221
查看次数

我可以手动解决诗歌中的依赖冲突(SolverProblemError)吗?

我决定使用poetry,一切都很顺利,根据需要添加了现有项目模块的依赖项。\n当我尝试添加 googlesearch-python 包时,我收到了以下 SolverProblemError:

\n
\n
(.env) C:\\Users\\marti\\OneDrive\\Documents\\Master_s_thesis\\Code\\Mastersthesis>poetry add googlesearch-python\nUsing version ^2020.0.2 for googlesearch-python\n\nUpdating dependencies\nResolving dependencies...\n\n  SolverProblemError\n\n  Because googlesearch-python (2020.0.2) depends on beautifulsoup4 (4.9.1) which depends on soupsieve (<2.0), googlesearch-python (2020.0.2) requires soupsieve (<2.0).\n  And because googlesearch-python (2020.0.2) depends on soupsieve (2.0.1), googlesearch-python is forbidden.\n  So, because no versions of googlesearch-python match >2020.0.2,<2021.0.0\n   and mastersthesis depends on googlesearch-python (^2020.0.2), version solving failed.\n\n  at ~\\.poetry\\lib\\poetry\\puzzle\\solver.py:241 in _solve\n      237\xe2\x94\x82             packages = result.packages\n      238\xe2\x94\x82         except OverrideNeeded as e:\n      239\xe2\x94\x82             return self.solve_in_compatibility_mode(e.overrides, …
Run Code Online (Sandbox Code Playgroud)

python dependencies python-poetry

6
推荐指数
0
解决办法
1863
查看次数

是否可以从 python 中的 black 命令运行 isort formatter

我喜欢从精心设计的 Python 项目中获取灵感。

最后一个给我启发的是诗歌库

我从中复制了很多,但这篇文章的主题是blackisort

两者都配置良好pyproject.toml

[tool.isort]
profile = "black"
...
known_first_party = "poetry"


[tool.black]
line-length = 88
include = '\.pyi?$'
exclude = '''
/(
...
)/
'''
Run Code Online (Sandbox Code Playgroud)

格式设置如下Makefile

format: clean
    @poetry run black poetry/ tests/
Run Code Online (Sandbox Code Playgroud)

我认为运行make format会运行black,它将在内部运行isort,但是当我运行时isort .,它随后正确地格式化了导入语句。然后好像black没跑isort

问:内部运行吗?blackisort

python isort python-black python-poetry

6
推荐指数
1
解决办法
8307
查看次数