1

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.

JJMcGee
  • 19
  • 1
  • 8

3 Answers3

6

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
Imran
  • 12,950
  • 8
  • 64
  • 79
2

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

holdenweb
  • 33,305
  • 7
  • 57
  • 77
1

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.

rmharrison
  • 4,730
  • 2
  • 20
  • 35
  • For additional discussion of python imports, see: https://stackoverflow.com/questions/710551/import-module-or-from-module-import – rmharrison Oct 31 '16 at 05:42
  • Thank you for your answer. However, I still receive the same error when inputting what you suggested. Under the anaconda site-packages, the directory is just deuces and inside is card.py, deck.py, evaluator.py and __init__.py. – JJMcGee Oct 31 '16 at 05:47
  • Odd (I don't use Anaconda). It'd then just be `from deuces.card import Card ` (`module.card` instead of `module.submodule.card`). – rmharrison Oct 31 '16 at 06:07
  • Do I have to change it in the init file, since thats where the error seems to be originating? Right now in that file it has : "from card import Card from deck import Deck from evaluator import Evaluator" – JJMcGee Oct 31 '16 at 06:46
  • No. That `__init__.py` file is using a relative import from within a module. – rmharrison Oct 31 '16 at 06:52
  • `>>> import deuces; help(deuces)` will show you what's at that level under 'PACKAGE CONTENTS.' You can use this to navigate, e.g. `help(deuces.deuces)` would show you the next level. – rmharrison Oct 31 '16 at 06:55
  • Is there maybe a different way I should try installing it, because no matter what I do, if it has 'deuces' in the command it gives me an error. – JJMcGee Oct 31 '16 at 17:56
  • The package author has already made it available via `pip`, so from the command-line simply `pip install deuces`. If you're on WIndows, note that git-bash comes with a command-line. – rmharrison Oct 31 '16 at 17:59
  • Also, to see the import command from the post working, simply git clone the repo. From the parent directory of the deuces folder (which was created by the clone), open python and run the import commands. – rmharrison Oct 31 '16 at 18:01
  • Could the issue be that the module is written in 2.7 and I'm using 3.5? I assumed that I'd have to change the files, but I didn't think there was an importing difference. – JJMcGee Nov 01 '16 at 14:14
  • Good instincts; however, this package seems fine on both (I can `import deuces` with both 2.7 and 3.5). – rmharrison Nov 02 '16 at 07:55
  • I got it working on 2.7 but not on 3.5. Ill try reinstalling the module again and do the same thing I did for 2.7 and hopefully that'll do it. Thank you for your help. – JJMcGee Nov 02 '16 at 17:48
  • @JJMcGee What'd you do to get it working? Useful for posterity. – rmharrison Nov 03 '16 at 01:45