诗歌虚拟环境已激活

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

运行以下命令

poetry shell

返回以下错误

/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

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

python python-poetry
5个回答
48
投票

我必须执行以下操作

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

42
投票

poetry shell
是一个非常有缺陷的命令,维护人员经常谈论这一点。此特定问题的解决方法是手动激活 shell。可能值得为以下内容添加别名

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

所以您需要将其粘贴到您的

.bash_aliases
.bashrc

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

现在您可以运行

acpoet
来激活您的诗歌环境(不要忘记获取文件的来源以启用该命令)


7
投票

与激活普通虚拟环境类似。但我们需要找出诗歌虚拟环境的路径。

我们可以通过

poetry env info --path

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

这个诗歌演示中进行了解释。


0
投票

只需终止现有终端,打开一个新终端,然后

poetry shell


-2
投票

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

尝试使用以下方式卸载诗歌:

pip3 uninstall poetry

然后使用以下命令重新安装:

brew install poetry
如果您有Mac。

这对我有用。

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