1

I'm getting this error:

ImportError: cannot import name 'SUTime' from partially initialized module 'sutime' (most likely due to a circular import)

when importing the sutime module as:

from sutime import SUTime

as suggested in the sutime GitHub example: https://github.com/FraBle/python-sutime

Context: sutime is a Python library for parsing date/time from a natural language input, developed by the amazing team over at Stanford CoreNLP.

Note: I've already run the pre-req installs as well:

>> pip install setuptools_scm jpype1 # install pre-reqs
>> pip install sutime
>> # use package pom.xml to install all Java dependencies via Maven into ./jars
>> mvn dependency:copy-dependencies -DoutputDirectory=./jars
Hojung Kim
  • 143
  • 1
  • 2
  • 13

2 Answers2

1

It's not true that a circular import is the most likely cause of your error. A failed, incomplete, or in some way strange installation is more likely. Try this:

pip uninstall sutime
pip uninstall jpype1
pip uninstall setuptools_scm
pip3 install setuptools_scm jpype1  # note: pip3
pip3 install sutime

Then, in the python-sutime directory, enter this command:

./test.sh

It should output lots of log lines, and the last line but one should be similar to this:

======================== 5 passed, 2 warnings in 13.06s ========================

In the same directory you can enter and run the Python script from the Example section of the README. It should output many log lines before the reported output. There may be a way to avoid that, but anyway it happens only once, when the script starts.

Walter Tross
  • 12,237
  • 2
  • 40
  • 64
  • I've gone through those steps above, but getting the same error :( I entered the command and got this return: `zsh: no such file or directory: ./test.sh` – Hojung Kim Jan 16 '20 at 02:21
  • Ohhhhhhhhh I figured out the problem. I had named my script sutime.py which is definitely the issue. Now, I'm only getting the following error (progress!): `/Library/Frameworks/Python.framework/Versions/3.8/bin/python3: can't open file 'sutime.py': [Errno 2] No such file or directory` – Hojung Kim Jan 16 '20 at 20:13
  • 1
    when you do what, exactly, and in what directory? – Walter Tross Jan 16 '20 at 22:18
  • Running my Python script with from `sutime import SUTime` at the top, from my Desktop (the folder where I've got my script) – Hojung Kim Jan 16 '20 at 22:29
  • try to move (or copy) your script to the checkout directory of the python-sutime project (should be called `python-sutime`), and run it from there – Walter Tross Jan 16 '20 at 22:38
0
  1. Clone the git repo. -

    !git clone https://github.com/FraBle/python-sutime.git

  2. Go to the python-sutime/sutime in the cloned repo. There is a pom.xml file. Open the terminal and issue the following command.

    mvn dependency:copy-dependencies -DoutputDirectory=./jars -P english

  3. Now you can simply import the sutime from the sutime.py script in the cloned repo folder.

  4. If you want to use sutime from anywhere, install sutime using...

    pip install sutime

and replace the /usr/local/lib/python3.6/dist-packages/sutime folder with the sutime folder you get after step 2.

Gihan Gamage
  • 2,944
  • 19
  • 27