如何让 python-chess SVG 渲染在 Google Colab 中工作?
How do I get python-chess SVG rendering working in Google Colab?
我正试图从 python-chess SVG rendering 中获取此代码示例。
import chess
import chess.svg
chess.svg.piece(chess.Piece.from_symbol("R"))
当我 运行 代码时,我得到以下 HTML 输出,但不是白车的图像。
<svg version="1.1" viewBox="0 0 45 45" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><g class="white rook" fill="#fff" fill-rule="evenodd" id="white-rook" stroke="#000" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5"><path d="M9 39h27v-3H9v3zM12 36v-4h21v4H12zM11 14V9h4v2h5V9h5v2h5V9h4v5" stroke-linecap="butt" /><path d="M34 14l-3 3H14l-3-3" /><path d="M31 17v12.5H14V17" stroke-linecap="butt" stroke-linejoin="miter" /><path d="M31 29.5l1.5 2.5h-20l1.5-2.5" /><path d="M11 14h23" fill="none" stroke-linejoin="miter" /></g></svg>
这解决了我的问题:
import chess
import chess.svg
import IPython
html_code = chess.svg.piece(chess.Piece.from_symbol("R"))
display(IPython.display.HTML(html_code))
现在白车显示在 Colab 中。
我正试图从 python-chess SVG rendering 中获取此代码示例。
import chess
import chess.svg
chess.svg.piece(chess.Piece.from_symbol("R"))
当我 运行 代码时,我得到以下 HTML 输出,但不是白车的图像。
<svg version="1.1" viewBox="0 0 45 45" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><g class="white rook" fill="#fff" fill-rule="evenodd" id="white-rook" stroke="#000" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5"><path d="M9 39h27v-3H9v3zM12 36v-4h21v4H12zM11 14V9h4v2h5V9h5v2h5V9h4v5" stroke-linecap="butt" /><path d="M34 14l-3 3H14l-3-3" /><path d="M31 17v12.5H14V17" stroke-linecap="butt" stroke-linejoin="miter" /><path d="M31 29.5l1.5 2.5h-20l1.5-2.5" /><path d="M11 14h23" fill="none" stroke-linejoin="miter" /></g></svg>
这解决了我的问题:
import chess
import chess.svg
import IPython
html_code = chess.svg.piece(chess.Piece.from_symbol("R"))
display(IPython.display.HTML(html_code))
现在白车显示在 Colab 中。