我在一些 python 项目中使用 Poetry。在某个阶段我想重命名项目的根文件夹并不罕见。当我这样做并运行poetry shell诗歌时,会创建一个新的虚拟环境。但我不需要新的虚拟环境,我只想继续使用现有的虚拟环境。我知道我可以通过运行手动激活旧环境source {path to the old venv}/bin/activate,但随后我必须单独跟踪旧环境名称并避免使用poetry shell.
我能做点什么吗?再次开始安装依赖项、将 IDE 指向新环境并删除旧的虚拟环境是相当耗时的,只是因为您更改了根文件夹名称 - 这种情况可能会发生多次。这个问题表明该问题没有解决方案,但想确认这一点,因为对我来说这似乎是相当烦人的问题。
使用官方安装程序在 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) 最新的预览版支持在 M1 MacBook Pro 上进行加速训练。目前仅最新预览版(每晚)版本支持此功能:
\n\n\n首先,只需在运行 macOS 12.3 或更高版本以及原生 Python 版本 (arm64) 的 Apple Silicon Mac 上安装最新的预览版(每晚)版本即可。
\n
根据文档,这是通过以下方式安装最新预览版本的方法pip:
pip3 install --pre torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/nightly/cpu\nRun Code Online (Sandbox Code Playgroud)\n但我正在使用Poetry来管理我的 Python 项目依赖项。
\n诗歌似乎不支持该--pre选项:
$ 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) 问题:\n我正在尝试使用 ssh 密钥作为 tool.poetry.dev.dependency 在我的 pyproject.toml 中添加 bitbucket 存储库,并通过 docker compose 将其安装在 docker 容器中。但是,我在构建容器时遇到以下错误(请参阅错误)。
\n在 Docker 容器中安装诗歌期间,有什么我可能会忽略的事情和/或建议能够将 bitbucket 存储库作为依赖项拉出吗?
\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) 我有一个 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) 我可以使用以下命令安装 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) 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.\nRun Code Online (Sandbox Code Playgroud)\n我的项目结构
\nnews\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 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)
我决定使用poetry,一切都很顺利,根据需要添加了现有项目模块的依赖项。\n当我尝试添加 googlesearch-python 包时,我收到了以下 SolverProblemError:
\nRun Code Online (Sandbox Code Playgroud)(.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, …
我喜欢从精心设计的 Python 项目中获取灵感。
最后一个给我启发的是诗歌库。
我从中复制了很多,但这篇文章的主题是black和isort。
两者都配置良好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-poetry ×10
python ×8
docker ×2
pip ×2
bitbucket ×1
boto3 ×1
dependencies ×1
dockerfile ×1
isort ×1
macos ×1
pyenv ×1
python-black ×1
python-s3fs ×1
pytorch ×1