Search code examples
iospython-3.xapplescriptappkit

Appkit Working properly inside venv but not without using virtual env


I have installed PyObjC for using AppKit library in my virtual env I can able to import Appkit inside pytthon3 venv

I have tried installing the pyobjc using pip3 outside venv and installed successfully but when I try to import Appkit outside venv there it shows the import error for AppKit

This is outside venv

XXX_XXX_XXX:~ dreams$ python3.

Python 3.7.6 (v3.7.6:43364a7ae0, Dec 18 2019, 14:18:50)

[Clang 6.0 (clang-600.0.57)] on darwin

Type "help", "copyright", "credits" or "license" for more information.

import AppKit

Traceback (most recent call last):

File "", line 1, in

ModuleNotFoundError: No module named 'AppKit'

Inside venv

XXX_XXX_XX:~ dreamguys$ source activeWindowEnv/bin/activate

(activeWindowEnv) XXX_XXX_XX:~ dreams$ python

Python 3.7.6 (v3.7.6:43364a7ae0, Dec 18 2019, 14:18:50)

[Clang 6.0 (clang-600.0.57)] on darwin

Type "help", "copyright", "credits" or "license" for more information.

import AppKit


Solution

  • There is a package named appkit in pip3 which has no relation to the AppKit in apple. So please check the package you need to install before importing the AppKit module.

    AppKit module provides you with the objective C classes of the apple mac system, from which we can able to get the current active window.

    In my venv there is no problem because I have installed pyObjC only for getting the AppKit import. but in main env I have mistakenly installed the appkit library, thats where the problem arised

    Coming back to my problem, I have uninstalled both appkit and pyobjc and reinstalled the same using pip3 and now my imports worked fine. Try reinstalling the pyObjC. It will solve the problem