Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running .App (made primarily in opencv-python i.e. cv2) in terminal gives Symbol Not Found: _iconv error #349

Closed
adityashukzy opened this issue May 2, 2021 · 2 comments

Comments

@adityashukzy
Copy link

My issue is that py2app setup.py line does everything perfectly and it shows Done! at the end, but when I run the .app it gives the open console/terminate popup. So I run the executable in the terminal to see what errors it throws up. These are the errors.

File "/Users/adityashukla/Documents/GitHub/Maks/dist/Maks.app/Contents/Resources/maks_app.py", line 2, in <module>
    import cv2
  File "/Users/adityashukla/Documents/GitHub/Maks/dist/Maks.app/Contents/Resources/lib/python3.7/cv2/__init__.py", line 3, in <module>
    from .cv2 import *
ImportError: dlopen(/Users/adityashukla/Documents/GitHub/Maks/dist/Maks.app/Contents/Resources/lib/python3.7/cv2/cv2.cpython-37m-darwin.so, 2): Symbol not found: _iconv
  Referenced from: /Users/adityashukla/Documents/GitHub/Maks/dist/Maks.app/Contents/Resources/lib/python3.7/cv2/.dylibs/libavcodec.58.35.100.dylib
  Expected in: /Users/adityashukla/Documents/GitHub/Maks/dist/Maks.app/Contents/MacOS/../Frameworks/libiconv.2.dylib
 in /Users/adityashukla/Documents/GitHub/Maks/dist/Maks.app/Contents/Resources/lib/python3.7/cv2/.dylibs/libavcodec.58.35.100.dylib
2021-05-01 19:46:31.196 Maks[5531:155509] Maks Error

I've seen other people post a similar error on some other issues (which don't seem to have been answered). The error basically has something to do with OpenCV and that dylib file but I can't figure out how to solve this.

For reference, here is my setup.py file. I originally had opencv-python as 4.x.x. something and then I tried downgrading that to 3.4.5.20 (which was suggested on a StackOverflow thread) which threw up the same error stuff.

from setuptools import setup
import sys
sys.setrecursionlimit(20000)
APP = ['maks_app.py']
DATA_FILES = ['violator.wav', 'non_violator.wav', 'facemask-model']
OPTIONS = {
	'argv_emulation': True, 
	'site_packages': True,
	'iconfile': 'maks-icon.icns',
	'packages': ['cv2', 'keras', 'numpy', 'PIL', 'tensorflow', 'mongo_upload'],
	'plist': {
		'CFBundleName': 'Maks',
	}
}

Maks is the name of my app, it does face-mask detection and I'm using opencv, keras, tensorflow, numpy, PIL and another code file I wrote called mongo_upload which has a function for me to be able to talk to a MongoDB cluster.

I also had a question that since I'm loading a folder that has machine learning weights inside of it, will I include that folder name or not in my data_files list? And if not, then how do I tell my py2app to include that folder in the bundle too (since the app will load those weights)?

ronaldoussoren added a commit that referenced this issue Aug 29, 2021
@ronaldoussoren
Copy link
Owner

To work my way up from the end:

  • Using a folder in datafiles with copy that entire folder in the Resources folder of the app bundle. That folder will also be the working directory of the app.
  • In general you shouldn't have to use the packages option, py2app should automatically do the right thing here (and if it doesn't for packages on PyPI I'd like to know). In this case the addition of numpy is needed because opencv imports it in C code (which py2app cannot inspect).
  • You can use ``setup(name="Maks", ...)``` to set the application name instead of using the plist option

The error you get with opencv2 indicates that py2app hasn't copied everything needed. I'm not sure what's going on here as I haven't been able to reproduce the issue.

I'm on an M1 system using python3.9 (universal2 build)

  • pip install opencv-python installs a copy of the cv2 extension with a hard dependency on homebrew, couldn't test
  • arch -x86_64 pip install opencv-python install a copy of cv2 that works for me (arch -x86_64 python setup.py py2app --arch=x86_64 )

Installed are:

numpy         1.21.2
opencv-python 4.5.3.56

I tested this with a small script that just imports cv2 and numpy (the latter because of the hidden dependency in the cv2 extension).

I've added a recipe for opencv to automatically include numpy when an import of cv2 is detected.

Question: How did you install opencv?

@ronaldoussoren
Copy link
Owner

There is not enough information in the first message to investigate further. I'm hoping that the cv2 recipe is good enough...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants