Yaroslav Kishchenko
Yaroslav Kishchenko

Reputation: 483

Python package names collision

I have a following project structure:

program_name/
    __init__.py
    __main__.py
    package_name/
        __init__.py
        some_module.py

when I run python program_name from top level directory I get an error. It appears, that some of mine dependencies import the package with the same name as mine. Namely I import numpy in __main__.py and, somewhere deep inside, it has import package_name line. So instead of importing its dependency it import my package.

Can I solve it, without renaming my package? I can understand name collision with third party packages you use directly in your project. But here I have a name collision with some of the dependencies.

Upvotes: 0

Views: 711

Answers (1)

Zompa
Zompa

Reputation: 468

If you inspect sys.path, you can know the search order used by your application.

You can modify the order befor import the incriminated library and after make an explicit import to reach your library.

In my opinion it is better change your package name.

Upvotes: 2

Related Questions