0

I have a simple package that I wrote in Python2. I've made the required syntax change for Python3 (namely just the print statements). The structure is as follows:

my_only_module/
    __init__.py
    my_only_module.py

And inside my_only_module.py is:

import requests
import some_other_standard_lib

# basic class gets overwritten
class Basic(object):
    def basic_function():

# advanced1 class inherits Basic class.
class Advanced1(Basic):
    def advanced_function():
        ...

# advanced2 class inherits Basic class.
class Advanced2(Basic):
    def advanced_function(): 
        ... 

__init__.py has:

from my_only_module import *

And this all used to work like this (after installing in Pyhton2.7):

from my_only_module import Advanced1
a_one = Advanced1()

from my_only_module import Advanced2
a_two = Advanced2()

But in Python 3.4, it fails with the following message:

ImportError: cannot import name 'Advanced2'

Any ideas would be appreciated.

Tristan Tao
  • 855
  • 11
  • 29
  • 1
    `from .my_only_module import Advanced2`. Note the leading dot. Implicit relative imports are gone in Python 3. –  May 12 '16 at 22:01
  • That causes a `SystemError: Parent module '' not loaded, cannot perform relative import`. I already read the duplicate post, but didn't feel that it solved my issue. But I'll go back and read it more carefully. I also forgot to include that I already use `setup.py` for installation. – Tristan Tao May 12 '16 at 22:11
  • In *which file* do you have the two failing import statements? You may want to show the *full* traceback. –  May 13 '16 at 04:54
  • So, I was trying to do python __init__.py to make sure that it was working when I was checking... That was the big mistake. In the end I just tried your advice and transferred everything to **.my_only_module** etc in the init files and it all worked out with a full setup (_python setup.py_ install and _pip_). In case you were curious, actual code is [in this github repo](https://github.com/tristantao/py-bing-search/tree/master/py_bing_search). Thanks for the help! – Tristan Tao May 16 '16 at 17:55

0 Answers0