诗歌 虚拟环境已经激活

Har*_*oli 9 python python-poetry

运行以下

poetry shell
Run Code Online (Sandbox Code Playgroud)

返回以下错误

/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
Run Code Online (Sandbox Code Playgroud)

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

Har*_*oli 7

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

source "$( poetry env list --full-path )/bin/activate"
Run Code Online (Sandbox Code Playgroud)

  • 这根本不起作用,请参阅 Mr.bjerre 的回答以获得更可靠的东西 (3认同)

小智 7

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

我们可以通过以下方式找到路径poetry env info --path

source $(poetry env info --path)/bin/activate
Run Code Online (Sandbox Code Playgroud)

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


mr.*_*rre 6

我必须执行以下操作

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

  • 您可以在您的个人资料中将其设置为别名 - `alias activate_poetry="source \"\$(poetry env list --full-path | grep Activated | cut -d' ' -f1 )/bin/activate\"" `。运行此命令时,请确保您位于项目目录(包含 pyproject.toml 的目录)中。 (2认同)