如何使用 python诗以独立的方式将包安装到 virtualenv ?
我最近迁移到诗歌
我的依赖关系管理,因此如果我的问题不在诗歌
的范围之内,请原谅。
最终目标
我的最终目标是创建一个 rpm软件包,其中包含A virtualenv及其软件及其所有依赖项。然后,此RPM将在安装的系统中以隔离>提供我的软件。
在我的诗歌> virtualenv
中使用诗歌安装
时,重现
我面临的问题。一旦删除了我的软件的源目录,我的 cli 就拒绝工作。
重现
我已经创建了一个简单的存储库来重现问题: https://github.com/riton/ python poetry-venv
这是我使用诗歌
:
#!/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
# without the source dir
cd $ALT_SRC_DIR
[...]
python3.8 -m venv "$VENV_DIR"
source $VENV_DIR/bin/activate
[...]
poetry install --no-dev -v
[...]
# Our software will be called without an activated virtualenv
# so 'deactivate' the current one
deactivate
cd /
echo "Try after install"
# Start the "CLI" after installation
$VENV_DIR/bin/python-poetry-venv
echo "Removing source directory and trying again"
rm -rf $ALT_SRC_DIR
$VENV_DIR/bin/python-poetry-venv
echo "Removing user cache dir and trying again"
rm -rf $USER_CACHE_DIR
$VENV_DIR/bin/python-poetry-venv
上面的脚本失败的错误:
[...]
Try after install
+ /venv/bin/python-poetry-venv
THIS IS THE MAIN
+ echo 'Removing source directory and trying again'
Removing source directory and trying again
+ rm -rf /src2
+ /venv/bin/python-poetry-venv
Traceback (most recent call last):
File "/venv/bin/python-poetry-venv", line 2, in <module>
from python_poetry_venv.cli import main
ModuleNotFoundError: No module named 'python_poetry_venv'
make: *** [Makefile:2: test-with-poetry-install] Error 1
, source Directory 被删除。 CLI拒绝工作。
尝试使用pip安装
我尝试用诗歌构建&amp;&amp;&amp;&amp; pip install dist/*。whl
(链接到此脚本版本),
使用pip install
的版本.whl
文件,我成功地创建了独立部署我的应用程序。这适用于RPM包装,可以在任何地方部署。
软件版本的
+ python3.8 -V
Python 3.8.13
+ poetry --version
Poetry version 1.1.13
最终想法
我不禁认为我在这里滥用诗歌
。因此,任何帮助将不胜感激。
提前
感谢
I've recently migrated to poetry
for my dependencies management so pardon if my question is out of the scope of poetry
here.
Final goal
My final goal is to create a RPM package that contains a virtualenv with my software installed along with all its dependencies. This RPM would then provide my software in isolation with the system where it is installed.
Reproduce the problem
I'm facing a problem while using poetry install
in my virtualenv
. As soon as the source directory of my software is deleted, my CLI refuses to work any longer.
Reproduce
I've created a simple repository to reproduce the problem: https://github.com/riton/python-poetry-venv
Here are the that I'm using with 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
# without the source dir
cd $ALT_SRC_DIR
[...]
python3.8 -m venv "$VENV_DIR"
source $VENV_DIR/bin/activate
[...]
poetry install --no-dev -v
[...]
# Our software will be called without an activated virtualenv
# so 'deactivate' the current one
deactivate
cd /
echo "Try after install"
# Start the "CLI" after installation
$VENV_DIR/bin/python-poetry-venv
echo "Removing source directory and trying again"
rm -rf $ALT_SRC_DIR
$VENV_DIR/bin/python-poetry-venv
echo "Removing user cache dir and trying again"
rm -rf $USER_CACHE_DIR
$VENV_DIR/bin/python-poetry-venv
The script above fails with the following error:
[...]
Try after install
+ /venv/bin/python-poetry-venv
THIS IS THE MAIN
+ echo 'Removing source directory and trying again'
Removing source directory and trying again
+ rm -rf /src2
+ /venv/bin/python-poetry-venv
Traceback (most recent call last):
File "/venv/bin/python-poetry-venv", line 2, in <module>
from python_poetry_venv.cli import main
ModuleNotFoundError: No module named 'python_poetry_venv'
make: *** [Makefile:2: test-with-poetry-install] Error 1
link to the full script source
As soon as the source directory is removed. The CLI refuses to work any longer.
Trying with pip install
I've tried to replace the poetry install
with something like poetry build && pip install dist/*.whl
(link to this script version)
With the version using pip install
of the .whl
file, I'm successfully creating a standalone deployment of my application. This is suitable to RPM packaging and could be deployed anywhere.
Software versions
+ python3.8 -V
Python 3.8.13
+ poetry --version
Poetry version 1.1.13
Final thoughts
I can't help but think that I'm misusing poetry
here. So any help will be very much appreciated.
Thanks in advance
Regards
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我参加聚会迟到了,但我想提出一种实现这一目标的方法。
诗歌
在管理项目的主要和开发依赖项并锁定其版本方面令人惊讶,但在部署您的情况时,我不会依靠它。这是一种解决它的方法:您拥有它,您需要的一切都将在
venv
文件夹中独立。I'm late to the party, but I want to suggest a way to accomplish this.
While
poetry
is amazing at managing your project's main and dev dependencies and locking their versions, I wouldn't rely on it while deploying on your situation. Here's a way to solve it:There you have it, everything you need will be self-contained in the
venv
folder.