Erik
Erik

Reputation: 3198

do I have a circular import in python

I'm trying to port over a python project from v2.x, to v3.x

one of the major changes to python was the import system.

I am now seeing an error when trying to load my python notebook as follows

package/
    __init__.py
    bh_tsne.py

Collect Samples.ipynb //imports utils.list_all_files, sees error

Error Output

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-2-1339232cd15c> in <module>()
      1 import numpy as np
      2 from os.path import join
----> 3 from utils.list_all_files import list_all_files
      4 from multiprocessing import Pool

/~/AudioNotebooks/utils/__init__.py in <module>()
      4 from . import show_array
      5 from . import make_mosaic
----> 6 from . import bh_tsne
      7 from . import normalize
      8 from . import mkdir_p

ImportError: cannot import name 'bh_tsne'

strangely.. I think the problem is a circular dependence.. but bh_tsne doesn't rely on any utilities.. could the circularity be coming from my utils.list_all_files and then the __init__.py ?

bh_tsne imports

from argparse import ArgumentParser, FileType
from os.path import abspath, dirname, isfile, join as path_join
from shutil import rmtree
from struct import calcsize, pack, unpack
from subprocess import Popen
from sys import stderr, stdin, stdout
from tempfile import mkdtemp
from platform import system
from os import devnull
import numpy as np
import os, sys 
import io

Edit

Is that redundant os.path join perhaps the root cause?

Upvotes: 0

Views: 145

Answers (2)

Erik
Erik

Reputation: 3198

I ended up just upgrading the wrapper that was used in one project from it's source upstream project. The original owner had done upgrades.

https://github.com/lvdmaaten/bhtsne/blob/master/bhtsne.py

and the import worked after that as

import utils.bhtsne as bhtsne

Upvotes: 1

Victor Silva
Victor Silva

Reputation: 326

I found out that bh_tsne seems NOT to work with python 3. Also another version (Multicore TSNE) just work with python 2.7 as well

Upvotes: 0

Related Questions