Search code examples
djangopython-2.7importpippython-module

Local python module overrides module installed with pip


I am having issues with importing, my own, pip package named the same as a module inside a django-app. Lets say my own pip module is called: fancymodule. I then have a module-folder inside a django-app named the same:

* django-project
    * payments
        * models.py
        * fancymodule/
            * __init__.py

The problem I am having, is that inside payments/models.py, I import:

from fancymodule import ApiClient

This is suppose to reference the fancymodule installed through pip. But is instead referencing the module inside the payments-django-app instead.

If I wanted to reference the module inside the payments-django-app, in my head, this should be:

from payments.fancymodule import whatever

I get that from the view of payments/models.py, the import fancymodule .. will reference fancymodule inside the payments-folder.. but can i change/fix this, so it reference the fancymodule installed through pip ?

FYI: Working on an old legacy project.

Home someone can help.


Solution

  • marcinn suggestion about using from __future__ import absolute_import worked.

    So my solution inside the models.py file ended up being:

    from __future__ import absolute_import
    from fancymodule import ApiClient
    

    And as I said to above comment.. I couldn't find anything wrong with my PYTHONPATH. as marcinn also said, this is most likly a Python 3.x thing.. and since i am on 2.7, it makes sense the PYTHONPATH looks fine.

    OBS: PyCharm redlines the from fancymodule import ApiClient, but it works. So i think its just PyCharm that needs to be restartet to remove the redlines.