wroberts / pydaedalus

A Python wrapper of the Daedalus maze generator.
GNU General Public License v2.0
22 stars 5 forks source link

Windows necessary? #1

Open rebcabin opened 7 years ago

rebcabin commented 7 years ago

(apologies if this isn't the appropriate place to ask questions, but I don't know another place)

After "pip install pydaedalus" under Anaconda Python 2.7.13 on Mac, I get

ImportError                               Traceback (most recent call last)
<ipython-input-1-526a22e210bd> in <module>()
      2 import matplotlib.pyplot as plt
      3 import numpy as np
----> 4 from daedalus import Maze

/Users/bbeckman/Documents/pydaedalus/daedalus/__init__.py in <module>()
     25     __version__ = "unknown (%s)" % ex
     26 
---> 27 from ._maze import (Maze,
     28                     COLOR_WHITE, COLOR_BLACK,
     29                     ENTRANCE_CORNER, ENTRANCE_MIDDLE, ENTRANCE_BALANCED, ENTRANCE_RANDOM)

ImportError: No module named _maze

I deduce that I must build the cpp sources and figure out how to get an interop module "_maze" going. No problem, but a few questions

  1. Does this compile only on Windows, or is there any hope of building it on Mac or Linux? I notice the src directory has a version of Daedalus with a bunch of cpp files, some of which seems algorithmic and some of which seem to be interfacing to Windows. At least conceptually, it should be possible to separate the algorithmic bits from the Windows bits (but doing so requires some intentionality on the part of the original programmer, lest Windows dependencies leak all over the rest of the code). Because you're using matplotlib and Python for display, there should be no theoretical reason for dependency on Windows.

  2. If you've built it off Windows, would you happen to have a CMakeLists.txt or makefile?

wroberts commented 7 years ago

Hi, thanks for the bug report. This is exactly the right place to discuss this issue.

Daedalus is Windows software, but for this project I just bolted a cython interface onto the side of it; therefore, pydaedalus does not require Windows (in fact, I've never tested it on Windows, I've only ever built it on Mac and Linux).

The _maze python extension is meant to be built with the setup.py script, and this should get called by pip automatically. If you're not able to import _maze, that on the face of it suggests a build error on your machine to me (more on this in a second). Before we get into that, though: why is your traceback showing pydaedalus under your ~/Documents directory? Surely that can't be where anaconda puts installed packages? I'd suggest trying the test code again, making sure that your working directory is not /Users/bbeckman/Documents/pydaedalus, just in case Python is loading from an uncompressed source download that doesn't have the extension compiled.

I can't remember quite what happens when pip fails to build an extension, but you can try checking that things look OK. If you pip unistall pydaedalus and then reinstall, you can watch the build happening; if anything is breaking, this is where it's happening. For me, pip hides output unless I ask it to be verbose (like -v; I use -vvv):

sudo pip install --no-use-wheel -vvv pydaedalus

With verbose output, I can watch the compiler (clang++ for me) getting called, and there's miles of warnings dumped (daedalus uses quite a bit of old-style C code that modern C++ compilers get grumpy about), but no errors. The last lines look like:

/usr/bin/clang++ -bundle -undefined dynamic_lookup -isysroot / -L/opt/local/lib -Wl,-headerpad_max_install_names -L/opt/local/lib/db48 build/temp.macosx-10.11-x86_64-2.7/daedalus/_maze.o build/temp.macosx-10.11-x86_64-2.7/daedalus/wrapper.o build/temp.macosx-10.11-x86_64-2.7/daedalus/src/daedalus.o build/temp.macosx-10.11-x86_64-2.7/daedalus/src/maze.o build/temp.macosx-10.11-x86_64-2.7/daedalus/src/solve.o build/temp.macosx-10.11-x86_64-2.7/daedalus/src/util.o build/temp.macosx-10.11-x86_64-2.7/daedalus/src/graphics.o build/temp.macosx-10.11-x86_64-2.7/daedalus/src/color.o build/temp.macosx-10.11-x86_64-2.7/daedalus/src/create.o build/temp.macosx-10.11-x86_64-2.7/daedalus/src/create2.o build/temp.macosx-10.11-x86_64-2.7/daedalus/src/create3.o build/temp.macosx-10.11-x86_64-2.7/daedalus/src/labyrnth.o build/temp.macosx-10.11-x86_64-2.7/daedalus/src/threed.o build/temp.macosx-10.11-x86_64-2.7/daedalus/src/draw.o build/temp.macosx-10.11-x86_64-2.7/daedalus/src/inside.o build/temp.macosx-10.11-x86_64-2.7/daedalus/src/command.o build/temp.macosx-10.11-x86_64-2.7/daedalus/src/solids.o build/temp.macosx-10.11-x86_64-2.7/daedalus/src/draw2.o -o build/lib.macosx-10.11-x86_64-2.7/daedalus/_maze.so
running install_lib
creating /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/daedalus
copying build/lib.macosx-10.11-x86_64-2.7/daedalus/__init__.py -> /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/daedalus
copying build/lib.macosx-10.11-x86_64-2.7/daedalus/_maze.so -> /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/daedalus
creating /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/daedalus/test
copying build/lib.macosx-10.11-x86_64-2.7/daedalus/test/__init__.py -> /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/daedalus/test
copying build/lib.macosx-10.11-x86_64-2.7/daedalus/test/test_maze.py -> /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/daedalus/test
byte-compiling /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/daedalus/__init__.py to __init__.pyc
byte-compiling /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/daedalus/test/__init__.py to __init__.pyc
byte-compiling /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/daedalus/test/test_maze.py to test_maze.pyc
running install_egg_info
running egg_info
writing pydaedalus.egg-info/PKG-INFO
writing top-level names to pydaedalus.egg-info/top_level.txt
writing dependency_links to pydaedalus.egg-info/dependency_links.txt
reading manifest file 'pydaedalus.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
warning: no files found matching 'LICENSE.md'
warning: no files found matching 'daedalus/src/unused'
writing manifest file 'pydaedalus.egg-info/SOURCES.txt'
Copying pydaedalus.egg-info to /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pydaedalus-0.1.3-py2.7.egg-info
running install_scripts
writing list of installed files to '/tmp/pip-466Qfv-record/install-record.txt'
done
Removing source in /private/tmp/pip-build-L1nFfg/pydaedalus

So you can see that my extension module lives at /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/daedalus/_maze.so (I'm on OS X 10.11 using Py2.7 installed with MacPorts).

As a final note, there's always the disappointing possibility that yer Mac OS X just plain doesn't have a C compiler; after all, Apples don't ship with compilers installed, you gotta do it yourself. If running both which clang++ and which g++ in your shell doesn't report any paths, this may be your problem; see How to install a C compiler for more.