Importing pye files

85 views
Skip to first unread message

Amanda Beuno

unread,
Sep 2, 2020, 9:50:43 AM9/2/20
to PyInstaller
Good day, 

I searched the group on how to import pye files but I couldn`t find any topics on that matter. Apologies if I missed it.

I have a pye file in my project that I need to import in my project and I tried adding it using "--hidden-import", but I always get "missing module named pyeModule". 

I also tried adding that pye file to the PYTHONPATH but to no avail. 

Any pointers would be appreciated!

Amanda 

bwoodsend

unread,
Sep 2, 2020, 10:35:18 AM9/2/20
to PyInstaller
I'm pretty certain PyInstaller is completely unaware `.pye`s exist and are therefore not recognised by any of the import/`PYTHONPATH` based parts of PyInstaller. So `--hidden-import` won't do it but just adding it as a plain data file using `--add-data=source:target` should work. This gets used quite often for `.pyd`s.

Where in your app you should put it (the `target`) depends on how you import your `pye`. If you use plain `import pyeModule` then it should just go in the root of your app:

```shell
PyInstaller --add-data=/path/to/pyeModule.pye:. your_script.py
```

If pyeModule is part if a larger package and you use `from foo.bar import pyeModule` then you need to mirror the directory structure:

```shell
PyInstaller --add-data=/path/to/pyeModue.pye:./foo/bar/ your_script.py
```

Vincent Le Goff

unread,
Sep 2, 2020, 10:35:20 AM9/2/20
to pyins...@googlegroups.com

Hi Amanda,

It seems you want to use the feature of pyconcrete.  I haven't used that package myself but from the documentation, it would seem like .pye files are looked in the Python path.  My guess would be to import them, not as hidden modules (it won't work, hidden modules only are for Python modules, .py files, if I'm not mistaken), but as data files.  You then need to extend sys.path to let it know where to find your PYE files.

I might be mistaken, someone will correct if I'm wrong, but I believe, when you freeze a Python script with PyInstaller, the generated Python script has a limited sys.path which doesn't include the current working directory, contrary to what happens in a non-frozen Python environment.  I tend to add a line like this at the top of my main project file, to ensure the Python path contains the current working directory, even when frozen:

from pathlib import Path
import sys
sys.path.append(str(Path().absolute()))
Obviously, you'll need to do that in your main script and before you import your PyE file.  And your .pye file will need to be in the "current working directory" when you execute your frozen script.  So you'll also need to add it as a data file.

You don't have to put it in the root directory either.  It can be messy.  You can place it in a sub-directory.  That's your choice.  Just remember to edit your .spec file accordingly, and your main script to extend the Python path.

HTH,

Vincent

--
You received this message because you are subscribed to the Google Groups "PyInstaller" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyinstaller...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyinstaller/f77233e4-fc99-4bf2-9f86-67f5e36468f9n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages