Python 安装特定版本的包时出现问题 "chess is not a package"

Python problem installing package for specific version "chess is not a package"

所以,我正在尝试在我的服务器中使用 PUTTY 安装国际象棋 python 包。 服务器有 python 2.6 和 python 3.4。 国际象棋包只适用于 3.4.

所以我要安装它 运行:

python3 -m pip install python-chess

回复:

Requirement already satisfied: python-chess in /home/egqbe6ns/.local/lib/python3.4/site-packages (0.27.3)

脚本Chess.py:

import chess
import chess.engine

fen = 'r2qkb1r/1p1bpp1p/p1n2p2/8/B1pP4/5N2/P1P2PPP/RN1QK2R w KQkq - 0 12'
board = chess.Board(fen)
handler = chess.uci.InfoHandler()

当我 运行 脚本 python3 chess.py 2>&1:

Traceback (most recent call last):
  File "<frozen importlib._bootstrap>", line 2218, in _find_and_load_unlocked
AttributeError: 'module' object has no attribute '__path__'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "chess.py", line 1, in <module>
    import chess
  File "/home/egqbe6ns/public_html/chess.py", line 2, in <module>
    import chess.engine
ImportError: No module named 'chess.engine'; 'chess' is not a package

扩展信息:

pip --version
pip 19.1.1 from /home/egqbe6ns/.local/lib/python3.4/site-packages/pip (python 3.4)

python3 --version
Python 3.4.3

您似乎已将脚本命名为 chess.py。默认情况下,将在其中搜索模块的标准目录 (sys.path) 包括当前目录,import chess 将您的脚本作为模块加载。显然,它不包含子模块 engine

只需将脚本重命名为其他名称,删除文件 chess.pyc(如果存在)然后重试