PYD Files in a subfolder?

This forum is currently in read-only mode.
From the Asset Store
Source File, music and art pack for Android Negotiator
  • 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.

  • is there a way to put *.pyd files into a subfolder instead of in base directory with the exe? I

    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?!

  • Including the *.pyd files within the executable doesn't work. Rojohound? Where ya at? lol

  • 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?

  • 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:

    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?
  • 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:

      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

    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:

    <img src="http://kmvegas.com/gamedev/error1.png">

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

    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 [b]kmvegas[/b]? Also, why the inconsistency of not needing to import sys? (According to python.org it needs to be imported)
  • 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.

  • 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.

    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:

    - 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)
  • 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

  • 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

    Here you are

    PyPkgTest.rar

    The rar contains a folder "PyPkgTest". Wherever I move this folder to both .cap and compiled .exe work. Of course, the inner structure of this parent folder needs to be kept intact. The module is a very *very* easy example module, it's just a class that counts from 10 up with step 10 and resets when reaching 100. But with it you can validate that it's really working.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Ah... I think I might know what the issue was. I was attempting to include the py/pyc files within the executable but leave the pyd files outside in the directory / subdirectory. Maybe that's the difference between your method and R0J0's, since his worked for me and yours didn't. In any case, your example does work just fine so I have kind of a template now to experiment with. Thanks much!

  • You're welcome

    Could it be some kind of reference problem? Take the "PyPkgTest" folder as an example and copy one of the .pyd (e.g. base.pyd) to the folder "mypython". Now (having appended the game's folder path to sys.path) to reference it, you can't just import "base". It needs to be

    import mypython.base[/code:nbqn8006]or
    [code:nbqn8006]from mypython import base[/code:nbqn8006]
    
    For the first one, all calls to "base" must be "mypython.base", the second one let's you reference it directly, without "mypython."
    
    EDIT: Also, Python is case-sensitive. Something like "import myPython.base" won't work, cause the folder is known to Python as "mypython"
  • Honestly, I think it has something to do with how Pygame references it's files, after looking at some of it's .py files.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)