OK, hold on, lets clear up a bit of confusion here. Now that I have more than 5 minutes to write a post at the end of a class, here we go. So paul is somewhat wrong, if you use cython, you will likely want to use a pyinstaller hook to manage your hidden imports. So, you will probably need to use them. Hooks aren't just for hiddenimports, hooks are used when you have a package that needs special treatment when compiling. Maybe it's moving a dll file to the proper place or maybe it's just hiddenimports or maybe it's printing a warning to the user saying hey bro please upgrade me to compile. Using hooks for hiddenimports though is at least what I do and it works quite well. No, you don't need one for each module. Basically what you do is choose a module, any module. It needs to exist though. This may or may not work with the main script, I've never tested that, so I'd just use a module. So lets say our module is called game.py. Just encase you need other custom hooks, what I would do is create a folder in your games running directory called hooks. Now, create a file called "hook-game.py" in your hooks folder. This is actually a python script, allowing you to import stuff and do whatever pythonic thing you need to. In this case, all you need is hiddenimports. Basically pyinstaller will exec this python script once you tell it about the hooks folder, and access the hiddenimports global of it. So say in your cythonized file, you include the modules os, threading, enemy, json, and item. To tell pyinstaller about these imports, add this to your hook-game.py file of course excluding the start and end quotes. "hiddenimports=["os", "json", "threading", "game", "item"]". Now, to tell pyinstaller about your hook, pass the additional argument --additional-hooks-dir, like this. "--additional-hooks-dir=hooks". Now when you build with that argument, the hook-game.py file will be executed and the modules from the hiddenimports variable you declared in it will be included. I have not tested it and am not sure of the sintax, but you can also declare hiddenimports through the command line. I believe there is a --hiddenimports arg or something, but as I said I never tested for how to use it. You can also use spec files like you were doing before, but as I said in my previous post, you can't change command line arguments when using a spec file as far as I know. I don't use spec files at all so others may have a much more complete knowledge of this than me. But from my understanding, spec files are actually built using your command line arguments. So when you build a spec based on your py script, like pyinstaller --onefile --windowed script.py, it will make a spec file based on those arguments. So now, to recompile, you can call pyinstaller script.spec and it will use the arguments you first used to create it. Thus, if you pass new arguments, they won't be used because the spec file overrides them. To change them, you have to modify the spec file in notepad, as visualstudio pointed out. As I said I'm not completely clear on it so take what I say about spec files with a grain of salt. However, there is a much, much less annoying approach you can take. Why bother with hiddenimports at all! Remember, all your trying to do here is to tell pyinstaller that a module you need must be imported. By default, pyinstaller scans all scripts it loads for import lines and uses that to figure out imports. So, all you need to do is in your main script that you are compiling, that launches your application, just add them all there. "import os, threading, json, game, item". Now compile, and it'll work perfectly. All you need pyinstaller to do is to import the modules. It doesn't matter what scripts use them, they just need to be in the pyinstaller package, and then any module that needs can use them. So what I'm trying to say here is that imports are separate from the modules that import them. Basically on compile, pyinstaller finds all the imports it can, and tosses them into your final package. When you run that package, it doesn't matter where they came from just that they are there. Your modules will import what's needed, and if it exists, your app will start. So knowing this, you can skip the step of hiddenimports entirely. Obviously you have to start from a python script when you compile with pyinstaller, so in that script, just make sure to keep updating it with new import lines whenever you add a new one to something that will be cythonized. So long as those imports are in a file pyinstaller can read, and of course it can read your main file, those imports will be included and your app will work just fine. Then, you don't need spec files at all. Ultimately what path you choose to take is up to you. Hope this makes things more clear, please don't hesitate to ask questions.
I am a web designer, and a game developer. If you wish see me at
http://www.samtupy.com