HumanSignal / labelImg

LabelImg is now part of the Label Studio community. The popular image annotation tool created by Tzutalin is no longer actively being developed, but you can check out Label Studio, the open source data labeling tool for images, text, hypertext, audio, video and time-series data.
https://youtu.be/p0nR2YsCY_U
MIT License
22.76k stars 6.3k forks source link

ImportError: No module named 'resources' when installed by pip with Python 3.5 #106

Open shaform opened 7 years ago

shaform commented 7 years ago

On Ubuntu 16.04, do:

$ sudo apt install python3-pyqt5  # replace it with python3-pyqt4 produces the same exception
$ python3 -m venv --system-site-packages env
$ source env/bin/activate
$ pip install -U pip
$ pip install labelImg
$ labelImg

get:

Traceback (most recent call last):
  File "/home/$USER/env/bin/labelImg", line 9, in <module>
    load_entry_point('labelImg==1.3.3', 'console_scripts', 'labelImg')()
  File "/home/$USER/env/lib/python3.5/site-packages/pkg_resources/__init__.py", line 542, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/home/$USER/env/lib/python3.5/site-packages/pkg_resources/__init__.py", line 2569, in load_entry_point
    return ep.load()
  File "/home/$USER/env/lib/python3.5/site-packages/pkg_resources/__init__.py", line 2229, in load
    return self.resolve()
  File "/home/$USER/env/lib/python3.5/site-packages/pkg_resources/__init__.py", line 2235, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "/home/$USER/env/lib/python3.5/site-packages/labelImg/labelImg.py", line 27, in <module>
    import resources
ImportError: No module named 'resources'
tzutalin commented 7 years ago

You forget to run $ make

shaform commented 7 years ago

But Makefile would not be installed by pip. If I run $ make, the following message appears:

make: *** No targets specified and no makefile found.  Stop.

Interestingly, the resources.py file does exist.

$ ls env/lib/python3.5/site-packages/labelImg/resources.py 
env/lib/python3.5/site-packages/labelImg/resources.py

If I install pyqt4 and manually import

>>> from labelImg import resources
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/$USER/env/lib/python3.5/site-packages/labelImg/resources.py", line 6316, in <module>
    qInitResources()
  File "/home/$USER/env/lib/python3.5/site-packages/labelImg/resources.py", line 6311, in qInitResources
    QtCore.qRegisterResourceData(0x01, qt_resource_struct, qt_resource_name, qt_resource_data)
TypeError: qRegisterResourceData(int, str, str, str): argument 2 has unexpected type 'str'

If I install pyqt4 and sip, we get segmentation fault.

$ labelImg
Segmentation fault (core dumped)
>>> from labelImg import resources
Segmentation fault (core dumped)

If I install pyqt5 and manually import

>>> from labelImg import resources
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/$USER/env/lib/python3.5/site-packages/labelImg/resources.py", line 10, in <module>
    from PyQt4 import QtCore
ImportError: No module named 'PyQt4'
tzutalin commented 7 years ago

Hi @shaform , I think you can refer to the travis file to know the build and test env.

Otherwise, you can try to use docker or pip install it directly.

shaform commented 7 years ago

Hi @tzutalin,

Thank you. This is really helpful. Now I am able to reproduce my issue on Travis CI when using pip install. Please see https://travis-ci.org/shaform/labelImg/builds/248948327

Basically, I have modified the travis file to test against the labelImg package installed by pip instead of the one inside the repo, which shows us that the package uploaded to PyPI is potentially corrupted.

See diff: https://github.com/shaform/labelImg/commit/44a8c4a1116561a3c028c28ee8a60e4bb82381a7

tungalbert99 commented 7 years ago

Sorry! I was having this issue too. @shaform did you just end up installing directly from the repo or did @tzutalin reupload the PyPI?

shaform commented 7 years ago

@tungalbert99

-        self.recentFiles = list(settings.get('recentFiles', []))
+        self.recentFiles = list(settings.get('recentFiles') or [])

The command I used was:

$ sudo apt install python3-lxml pyqt5-dev-tools cmake
$ make qt5py3
$ python3 labelImg.py
kryvashek commented 7 years ago

Excuse me, is there are any corrections performed due to this issue? (I could miss, that`s why I`m asking). I`ve met the same problem despite of current issue being closed and I`d rather prefer to install labelImg from PyPl package than from sources.

lcd047 commented 7 years ago

Same issue here with Python 2.7.

FrankenApps commented 7 years ago

Why is this closed? I have the same issue with Python 3.6 on Ubuntu 16.04...

shaform commented 7 years ago

I can confirm the build still fails, as shown here: https://travis-ci.org/shaform/labelImg/builds/248948327. However, one could still build the package by herself rather than installing it from PyPI.

mrgloom commented 7 years ago

Same issue under Windows 7 and Python 3.6.1 |Anaconda 4.4.0 (64-bit)

kindlychung commented 7 years ago

Same issue on ubuntu 17.04 with python 3.6

a258sa258s commented 6 years ago

一樣的問題 大概只能從原始碼安裝了

metal3d commented 6 years ago

Same here, pip install and fails. I never see labelimg working with several methods:

renweizhukov commented 6 years ago

Tried on Ubuntu 16.04LTS: pip install worked but labelImg returned the same error.

$ pip install labelImg
Collecting labelImg
  Downloading labelImg-1.6.0.tar.gz (373kB)
    100% |████████████████████████████████| 378kB 1.1MB/s 
Building wheels for collected packages: labelImg
  Running setup.py bdist_wheel for labelImg ... done
  Stored in directory: /home/renwei/.cache/pip/wheels/b3/86/f3/517dffac32aeb789e2378b4aaba7b03f088b18ff166928f651
Successfully built labelImg
Installing collected packages: labelImg
Successfully installed labelImg-1.6.0
$ labelImg
Traceback (most recent call last):
  File "/home/renwei/anaconda3/envs/ml/bin/labelImg", line 7, in <module>
    from labelImg.labelImg import main
  File "/home/renwei/anaconda3/envs/ml/lib/python3.6/site-packages/labelImg/labelImg.py", line 27, in <module>
    import resources
ModuleNotFoundError: No module named 'resources'
vitusTreatise commented 6 years ago

If these issues haven't already been resolved, these were my changes to get the pip-installed version of labelImg to work (at least start) - python 3.5 running a virtualenv with other pre-reqs installed.

  1. site-packages/labelImg/labelImg.py change line 27 "import resources" to "from labelImg import resources"

  2. site-packages/labelImg/resources.py change line 12: qt_resource_data = "\ to qt_resource_data = b"\

Same for lines 6596 qt_resource_name = b"\ , and 6711, qt_resource_struct = b"\

Fires right up, but haven't really tested functionality yet.

azmathmoosa commented 6 years ago

@vitusTreatise

I followed your advice and got another error

Traceback (most recent call last): File "/usr/local/bin/labelImg", line 9, in load_entry_point('labelImg==1.6.0', 'console_scripts', 'labelImg')() File "/usr/lib/python3/dist-packages/pkg_resources/init.py", line 542, in load_entry_point return get_distribution(dist).load_entry_point(group, name) File "/usr/lib/python3/dist-packages/pkg_resources/init.py", line 2569, in load_entry_point return ep.load() File "/usr/lib/python3/dist-packages/pkg_resources/init.py", line 2229, in load return self.resolve() File "/usr/lib/python3/dist-packages/pkg_resources/init.py", line 2235, in resolve module = import(self.module_name, fromlist=['name'], level=0) File "/usr/local/lib/python3.5/dist-packages/labelImg/labelImg.py", line 27, in from labelImg import resources File "/usr/local/lib/python3.5/dist-packages/labelImg/resources.py", line 10, in from PyQt4 import QtCore ImportError: No module named 'PyQt4'

Installed pyqt4 sudo apt-get install python-qt4

Still no luck! The prebuilt binaries don't work, neither does pip installer but this issue is "closed". Can someone open this please.

benediktbrandt commented 6 years ago

@azmathmoosa

I have the same issue. Indeed can someone reopen?

ludwigprager commented 6 years ago

I also experienced the issue "No module named 'resources'". I could solve it with separate calls to 'pip3 install' . See my Dockerfile or try the docker container if you work on linux.

reiinakano commented 6 years ago

@vitusTreatise solution works for me. Again, I haven't tested all functionality yet. @vitusTreatise have you confirmed it all works fine?

ronalddas commented 6 years ago

Hi, I have the same issue on Ubuntu 18.04 and Python 3.6.5, I installed it using pip, but the same error

no module named resources

vitusTreatise commented 6 years ago

@reiinakano - yes, worked fine in the context of what I was trying to accomplish, which was to learn something about tensorflow. Was following along with this tutorial:

https://www.youtube.com/watch?v=K_mFnvzyLvc

Did what was required after above modifications.

juliusHuelsmann commented 6 years ago

@azmathmoosa @benediktbrandt afaik the debian python-qt4 package is for python2. You are trying to use python3 though. If you don't want to stick with qt4 you could for instance use for instance pyqt5-dev-tools via apt. For qt4 i think libqt4-dev should work, too.

pglen commented 4 years ago

I fell for it too. Perhaps wrapping the resources import into a try / except construct, and printing something like: "run make before starting labelimg" THX