labelImg icon indicating copy to clipboard operation
labelImg copied to clipboard

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

Open shaform opened this issue 7 years ago • 24 comments

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'

  • OS: Ubuntu 16.04
  • PyQt version: PyQt 5 / PyQt4 with Python 3.5

shaform avatar Jun 29 '17 12:06 shaform

You forget to run $ make

tzutalin avatar Jun 29 '17 13:06 tzutalin

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'

shaform avatar Jun 29 '17 14:06 shaform

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.

tzutalin avatar Jun 30 '17 02:06 tzutalin

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

shaform avatar Jun 30 '17 21:06 shaform

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

tungalbert99 avatar Jul 07 '17 05:07 tungalbert99

@tungalbert99

  • I just re-run the travis-ci, and it still fails https://travis-ci.org/shaform/labelImg/builds/248948327. So the PyPI package is still broken.

  • I am able to run labelImg in the repo with system Python 3 with the following modification:

-        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

shaform avatar Jul 07 '17 11:07 shaform

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.

kryvashek avatar Jul 28 '17 12:07 kryvashek

Same issue here with Python 2.7.

lcd047 avatar Aug 27 '17 11:08 lcd047

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

FrankenApps avatar Sep 01 '17 17:09 FrankenApps

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.

shaform avatar Sep 02 '17 00:09 shaform

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

mrgloom avatar Oct 30 '17 12:10 mrgloom

Same issue on ubuntu 17.04 with python 3.6

kindlychung avatar Nov 06 '17 15:11 kindlychung

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

a258sa258s avatar Mar 09 '18 16:03 a258sa258s

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

  • pip => pyqt4 not found (I installed pyqt5)
  • real installation => RuntimeError: the PyQt4.QtCore and PyQt5.QtCore modules both wrap the QObject class

metal3d avatar Mar 11 '18 23:03 metal3d

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'

renweizhukov avatar Apr 02 '18 23:04 renweizhukov

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.

vitusTreatise avatar Apr 07 '18 15:04 vitusTreatise

@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.

azmathmoosa avatar Apr 10 '18 11:04 azmathmoosa

@azmathmoosa

I have the same issue. Indeed can someone reopen?

benediktbrandt avatar May 18 '18 01:05 benediktbrandt

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.

ludwigprager avatar Jun 17 '18 20:06 ludwigprager

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

reiinakano avatar Aug 04 '18 06:08 reiinakano

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

ronalddas avatar Aug 08 '18 15:08 ronalddas

@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.

vitusTreatise avatar Aug 08 '18 16:08 vitusTreatise

@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.

juliusHuelsmann avatar Aug 13 '18 19:08 juliusHuelsmann

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

pglen avatar Dec 02 '19 21:12 pglen