Python External Libraries w/ AI, Speech

Post your own tutorials, guides and demos.

Post » Fri May 21, 2010 5:44 pm

Do you have setuptools installed?
[url:3bbhi16n]http://pypi.python.org/pypi/setuptools[/url:3bbhi16n]
Image Image
B
161
S
48
G
89
Posts: 7,347
Reputation: 66,249

Post » Fri May 21, 2010 5:53 pm

Yeah, it comes with the ActivePython install, i believe.

At least, when i downloaded the package you linked to and i tried installing it, it gave me an error like: "cannot create a directory when one exists already".
B
2
G
3
Posts: 52
Reputation: 954

Post » Fri May 21, 2010 6:23 pm

Err...okay i figured it out. Somehow. This is how i did it.

So, i had installed ActivePython which set up my file dependancies properly (which the normal distro of python did NOT do, much to my frustration) and it gave me PythonWin, a GUI Python editor.

I made hello.py and setup.py for py2exe as per stated in the tutorial, then i made setup.py into setup.pyc by opening setup.py in PythonWin and clicking "import" which gave this output in PythonWin:

[quote:2fsxuk02]File "C:\Python26\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 427, in ImportFile
exec codeObj in __main__.__dict__
File "<auto import>", line 1, in <module>
File "C:\Pythonery\setup.py", line 4, in <module>
setup(console=["hello.py"])
File "C:\Python26\lib\distutils\core.py", line 140, in setup
raise SystemExit, gen_usage(dist.script_name) + "\nerror: %s" % msg
SystemExit: usage: [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
or: --help [cmd1 cmd2 ...]
or: --help-commands
or: cmd --help

error: no commands supplied[/quote:2fsxuk02]

Then, i could use the command "setup.pyc py2exe" (instead of "setup.py py2exe" like it says in the tutorial) and it compiles properly!

I'm completely new at Python and i kinda feel like i stumbled on this solution, so if someone can explain why it worked, i will be happy.
B
2
G
3
Posts: 52
Reputation: 954

Post » Sat May 22, 2010 4:34 pm

Very bizarre solution! I'm glad it is working. :D

When you ran the import command in PythonWin that actually generated an error, but at the same time it byte compiled the setup.py file. All a .pyc file is, is a byte-compiled version of the .py file. A byte-compiled version will load faster the next time because the compiling step will be skipped and the code will just be interpreted at runtime. There are some optimization flags that can be used to give a potential speedup in execution as well. If you are interested in massive speedups then look at Psyco which Just-In_Time (JIT) compiles Python code (but it only works on 32-bit systems currently).

Somehow, by byte-compiling it helped resolve the odd path issues so when you ran the full "setup.pyc py2exe" everything worked fine!

At some point in the future when I get a Windows 7 system setup properly I'll look into the best way to get this stuff to work.
B
8
S
3
G
7
Posts: 835
Reputation: 5,313

Post » Sat May 22, 2010 10:04 pm

Even though it works better than it did before--even managing to get the AIML example working perfectly as a .py script--i can't seem to get it to compile with py2exe properly. When i compile it and try to run the AIML exe, it says "WARNING: No match found for input: load aiml b" and anytime i try typing, it says the same thing but with whatever i typed in the prompt. :?

Mostly, i wanted to learn how to import python into Construct so i can import Pygame and be able to use a joystick with my games. If you can point me in the direction of the libraries i need for that, i would be happy. I would definitely be MORE happy if i could get this whole py2exe thing to work myself, but so it goes. :D

I think i may take a break from trying to get libraries to import for now and to try and learn Python on it's own. Thanks for your help and tutorials, though! Much appreciated.
B
2
G
3
Posts: 52
Reputation: 954

Post » Sat May 22, 2010 10:53 pm

[quote="feeblethemighty":3b9nmrj4]When i compile it and try to run the AIML exe, it says "WARNING: No match found for input: load aiml b" and anytime i try typing,[/quote:3b9nmrj4]
This error means that you didn't copy the AIML files into your execution path. It has to have something to load! The aiml files are the standard.zip which have to be unzipped in the same directory as your .cap or .exe.


As far as getting PyGame to work with Construct just use this:
http://www.box.net/shared/kcoxzzt7bz

This has the dependencies for Pygame. You will need to unzip the contents of the Library.zip file into your Construct/Data/Python directory. You will need to check all of the .pyc files per the quickguide, but you can skip PodSixnet and other unrelated .pyc files. The other dependencies (modules.zip) have to be redistributed with your game. Now you don't need ALL of those, but it will be up to you to decide which ones you need based on which parts of Pygame you use!

I've used Pygame several times within Construct this way and it works just fine!

Have fun in your Python studying!
B
8
S
3
G
7
Posts: 835
Reputation: 5,313

Post » Fri May 28, 2010 2:56 am

Anyone know of a way to get them to work from a subfolder?
B
2
S
2
G
3
Posts: 114
Reputation: 1,553

Post » Fri May 28, 2010 3:34 am

What do you mean by "them"? I haven't thought about running all of the dependencies from a subfolder, but there is no reason technically that it wouldn't work. If it doesn't work, then a feature needs to be added to Construct to specify subfolders for Python dependencies.

Edit: Another thing I haven't tried, but should be possible (since you can do it in py2exe) is to embed all dependencies inside the executable. This includes the Dll and the pyd files. If you want to give it a shot copies those files into the Construct/Data/Python directory and then select them when exporting the .exe. Who knows it might work!
B
8
S
3
G
7
Posts: 835
Reputation: 5,313

Post » Sat May 29, 2010 6:21 am

It is the python modules I meant and I think I've got it close to working... to start off it would give me an error saying there is no shutil to import. I read up about inserting a __init__.py into the intended subfolder, that seems to get me a little further. But its saying I have to path module. I think thats supposed to be part of os.py but I have the os in my subfolder which it seems to recognize but I still get the path.py error. And I'm talking in circles out of frustration. Won't be able to work on it for a few days so if anyone figures that out let me know please.
B
2
S
2
G
3
Posts: 114
Reputation: 1,553

Post » Sat May 29, 2010 1:59 pm

You should never need to put any .py or .pyc dependencies in a subfolder or in the same folder as your executable. So things like os.pyc or shutil.pyc should ALWAYS be embedded in your executable. This is done right before you build your executable in Cosntruct.

I don't think adding a __Init__.py helps with .pyd files (Python modules/dynamic link libraries). A __init__.py is typically used to specify import and other info for other .py or .pyc files in the same directory.

I won't have anytime to try this out this week, but if you haven't gotten it working by next weekend I might give it a shot to see what can be done with the .pyd files.
B
8
S
3
G
7
Posts: 835
Reputation: 5,313

PreviousNext

Return to Your tutorials & example files

Who is online

Users browsing this forum: No registered users and 0 guests