PYD Files in a subfolder?

For questions about using Classic.

Post » Sat Sep 11, 2010 12:17 am

I've seen this mentioned here and there, but nobody has concluded one way or another... is there a way to put *.pyd files into a subfolder instead of in base directory with the exe? I'm using pygames for joystick support, causing me to have 11 *.pyd files uglying up the folder.
B
2
G
2
Posts: 14
Reputation: 678

Post » Sat Sep 11, 2010 1:26 am

[quote="kmvegas":35ue2bfq]is there a way to put *.pyd files into a subfolder instead of in base directory with the exe? I[/quote:35ue2bfq]
I bet ROjohound would be the best person to answer this. I don't have a system configured to test this right now, but you could try placing the .pyd files in the Construct/Data/Python directory. Then selecting them when you go to build your executable. It might just be embedded in the .exe then. If that doesn't work, then that should be a feature request.

Technically, it is possible to do what you are saying: either put in subfolder or embed in .exe (you can do both with Py2exe). It is just it may not yet be possible through Construct. Rojohound?!
B
8
S
3
G
7
Posts: 835
Reputation: 5,313

Post » Sat Sep 11, 2010 4:21 am

Including the *.pyd files within the executable doesn't work. Rojohound? Where ya at? lol
B
2
G
2
Posts: 14
Reputation: 678

Post » Sat Sep 11, 2010 4:59 am

If I'm totally aside just ignore me, but does the standard package way not work?

If you create a folder (e.g. named joystick) for the .pyd in your games folder, place a empty __init__.py there too and in the script editor before anything else write

import os
import sys
sys.path.append(os.path.join(os.getcwd(), "joystick"))

That does not work?
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Sat Sep 11, 2010 11:40 am

Hi,
If you have all you pyd files in a sub-directory named "joystick", then run this line once at the start of the program and it should work:
[code:un7xghsh]sys.path.append(System.AppPath + 'joystick')[/code:un7xghsh]

Alternatively it should work by just selecting the relevant pyd files when exporting to an exe. What are the 11 pyd files?
B
79
S
24
G
52
Posts: 4,725
Reputation: 39,713

Post » Sat Sep 11, 2010 3:57 pm

Thanks for the help guys! First of all, R0J0hound's method of using a subdirectory worked. I then threw a blank __init__.py into the folder and changed the script to tulamide's, and it failed. As far as including the files with the exe, I haven't gotten that to work at all.

The files to be included are:

[list:2plgunkg]pygame.base.pyd
pygame.bufferproxy.pyd
pygame.color.pyd
pygame.constants.pyd
pygame.display.pyd
pygame.event.pyd
pygame.joystick.pyd
pygame.rect.pyd
pygame.rwobject.pyd
pygame.surface.pyd
pygame.surflock.pyd[/list:u:2plgunkg]

The pygame. prefix was added by cxfreeze when I used it to figure out which files I needed.

Also, the error I get when it can't find the files is:
B
2
G
2
Posts: 14
Reputation: 678

Post » Sat Sep 11, 2010 6:58 pm

R0J0hound, could you explain what exactly could be the difference between

[code:hnv0bltc]import os
import sys
sys.path.append(os.path.join(os.getcwd(), "joystick"))[/code:hnv0bltc]and

[code:hnv0bltc]sys.path.append(System.AppPath + 'joystick')[/code:hnv0bltc]?

The first one works like a charm for me, so why didn't it work for kmvegas? Also, why the inconsistency of not needing to import sys? (According to python.org it needs to be imported)
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Sat Sep 11, 2010 7:38 pm

Tulamide, they should work identically, I suspect the blank __init__.pyd caused it not to work. I didn't "import sys" because it was already imported when Construct initialized python.
B
79
S
24
G
52
Posts: 4,725
Reputation: 39,713

Post » Sat Sep 11, 2010 9:09 pm

[quote="R0J0hound":1ly30354]Tulamide, they should work identically, I suspect the blank __init__.pyd caused it not to work. I didn't "import sys" because it was already imported when Construct initialized python.[/quote:1ly30354]
Thank you, R0J0hound. The information about sys is stored :)
For the curious among us: The blank file I mentioned should be named __init__.py not .pyd (two leading and two trailing underscores), and is a kind of identifier for a python package. The __init__.py files are required to make Python treat the directories as containing packages.

This is a python package folder structure inside your games folder:
[code:1ly30354]- plants
__init__.py
- trees
__init__.py
beech.py
oak.py
- flowers
__init__.py
tulip.py
violet.py[/code:1ly30354]
The package is identified by its name "plants".

Now you only need to add the current working directory (= the path to your games folder) to sys.path:

version 1
[code:1ly30354]import os
sys.path.append(os.getcwd())[/code:1ly30354]
version 2
[code:1ly30354]sys.path.append(System.AppPath)[/code:1ly30354]
version 1 is of help if you happen to import a package from within a module.

Either way, the package is now available for import. You access them with their folder and module names in a dot structure, and there are several ways to import what you need:
[code:1ly30354]import plants.trees.oak[/code:1ly30354]
This imports the module oak, and it must be referenced in code with the full name structure:
[code:1ly30354]plants.trees.oak.grow(speed, branch)[/code:1ly30354](assuming, grow is a function of the module oak)

A reference shortcut is:
[code:1ly30354]from plants.trees import oak[/code:1ly30354]
Now oak can be referenced directly:
[code:1ly30354]oak.grow(speed, branch)[/code:1ly30354]

These techniques work for all files that are imported directly using import, either pure python or extensions (like the dll for python, identified by the extension .pyd)
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Sun Sep 12, 2010 1:19 am

tulamide, I don't mean to be a bother but is there any way you could show me a working example, both *.cap and compiled? I feel really stupid but for some reason, I just can't get your method to work
B
2
G
2
Posts: 14
Reputation: 678

Next

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 2 guests