Skip to content

How to use this when I package all into a package and installed in local virtual env? #18

Open

Description

@iScheme4U

This utility works fine when I am using it in development env, but when I package my project and install to my local virtual env, it will complain following:

ImportError: cannot import name 'config' from 'config2.config'.

Looks like it cannot find the configuration files, how can I solve this problem?

Thanks

Activity

  1. bjoluc commented on Jan 27, 2021

    @bjoluc

    Hi there,
    to me, it looks like config2 is not installed along with your package. Do you define it as a requirement in your setup.py? If you'd like to get rid of the manual setup.py stuff, I can highly recommend Poetry for packaging. You could just poetry add config2 then and it should work (if the problem is not config2-related).

    One problem in this regard is #17, so bear in mind that, by adding config2 as a dependency, your package also depends on lots of development dependencies of it, unfortunately. If you find any other config2-oddities (like I did), you may check out appcfg which takes a similar, slightly less magical, but more stable approach (and has 100% test coverage). I made this to overcome the shortcomings of config2 (which seems to be stale).

    EDIT: The devel's in detail; misread the ImportError, sorry! I guess you are right with your assumption, and I also guess this is due to the stack inspection magic in config2. I was experiencing something similar a year or so ago. Should work with appcfg!

  2. iScheme4U commented on Jan 29, 2021

    @iScheme4U
    Author

    Hi there,
    I double checked that i have included the library in my setup, like I said, it works fine in development, but it will complain the fore mentioned error.
    Looks like it cannot find the configuration files, so it cannot create the config object, so ImportError occurred.

  3. bjoluc commented on Jan 29, 2021

    @bjoluc

    I remember I had a related problem about a year ago. It seemed to me like the stack inspection would fail to retrieve the proper config path. Maybe it was also related to rootpath not finding the right directory. Another related problem that I had with config2 was that it would not work if applied in multiple packages at the same time. I solved these issues in appcfg by explicitly passing __name__, and then just using the builtin importlib utils to infer the path. This also enables other packages (such as tests) to retrieve the configuration of a specific package via the package name. I generally prefer explicit over implicit in those cases (why should we try to infer information that is already available via __name__).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions