minecraftplayer1234
minecraftplayer1234

Reputation: 2227

Importing own Python package from git

I have the following python package created by myself:

C:.
│   .gitignore
│   MANIFEST
│   setup.py
│
├───.vscode
│   │   settings.json
│   │
│   └───.ropeproject
│           config.py
│           objectdb
│
├───calendarlib
│   │   __init__.py
│   │
│   ├───cal
│   │   │   cal.py
│   │   │   event.py
│   │   │   __init__.py
│   │   │
│   │   └───__pycache__
│   │           cal.cpython-36.pyc
│   │           calendar.cpython-36.pyc
│   │           event.cpython-36.pyc
│   │           __init__.cpython-36.pyc
│   │
│   ├───database
│   │   │   db.py
│   │   │   __init__.py
│   │   │
│   │   └───__pycache__
│   │           db.cpython-36.pyc
│   │           __init__.cpython-36.pyc
│   │
│   └───ui
│           window.py
│           __init__.py
│
├───calendarlib.egg-info
│       dependency_links.txt
│       PKG-INFO
│       SOURCES.txt
│       top_level.txt
│
└───dist
        calendarlib-0.1.tar.gz
        calendarlib-0.2.tar.gz

__init__s are empty. Now when I use this code like with creating main.py here and importing stuff, it works. But when I push it to my git repo, install it with: pip install -U git+https://github.com/frynio/calendarlib (it is present in site-packages in Python installation dir) and do something like this:

import sys
from calendarlib.ui import window

if __name__ == '__main__':
    app = window.QApplication(sys.argv)
    foo = window.CalendarWindow()
    foo.show()
    sys.exit(app.exec_())

It says:

Traceback (most recent call last):
  File "main.py", line 2, in <module>
    from calendarlib.ui import window
  File "C:\Python36\lib\site-packages\calendarlib\ui\window.py", line 4, in <module>
    from database import db
ModuleNotFoundError: No module named 'database'

The code is in here.

What can I do? Should I import it somehow different in my app, or should I change imports in calendarlib itself?

Upvotes: 0

Views: 129

Answers (1)

Solo
Solo

Reputation: 389

The import should be relative to the package. from calendarlib.database import db instead of from database import db

From looking at the github repo it looks like the line is correct there... Maybe you should re-install with pip?

Upvotes: 1

Related Questions