为什么我的环境中没有 python 包,即使“poetry add <package>”成功并且虚拟环境已激活?

问题描述 投票:0回答:1

使用

poetry
,我初始化了一个新项目,创建了一个新环境,并添加了一个包,但是该包没有与
pip3
一起显示 - 为什么不呢?

例如,当我运行以下命令时:

set -x
rm -fr /tmp/my-project
mkdir /tmp/my-project
cd /tmp/my-project
poetry init --no-interaction --python=3.7.13
pyenv local 3.7.13
poetry env use python
poetry env list  # confirm virtual env is activated
echo 'Note that the virtual env is "(Activated)" above.'
poetry add chardet
poetry show
pip3 list  # no chardet -- why not?
echo 'Why is chardet not present above?'

我得到以下输出:

+ rm -fr /tmp/my-project
+ mkdir /tmp/my-project
+ cd /tmp/my-project
+ poetry init --no-interaction --python=3.7.13
+ pyenv local 3.7.13
+ poetry env use python
Using virtualenv: /Users/robbednark/Library/Caches/pypoetry/virtualenvs/my-project-QXbwbAtx-py3.7
+ poetry env list
my-project-QXbwbAtx-py3.7 (Activated)
+ echo 'Note that the virtual env is "(Activated)" above.'
Note that the virtual env is "(Activated)" above.
+ poetry add chardet
Using version ^5.2.0 for chardet

Updating dependencies
Resolving dependencies... (0.1s)

No dependencies to install or update

Writing lock file
+ poetry show
chardet 5.2.0 Universal encoding detector for Python 3
+ pip3 list
Package    Version
---------- -------
pip        23.3.2
setuptools 47.1.0
+ echo 'Why is chardet not present above?'
Why is chardet not present above?
pip virtualenv python-poetry
1个回答
0
投票

需要使用

poetry shell
poetry run <cmd>
或获取 virtualenv 来激活虚拟环境,例如,

$ poetry shell
$ pip3 info chardet

或者这个:

$ poetry run -- pip3 info chardet

或者这个:

$ source "$(poetry env info --path)/bin/activate"
$ pip3 info chardet

我不知道为什么

poetry env list
在运行其中任何一个之前显示环境已激活。

© www.soinside.com 2019 - 2024. All rights reserved.