Import Error Python: No module named 'card'

2019-06-03 11:21发布

I've spent the majority of the day trying to troubleshoot this issue. So I'm trying to import the 'deuces' package from github. However, I keep getting an error:

!python

Python 3.5.2 |Anaconda 4.2.0 (64-bit)| (default, Jul 5 2016, 11:41:13) [MSC v.1900 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information.

>>> from deuces import Card

Traceback (most recent call last): File "", line 1, in File "C:\Program Files\Anaconda3\lib\site-packages\deuces\__init__.py", line 1, in from card import Card ImportError: No module named 'card'

I've been trying to use anaconda and did the pip install deuces. I don't know what I'm doing wrong-- I also tried uninstalling the regular Python and reinstalling anaconda.

The card file is in the same directory so I'm not sure why it can not find it.

3条回答
女痞
2楼-- · 2019-06-03 11:48

I have created a fork of deuces that supports Python 3.

$ pip install treys

And you can use it with the new name:

>>> from treys import Card
查看更多
戒情不戒烟
3楼-- · 2019-06-03 11:54

deuces hasn't been ported to Python 3 yet, I suspect.

查看更多
不美不萌又怎样
4楼-- · 2019-06-03 12:04

TL;DR

>>> from deuces.deuces.card import Card 

Explanation...

1) Import the module
You missed a level in the directory structure.

>>> import deuces.deuces.card as card

or

>>> from deuces.deuces import card

Levels...

>>> import deuces             # Module
>>> import deuces.deuces      # Sub-module
>>> import deuces.deuces.card # card.py

2) Use the class from the module

Now that you have the module (card, lowercase), if you want to access the class (Card), simply card.Card.

查看更多
登录 后发表回答