Hiển thị các bài đăng có nhãn poetry. Hiển thị tất cả bài đăng
Hiển thị các bài đăng có nhãn poetry. Hiển thị tất cả bài đăng

Python: How can I correctly include a path dependency in pyproject.toml?

 python - How can I correctly include a path dependency in pyproject.toml? - Stack Overflow

Your folder structure looks a bit weird. It looks like your prefer the "src" variant. So I would suggest the following:

./
├── abc-lib
│   ├── pyproject.toml
│   └── src
│       └── abc_lib
│           ├── __init__.py
│           └── main.py
└── abc-web-api
    ├── pyproject.toml
    └── src
        └── abc_web_api
            ├── __init__.py
            └── main.py

With this pyproject.toml in abc-lib:

[tool.poetry]
name = "abc-lib"
version = "0.1.0"
description = ""
authors = ["Someone <someone@example.com>"]


[tool.poetry.dependencies]
python = "^3.6"

[tool.poetry.dev-dependencies]

[build-system]
requires = ["poetry>=1.0"]
build-backend = "poetry.masonry.api"

And this in abc-web-api:

[tool.poetry]
name = "abc-web-api"
version = "0.1.0"
description = ""
authors = ["Someone <someone@example.com>"]


[tool.poetry.dependencies]
python = "^3.6"
abc-lib = {path = "../abc-lib"}

[tool.poetry.dev-dependencies]

[build-system]
requires = ["poetry>=1.0"]
build-backend = "poetry.masonry.api"

poetry shell

 Basic usage | Documentation | Poetry - Python dependency management and packaging made easy (python-poetry.org)

Activating the virtual environment

The easiest way to activate the virtual environment is to create a new shell with poetry shell. To deactivate the virtual environment and exit this new shell type exit. To deactivate the virtual environment without leaving the shell use deactivate.

Why a new shell?

Child processes inherit their environment from their parents, but do not share them. As such, any modifications made by a child process, is not persisted after the child process exits. A Python application (Poetry), being a child process, cannot modify the environment of the shell that it has been called from such that an activated virtual environment remains active after the Poetry command has completed execution.

Therefore, Poetry has to create a sub-shell with the virtual envrionment activated in order for the subsequent commands to run from within the virtual environment.

Alternatively, to avoid creating a new shell, you can manually activate the virtual environment by running source {path_to_venv}/bin/activate (source {path_to_venv}\Scripts\activate.bat on Windows). To get the path to your virtual environment run poetry env info --path. You can also combine these into a nice one-liner, source $(poetry env info --path)/bin/activate To deactivate this virtual environment simply use deactivate.

POSIX SHELLWINDOWSEXIT/DEACTIVATE
New Shellpoetry shellpoetry shellexit
Manual Activationsource {path_to_venv}/bin/activatesource {path_to_venv}\Scripts\activate.batdeactivate
One-linersource`poetry env info --path`/bin/activatedeactivate

'poetry install' command fails; *.whl files are not found

 python - 'poetry install' command fails; *.whl files are not found - Stack Overflow


According to https://github.com/python-poetry/poetry/issues/4163, it seems to be an issue still pending to be resolved.

As a workaround, dumping dependencies to a requirements.txt file via poetry:

$ poetry export -f requirements.txt --output requirements.txt --without-hashes

and then installing them via pip, worked for me:

$ pip install -r requirements.txt
Specifically I found that deleting the AppData\Local\pypoetry\Cache\artifacts folder (I'm on Windows 10) worked for me. virtualenvs for other projects may be in AppData\Local\pypoetry\Cache\virtualenvs so you might not want to delete the root cache folder at AppData\Local\pypoetry\Cache in its entirety.

anti-pattern là gì

  Trong công nghệ và lập trình, Anti-pattern (mẫu phản diện) là những giải pháp bề ngoài có vẻ hiệu quả để giải quyết một vấn đề phổ biến, ...