TikZ-Editor icon indicating copy to clipboard operation
TikZ-Editor copied to clipboard

cannot import name 'factory'

Open siefkenj opened this issue 6 years ago • 18 comments

I get the following error when trying to execute tikz_editor.pyw

Traceback (most recent call last):
  File "./tikz_editor.pyw", line 18, in <module>
    import tikz_editor
  File "/home/albert/programming/latexwatch/TikZ-Editor/tikz_editor/__init__.py", line 20, in <module>
    from tikz_editor.controllers import ControllerFactory
  File "/home/albert/programming/latexwatch/TikZ-Editor/tikz_editor/controllers/__init__.py", line 16, in <module>
    from .factory import ControllerFactory
  File "/home/albert/programming/latexwatch/TikZ-Editor/tikz_editor/controllers/factory.py", line 19, in <module>
    from .documents import DocumentsController
  File "/home/albert/programming/latexwatch/TikZ-Editor/tikz_editor/controllers/documents.py", line 17, in <module>
    from . import factory
ImportError: cannot import name 'factory'

I get the same error when running setup.py install

siefkenj avatar Nov 08 '17 04:11 siefkenj

I'll check that... maybe it's because I switched the master branch to py3/qt5 ? The py2/qt4 version is maintained in branch https://github.com/fredokun/TikZ-Editor/tree/py2qt4 (corresponding to PR #8). In the meantime I investigate the problem.

fredokun avatar Nov 08 '17 09:11 fredokun

Yeah ... I think it's a python2 vs. python3 issue, can you confirm ?

fredokun avatar Nov 08 '17 09:11 fredokun

I can confirm. The py2qt4 branch works on my system.

siefkenj avatar Nov 08 '17 15:11 siefkenj

ok, sorry for the sudden (unadvertised) change

fredokun avatar Nov 08 '17 15:11 fredokun

@fredokun they py2qt4 branch works with python2 on my system, but the master branch does not work with python3 or python2. I am confused why you closed the issue.

siefkenj avatar Nov 08 '17 15:11 siefkenj

I tried with python3 qt5 and it worked... I think it's also an issue with qt5 not installed or for python2? I'll reopen if it's something else...

Le 8 nov. 2017 4:33 PM, "Jason Siefken" [email protected] a écrit :

@fredokun https://github.com/fredokun they py2qt4 branch works with python2 on my system, but the master branch does not work with python3 or python2. I am confused why you closed the issue.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/fredokun/TikZ-Editor/issues/9#issuecomment-342854241, or mute the thread https://github.com/notifications/unsubscribe-auth/ABDadDYeYvntOhTydp41RHdwSbHyaC1yks5s0cnXgaJpZM4QV01N .

fredokun avatar Nov 08 '17 15:11 fredokun

I am able to run the example here: http://zetcode.com/gui/pyqt5/firstprograms/ with both python2 and python3, which makes me think pyqt5 is installed correctly for both versions of python. Both python2 and python3 have the same error wiht TikZ-Editor.

albert@turbo ~/programming/latexwatch/TikZ-Editor $ python3 tikz_editor.pyw 
Traceback (most recent call last):
  File "tikz_editor.pyw", line 18, in <module>
    import tikz_editor
  File "/home/albert/programming/latexwatch/TikZ-Editor/tikz_editor/__init__.py", line 20, in <module>
    from tikz_editor.controllers import ControllerFactory
  File "/home/albert/programming/latexwatch/TikZ-Editor/tikz_editor/controllers/__init__.py", line 16, in <module>
    from .factory import ControllerFactory
  File "/home/albert/programming/latexwatch/TikZ-Editor/tikz_editor/controllers/factory.py", line 19, in <module>
    from .documents import DocumentsController
  File "/home/albert/programming/latexwatch/TikZ-Editor/tikz_editor/controllers/documents.py", line 17, in <module>
    from . import factory
ImportError: cannot import name 'factory'
albert@turbo ~/programming/latexwatch/TikZ-Editor $ python2 tikz_editor.pyw 
Traceback (most recent call last):
  File "tikz_editor.pyw", line 18, in <module>
    import tikz_editor
  File "/home/albert/programming/latexwatch/TikZ-Editor/tikz_editor/__init__.py", line 20, in <module>
    from tikz_editor.controllers import ControllerFactory
  File "/home/albert/programming/latexwatch/TikZ-Editor/tikz_editor/controllers/__init__.py", line 16, in <module>
    from .factory import ControllerFactory
  File "/home/albert/programming/latexwatch/TikZ-Editor/tikz_editor/controllers/factory.py", line 19, in <module>
    from .documents import DocumentsController
  File "/home/albert/programming/latexwatch/TikZ-Editor/tikz_editor/controllers/documents.py", line 17, in <module>
    from . import factory
ImportError: cannot import name factory

siefkenj avatar Nov 08 '17 15:11 siefkenj

I do not have access to a mac (for now) but I'll investigate this, I reopen the issue.

fredokun avatar Nov 08 '17 15:11 fredokun

(I tried on linux and it works)

fredokun avatar Nov 08 '17 15:11 fredokun

but it seems you're on a unix box also ?

fredokun avatar Nov 08 '17 15:11 fredokun

I am on linux (gentoo). Let me know if there are other tests you'd like me to run.

siefkenj avatar Nov 08 '17 15:11 siefkenj

what is your version of python 3 ?

fredokun avatar Nov 08 '17 15:11 fredokun

Python 3.4.5 Python 2.7.12

siefkenj avatar Nov 08 '17 16:11 siefkenj

I also have PyQt5 version 5.7.1. I have gotten the code to run by doing the following:

  1. I moved the from . import factory from the beginning of controllers/documents.py to the def _createDocument method. I'm not sure when _createDocument is called, so maybe the issue still exists and just isn't triggered, or maybe this fixed it...
  2. After I did that there was a new problem with the preferences. They were all being returned as strings instead of bools/ints, etc. I manually hacked the 10 calls to preferences that were failing, adding things like True if value == 'true' else False. This makes me suspicious that a different version of PyQt5 automatically converts these types to python types? If so, the laziest fix would be to put a minimum version of PyQt5 required. Otherwise, it would be reasonable to do type coercion in preferences.py.

siefkenj avatar Nov 08 '17 16:11 siefkenj

This appears relevant: http://pyqt.sourceforge.net/Docs/PyQt5/pyqt_qsettings.html

siefkenj avatar Nov 08 '17 17:11 siefkenj

@siefkenj I ported it to Qt5 using the currently latest version: QT 5.9. and python 3.6. But yes, I didn't test it with lower version. Hope that helps.

MartinNowack avatar Nov 11 '17 16:11 MartinNowack

I made a PR #10 to address the issue.

siefkenj avatar Nov 11 '17 17:11 siefkenj

merged, thanks !

fredokun avatar Nov 13 '17 09:11 fredokun