Understanding PyInstaller

147 views
Skip to first unread message

Tony C

unread,
Jan 4, 2024, 9:01:43 PMJan 4
to PyInstaller

Hello,

I've been reading through the Pyinstaller docs trying to understand why the Python interpreter can find modules at application runtime (as sources, NOT an exe), but Pyinstaller
cannot. Pyinstaller itself is also a python application.

Oddly enough, I ran into an issue today where Pyinstaller couldn't find an import that comes with the Python interpreter (Python 3.11). This makes no sense to me.

When I fire up the python interpreter and manually import that module (imp.py)
the import works, although a deprecation warning is displayed.

import imp
"<stdin>:1: DeprecationWarning: the imp module is deprecated in favour of importlib and slated for removal in Python 3.12; see the module's documentation for alternative uses"

bwoodsend

unread,
Jan 4, 2024, 9:05:54 PMJan 4
to PyInstaller

Are you sure that your pyinstaller is not in a Python 3.12 environment? Freezing import imp works fine for me under Python 3.11.

Jasper Harrison

unread,
Jan 4, 2024, 9:08:42 PMJan 4
to pyins...@googlegroups.com
To answer the more general question of why PyInstaller can't find a certain module at runtime - it only packages the modules it thinks your program needs, and sometimes it doesn't detect a module correctly, leading to it not being included.

Jasper Harrison, aka Legorooj
Core Developer on PyInstaller






-------- Original Message --------
--
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/5aebaf08-6c8b-4f4d-b542-52846d89cd9en%40googlegroups.com.
publickey - EmailAddress(s=legorooj@protonmail.com) - 0x164CF234.asc
signature.asc

Tony C

unread,
Jan 5, 2024, 6:23:16 AMJan 5
to PyInstaller
The simple fact that pyinstaller is complaining about stdlib modules is just odd.

Tony C

unread,
Jan 5, 2024, 6:23:16 AMJan 5
to PyInstaller
Yes, it's Python 3.11

Python 3.11.2 (tags/v3.11.2:878ead1, Feb  7 2023, 16:38:35) [MSC v.1934 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.

Tony C

unread,
Jan 5, 2024, 6:23:16 AMJan 5
to PyInstaller
Thanks.
" it only packages the modules it thinks your program needs"

The question is - why doesn't it think any program doesn't need certain modules?

1. There is an import statement for that module at the top of the file.
2. There is clear usage of that module in the program, as in:
     result = module.function_call() 

I've gotten past a few of them by doing "Add file". This is the step that seems wrong though, since the module is imported and a function is called in that module.

bwoodsend

unread,
Jan 5, 2024, 6:36:28 AMJan 5
to PyInstaller

Python 3.11.2 (tags/v3.11.2:878ead1, Feb 7 2023, 16:38:35) [MSC v.1934 64 bit (AMD64)] on win32

But what does the second line of PyInstaller’s build log say?

The simple fact that pyinstaller is complaining about stdlib modules is just odd.

To PyInstaller, there’s no way of telling what modules are standard lib or 3rd party or your own code.

There is an import statement for that module at the top of the file.

Then PyInstaller will know that it needs that module and can’t find it. That reinforces my thinking that pyinstaller is not installed into that Python 3.11 environment that you think it is.

Tony Cappellini

unread,
Jan 5, 2024, 12:34:51 PMJan 5
to pyins...@googlegroups.com
>>But what does the second line of PyInstaller’s build log say?
483 INFO: PyInstaller: 6.3.0
483 INFO: Python: 3.11.2


>>To PyInstaller, there’s no way of telling what modules are standard lib or 3rd party or your own code.
The path to the python interpreter should make that easy

>>That reinforces my thinking that pyinstaller is not installed into that Python 3.11 environment that you think it is.
There is only 1 python interpreter on this system, and there are no virtual environments


--
You received this message because you are subscribed to a topic in the Google Groups "PyInstaller" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/pyinstaller/Uo-ss_svKXc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to pyinstaller...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyinstaller/bf9c6a84-b767-4cb1-8b39-b380029bb10fn%40googlegroups.com.

Chris Barker

unread,
Jan 5, 2024, 12:47:19 PMJan 5
to pyins...@googlegroups.com
On Fri, Jan 5, 2024 at 9:34 AM Tony Cappellini <capp...@gmail.com> wrote:
>>But what does the second line of PyInstaller’s build log say?
483 INFO: PyInstaller: 6.3.0
483 INFO: Python: 3.11.2

That looks right then.

I'm no expert, but it seems something is going fundamentally wrong here. My suggestion:

- make a VERY simple little script with minimal imports -- maybe without imp if you think that's a particular issue. Maybe pull an example from the docs.

- try to build it with PyInstaller

- if it doesn't work, then post EVERYTHING you did here, including the build log.

If it does work, then slowly add stuff to make it more complicated.

NOTE: I suspect the `imp` issue is a red herring -- unless it the only module that PyInstaller is having trouble with -- which I don't think is the case.

nevertheless, imp is deprecated -- now would be a good time to update that code :-)

HTH,
-CHB



 
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/CABRXM4kKam-3XMP7%3DjdWzYJ_sYNW0%2B%2B-RW7cCfuBYOKdWQZcDA%40mail.gmail.com.


--

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris....@noaa.gov

bwoodsend

unread,
Jan 5, 2024, 12:50:47 PMJan 5
to PyInstaller

Also worth checking the imp entry in the build/*/xref-*.html. I’m guessing it’s going to say not found which won’t tell us much but it might say something else.

Tony Cappellini

unread,
Jan 5, 2024, 1:41:10 PMJan 5
to pyins...@googlegroups.com
Got it, will try both of those

On Fri, Jan 5, 2024 at 9:50 AM bwoodsend <bwoo...@gmail.com> wrote:

Also worth checking the imp entry in the build/*/xref-*.html. I’m guessing it’s going to say not found which won’t tell us much but it might say something else.

--
You received this message because you are subscribed to a topic in the Google Groups "PyInstaller" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/pyinstaller/Uo-ss_svKXc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to pyinstaller...@googlegroups.com.
Message has been deleted

Tony C

unread,
Jan 5, 2024, 3:11:41 PMJan 5
to PyInstaller
I need to retract/delete that last email.
I was looking in an xref file that was generated yesterday, so I've deleted build & dist.

Now, only the output directory is being created. build and dist are not being generated in the project directory on each build.
Very strange

I do see build and dist being created in C:\Users\MyUSername\AppData\Local\Temp\blahblah\build   though

Why did these directories move?

Tony C

unread,
Jan 5, 2024, 3:18:10 PMJan 5
to PyInstaller
Here are some anomalies that I don't understand, from the AppData xfref file

Types if import:
* top-level: imported at the top-level - look at these first
* conditional: imported within an if-statement
* delayed: imported within a function
* optional: imported within a try-except-statement

IMPORTANT: Do NOT post this list to the issue-tracker. Use it as a basis for
            tracking down the missing module yourself. Thanks!

missing module named 'org.python' - imported by copy (optional)
missing module named org - imported by pickle (optional)
missing module named pwd - imported by posixpath (delayed, conditional, optional), shutil (delayed, optional), tarfile (optional), pathlib (delayed, optional), subprocess (delayed, conditional, optional)
missing module named grp - imported by shutil (delayed, optional), tarfile (optional), pathlib (delayed, optional), subprocess (delayed, conditional, optional)
missing module named posix - imported by posixpath (optional), shutil (conditional), importlib._bootstrap_external (conditional), os (conditional, optional)
missing module named resource - imported by posix (top-level)
missing module named _frozen_importlib_external - imported by importlib._bootstrap (delayed), importlib (optional), importlib.abc (optional)
excluded module named _frozen_importlib - imported by importlib (optional), importlib.abc (optional)
missing module named _posixsubprocess - imported by subprocess (conditional)
missing module named fcntl - imported by subprocess (optional)
missing module named readline - imported by code (delayed, conditional, optional)

These are stdlib modules that I have no problem importing in my program.


On Friday, January 5, 2024 at 9:50:47 AM UTC-8 bwoodsend wrote:

Samuel Aondo

unread,
Jun 1, 2024, 11:07:09 AMJun 1
to PyInstaller
here is a custom tool to solve your problems like module not found https://github.com/sazalo101/py-to-exe-or-linux-executable/
Reply all
Reply to author
Forward
0 new messages