configparser error: NoSectionError

159 views
Skip to first unread message

ttepperg

unread,
May 7, 2020, 5:51:44 AM5/7/20
to PyInstaller
Hi,

With the simplest script possible that only contains the following statement:

import pynbody

I get a weird error when trying to run the exe file (error message attached).


Pynbody is a library installed in a standard location, the same one in which
PyInstaller resides. Needless to say, I don't have the problem when running
the script from source (or any other more meaningful script using this library),
so the problem is happening at runtime.

I'm using PyInstaller 3.5 with Python 3.6 on a Mac (High Sierra).

Thanks a lot in advance for your help!

err.txt

Duane Kaufman

unread,
May 7, 2020, 8:17:23 AM5/7/20
to PyInstaller
Dear Sir,
Without reviewing the package pynbody myself, does it use an external file for configuration/setup? If it does, has it been included in the pyinstaller process as a dependency?

Sincerely,
Duane

Thor Tepper-Garcia

unread,
May 8, 2020, 2:37:02 AM5/8/20
to pyins...@googlegroups.com
Dear Duane (if I may),

Thank you for your email.

Pynbody does have a configuration file, which is however contained within its package directory. I’d assume that all of these files are imported by PyInstaller; most likely I’m mistaken.

Do I need to explicitly import this configuration file when creating an executable? If yes, how do I accomplish this?

Thanks in advance for your help!

Thor.

--
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/8a5b56ba-30dd-4fa0-a5de-40658e2b1ecb%40googlegroups.com.

Duane Kaufman

unread,
May 8, 2020, 8:25:02 AM5/8/20
to PyInstaller
Dear Thor,

> Pynbody does have a configuration file, which is however contained within its package directory. I’d assume that all of these files are imported by PyInstaller; most likely I’m mistaken.

I'm not sure pyinstaller simply wraps entire package directories as a group of files, though others may have deeper knowledge.

As a test, you might try just putting a copy of the configuration file next to the pyinstaller .exe, to see if it can find what it needs that way.

There are instructions in the docs for making pyinstaller package extra files into the .exe

Sincerely,
Duane
To unsubscribe from this group and stop receiving emails from it, send an email to pyins...@googlegroups.com.

bwoodsend

unread,
May 11, 2020, 3:19:49 AM5/11/20
to PyInstaller
Hi,

> Pynbody does have a configuration file, which is however contained within its package directory. I’d assume that all of these files are imported by PyInstaller; most likely I’m mistaken.
> I'm not sure pyinstaller simply wraps entire package directories as a group of files, though others may have deeper knowledge.

I can confirm that PyInstaller doesn't do anything of the sort I'm afraid. If you compile in 1 dir mode you may see folders inside named after packages such as numpy but that is because a dedicated hook file has been written for that package which explicitly specifies the data files to include and how to structure them.

I imagine your problem is just that config file isn't being bundled. The config filename is specified here in the source code. It uses the __file__ attribute which gets a bit ugly in PyInstaller but I'm fairly certain if you use the following it should work.
--add-data /full/path/to/site-packages/pynbody/default_config.ini;pynbody/default_config.ini

I'm afraid I can't test it as I don't have the compiler necessary to install pynbody but it's something I've had to do with other packages. If it doesn't work, try adding a print statement before the read command in pynbody's source code that prints the filename it is trying to read and post the output here.

Brénainn

Brénainn

Thor Tepper-Garcia

unread,
May 11, 2020, 3:19:54 AM5/11/20
to PyInstaller
Dear Duane,

Thanks for your reply.


> As a test, you might try just putting a copy of the configuration file next to the pyinstaller .exe, to see if it can find what it needs that way.
Unfortunately, that did not work. I also try explicitly importing the module within my python script; without success…

> There are instructions in the docs for making pyinstaller package extra files into the .exe
I’ll look into that, although on a quick read I could not find the information.

Thanks anyways,

Thor.

____________________________
Dr. Thorsten Tepper García
Astrophysicist
www.thorsten.mx
@thorsten_mx

ttepperg

unread,
May 20, 2020, 2:56:49 AM5/20/20
to PyInstaller
I have solved the issue.

It might be useful in other circumstances; I'm more than happy to provide
the details if anyone is interested.

Duane Kaufman

unread,
May 20, 2020, 8:16:15 AM5/20/20
to PyInstaller
Dear ttepperg,

If it is not too hard to do, a quick overview of what you had to do to fix this problem may help someone in the future.

Sincerely,
Duane

Thor Tepper-Garcia

unread,
May 21, 2020, 4:44:02 AM5/21/20
to pyins...@googlegroups.com
Dear Duane, Brénainn,

I did essentially what Brénainn suggested, although I did not see their reply until now; so I figured it out myself, and very much the hard way ;)
I simply copied the file config.ini file into my script’s dir and used the flag —add-data config.ini:pynbody

The trick is, as Brénainn mentioned, to understand that the dir structure of packages within the Python dist are mirrored by the temporary dir created at runtime. So my app was looking for the file within the <temp dir path>/pynbody but it was not there; also, —add-data config.ini:. did not help as this was binding the file into the parent dir.

Hope this helps others in similar situations.

Thor.

--
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/ec9c2499-b53f-4a0b-8801-4bdaf15247b2%40googlegroups.com.

bwoodsend

unread,
May 23, 2020, 4:58:20 AM5/23/20
to PyInstaller
 Hi Thor, thanks for sharing that.

I've written a PyInstaller hook based on what you've said. Could you road-test it for me? Download it from here.

To do this, download the hook, then add its parent folder as a hook dir using the `--additional-hooks-dir=folder` option. With this hook, you should be able to omit your `--add-data` and remove the copied .ini file without anything breaking. If it works then we can add it to PyInstaller permanently so that no-one ever has to fix this again.

Brénainn
Reply all
Reply to author
Forward
0 new messages