poetry 虚拟环境已经激活

poetry Virtual environment already activated

运行以下

poetry shell

returns下面的错误

/home/harshagoli/.poetry/lib/poetry/_vendor/py2.7/subprocess32.py:149: RuntimeWarning: The _posixsubprocess module is not being used. Child process reliability may suffer if your program uses threads.                                                                                                                                                                                    
  "program uses threads.", RuntimeWarning)                                                                                                                                                    
The currently activated Python version 2.7.17 is not supported by the project (^3.7).                                                                                                         
Trying to find and use a compatible version.                                                                                                                                                  
Using python3 (3.7.5)                                                                                                                                                                         
Virtual environment already activated: /home/harshagoli/.cache/pypoetry/virtualenvs/my-project-0wt3KWFj-py3.7

我怎样才能克服这个错误?为什么这个命令不起作用?

poetry shell 是一个非常有问题的命令,这在维护者中经常被谈论。此特定问题的解决方法是手动激活 shell。可能值得为以下别名

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

所以您需要将其粘贴到您的 .bash_aliases.bashrc

alias acpoet="source $(poetry env info --path)/bin/activate"

现在您可以运行 acpoet 激活您的诗歌环境(不要忘记获取您的文件以启用该命令)

我必须执行以下操作

source "$( poetry env list --full-path | grep Activated | cut -d' ' -f1 )/bin/activate"

这类似于激活一个普通的虚拟环境。但是我们需要找出诗歌虚拟环境的路径。

我们可以通过poetry env info --path

找到路径
source $(poetry env info --path)/bin/activate

this poetry demo中解释。

如果您使用传统的 pip 命令安装了 poetry,则 poetry 将仅限于为已安装的 python 版本创建虚拟环境。

尝试卸载 poetry 使用:

pip3 uninstall poetry

然后重新安装使用:

curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python

这对我有用。