因此,我尝试在我的服务器中使用PUTTY来安装国际象棋python包。服务器端有python2.6和python3.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)
Script 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
发布于 2019-07-20 21:38:43
看起来你已经将你的脚本命名为chess.py
。由于默认情况下,搜索模块的标准目录(sys.path
)包括当前目录,因此import chess
会将脚本作为模块加载。显然,它没有包含子模块engine
只需将脚本重命名为其他名称,删除文件chess.pyc
(如果存在),然后重试
https://stackoverflow.com/questions/57125243
复制相似问题