GraylinKim / sc2reader

A python library that extracts data from various Starcraft II resources to power tools and services for the SC2 community. Who doesn't want to hack on the games they play?
http://sc2reader.readthedocs.org
MIT License
411 stars 85 forks source link

Is mpyq a hard dependency? #172

Closed headwinds closed 9 years ago

headwinds commented 10 years ago

In the getting started documentation, it states that you need to import the sc2reader module into your python project.

import sc2reader
replay = sc2reader.load_replay('MyReplay', load_map=true)

I tried that and received errors about a missing mpyq module which is imported in resources.py. I found mpyq on github and grabbed the source. But then where should I put this mpyq module in my project? does it need to be configured anywhere?

Traceback (most recent call last):
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/runtime/wsgi.py", line 239, in Handle
    handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/runtime/wsgi.py", line 298, in _LoadHandler
    handler, path, err = LoadObject(self._handler)
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/runtime/wsgi.py", line 84, in LoadObject
    obj = __import__(path[0])
  File "/Users/bflowers/Projects/headwinds/sc2jsonhunt/handlers.py", line 20, in <module>
    import model
  File "/Users/bflowers/Projects/headwinds/sc2jsonhunt/model.py", line 34, in <module>
    from sc2reader.scripts import sc2json
  File "/Users/bflowers/Projects/headwinds/sc2jsonhunt/sc2reader/__init__.py", line 11, in <module>
    from sc2reader import factories, log_utils
  File "/Users/bflowers/Projects/headwinds/sc2jsonhunt/sc2reader/factories/__init__.py", line 3, in <module>
    from sc2reader.factories.sc2factory import SC2Factory
  File "/Users/bflowers/Projects/headwinds/sc2jsonhunt/sc2reader/factories/sc2factory.py", line 26, in <module>
    from sc2reader.resources import Resource, Replay, Map, GameSummary, Localization
  File "/Users/bflowers/Projects/headwinds/sc2jsonhunt/sc2reader/resources.py", line 11, in <module>
    import mpyq
ImportError: No module named mpyq
INFO     2014-05-12 13:14:00,558 module.py:627] default: "GET /api/themes HTTP/1.1" 500 -
INFO     2014-05-12 13:14:00,624 module.py:627] default: "GET /favicon.ico HTTP/1.1" 200 1704
INFO     2014-05-12 13:14:00,800 module.py:627] default: "GET /favicon.ico HTTP/1.1" 304 -
ERROR    2014-05-12 13:14:00,826 wsgi.py:262] 
Traceback (most recent call last):
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/runtime/wsgi.py", line 239, in Handle
    handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/runtime/wsgi.py", line 298, in _LoadHandler
    handler, path, err = LoadObject(self._handler)
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/runtime/wsgi.py", line 84, in LoadObject
    obj = __import__(path[0])
  File "/Users/bflowers/Projects/headwinds/sc2jsonhunt/handlers.py", line 20, in <module>
    import model
  File "/Users/bflowers/Projects/headwinds/sc2jsonhunt/model.py", line 34, in <module>
    from sc2reader.scripts import sc2json
  File "/Users/bflowers/Projects/headwinds/sc2jsonhunt/sc2reader/__init__.py", line 10, in <module>
    from sc2reader import engine
ImportError: cannot import name engine
GraylinKim commented 10 years ago

I'd recommend that you follow the installation guide to make sure things work correctly. It seems like you are working from source so use this one. This will install mypq into the correct location on your system.

Alternately, you could use pip install mpyq to install mpyq separately or install mpyq from source using a process similar to the one outlined for sc2reader in the link above.

EHadoux commented 10 years ago

Actually, I got the same issue as @headwinds in #157. I solved it as @GraylinKim says: I installed mypq separately with pip then I retried installing sc2reader (but I used the contributor installation).

headwinds commented 10 years ago

mpyq is installed and sc2reader works fine on my machine ;-D

I think the problem for me is when I try to use it in larger python project. I want to use sc2reader a library - as you intended it.

When I run python to compile my app, it can't find mpyq anymore even if I place the mpyq directory in the same location as resources.py - in theory, it should be able to find the mpyq library right?

Perhaps you could take a quick look at my progress log

headwinds commented 10 years ago

@EHadoux had an good suggestion about including a requirements.txt file. In my case, I'm trying to deploy to Google App Engine - would a requirements.txt tell the GAE server to install the necessary dependencies like mpyq?

headwinds commented 10 years ago

hey hey - some more googling - someone else created one - is this a sound approach?

headwinds commented 10 years ago

great that got me unstuck - I just needed to know where the disconnect was happening - it's on the GAE end - I discovered this stackover thread about importing python modules with GAE - I took the simple suggestion to drop in mpyq.py file into my project and its working now... well throwing different errors... but gives me something different to chase after. I'll probably try the slightly more complex lib approach next...

GraylinKim commented 10 years ago

There is no need for a requirements.txt file. Any installation from pypi or source using setup.py will install sc2reader and mypy just fine. I do not understand how someone following the installation directions would have any trouble.

To include sc2reader in a larger project you can add sc2reader to your projects requirements file or install it manually using the normal installation directions.

If you can be more specific about the setup steps you took that failed I can try to improve the documentation.

headwinds commented 10 years ago

You're not a junior python dev ;-D you're absolutely right - the instructions are great! I had no trouble installing it just trouble with deploying it. I don't know what the "normal installation directions" are so am going through a lot of python 101 stuff - apologies.

EHadoux commented 10 years ago

I do not understand how someone following the installation directions would have any trouble.

As far as I remember, the problem came (in my case) from the automatic installation of mpyq with the installation of sc2reader. After installing mpyq alone, sc2reader installed flawlessly.

hey hey - some more googling - someone else created one - is this a sound approach?

It's like that, yes.

I took the simple suggestion to drop in mpyq.py file into my project and its working now...

You can import it is different from it is working. In the example of the link, the "library" consists in a standalone file. I don't think it is the case for mpyq, you cannot use it like that thus. (my bad)

GraylinKim commented 10 years ago

Mpyq is a single file module so that will work just fine.

Separately, I'll add instructions for including sc2reader as a dependency in other projects.

headwinds commented 10 years ago

I can definitely help share my notes - as a bronze league python dev, I can share those trivial details that GMs probably wouldn't think worthwhile

I actually just made a major breakthrough in my own experiments - I've successfully deployed my app to GAE - it reads 10 lines of a sc2 replay and returns the camera events as a string which lots a lot like json.

so proud - I know its useless to an end user but I'm making good progress now thanks to your help!

GraylinKim commented 9 years ago

I'm going to close this issue out. To anyone coming upon this issue later, you cannot install your own dependencies on GAE. Instead you need to deploy them along side your project. When doing this you need to resolve all sub-dependencies of your project manually. In this case, you must both add mpyq and sc2reader files to your project.