Python Forum
Keyboard Maestro has problem importing python scripts
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Keyboard Maestro has problem importing python scripts
#1
I'm trying to run my python scripts with the click of one button. i'm tired of hunting for my terminal, activating it, then inputting an alias. so i've looked around for some things then can run python scripts on a mac with the click of one button. i've decided to go with keyboard maestro since i've had some very moderate success with it. in any case, when it runs my scripts it has trouble importing all of my modules.

I can run simple python scripts with KM (keyboard maestro) but when I try to run something quite complex it breaks down. KM cannot import certain modules. So I call one module which uses xlwings. When KM tries to import xlwings it has trouble importing the modules that xlwings imports. Look at this

from main import *
File "/Users/kylefoley/PycharmProjects/inference_engine2/inference2/proofs/other/activities/main.py", line 6, in 
import xlwings
File "/library/frameworks/python.framework/versions/3.6/lib/python3.6/site-packages/xlwings/init.py", line 25, in 
from . import _xlmac as xlplatform
File "/library/frameworks/python.framework/versions/3.6/lib/python3.6/site-packages/xlwings/_xlmac.py", line 10, in 
import aem
ModuleNotFoundError: No module named 'aem'
So you can see that it successfully executes

from main import *
which is my code. Then it imports xlwings. After that it goes into another module which is not my code. This is where things start to go wrong. It executes line 25 of in the xlwings module but then it cannot execute line 10 of the xlmac.py module. Really at a loss here.
Reply
#2
please always post errors (entire thing, without modification) it will usually immediately point to the error.
For any modules that are missing, from command line, run:
# To make sure it's the right pip:
[python]pip -V
# if not, try:
pip3 -V
#whichever one is associated with the right version of python is the one to use, then:

pip install package name
[/python]
Reply
#3
The program runs from command line but not from keyboard maestro. I have the module it's just that KM is not finding it.

Let me post the entire error message

2018-08-29 11:51:06 Traceback (most recent call last):
  File "/Users/kylefoley/PycharmProjects/inference_engine2/inference2/Proofs/other/activities/bd.py", line 3, in <module>
    from main import *
  File "/Users/kylefoley/PycharmProjects/inference_engine2/inference2/proofs/other/activities/main.py", line 6, in <module>
    import xlwings
  File "/library/frameworks/python.framework/versions/3.6/lib/python3.6/site-packages/xlwings/__init__.py", line 25, in <module>
    from . import _xlmac as xlplatform
  File "/library/frameworks/python.framework/versions/3.6/lib/python3.6/site-packages/xlwings/_xlmac.py", line 10, in <module>
    import aem
ModuleNotFoundError: No module named 'aem'
 Macro “Execute a Shell Script” cancelled (while executing Execute Shell Script).
Once again, the line

import aem
Works perfectly fine when using command line or PyCharm but not when the program is run from Keyboard Maestro.
Reply
#4
Ok, I've made a little bit of progress. I encounter versions of this error when I use terminal and I solve it by doing this:

import sys
str1 = "/library/frameworks/python.framework/versions/3.6/lib/python3.6/site-packages/"
sys.path.append(str1)
When I remove that code I get the following error:

Traceback (most recent call last):
  File "/Users/kylefoley/PycharmProjects/inference_engine2/inference2/Proofs/other/activities/main.py", line 6, in <module>
    import xlwings
ModuleNotFoundError: No module named 'xlwings'
So I'm on the right track. I just need to find out what path to append to sys so that I do not get this error:

Traceback (most recent call last):
  File "/Users/kylefoley/PycharmProjects/inference_engine2/inference2/Proofs/other/activities/main.py", line 6, in <module>
    import xlwings
  File "/library/frameworks/python.framework/versions/3.6/lib/python3.6/site-packages/xlwings/__init__.py", line 25, in <module>
    from . import _xlmac as xlplatform
  File "/library/frameworks/python.framework/versions/3.6/lib/python3.6/site-packages/xlwings/_xlmac.py", line 10, in <module>
    import aem
ModuleNotFoundError: No module named 'aem'
So after I found the module 'aem' I put in the following code:

str1 = "/library/frameworks/python.framework/versions/3.6/lib/python3.6/site-packages/aeosa/aem/"
sys.path.append(str1)
That didn't work however. I'm getting the same error message.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Trying to us python.exe from our network to run scripts cubangt 3 827 Aug-17-2023, 07:53 PM
Last Post: deanhystad
  python standard way of importing library mg24 1 872 Nov-15-2022, 01:41 AM
Last Post: deanhystad
  Problem with importing python-telegram library into the project gandonio 1 1,516 Nov-01-2022, 02:19 AM
Last Post: deanhystad
  Problem with importing Python file in Visual Studio Code DXav 7 4,936 Jun-15-2022, 12:54 PM
Last Post: snippsat
  keyboard module; must be root problem philipbergwerf 2 18,807 Apr-04-2021, 11:40 AM
Last Post: philipbergwerf
  Running python scripts from github etc pacmyc 7 3,609 Mar-03-2021, 10:26 PM
Last Post: pacmyc
  keyboard module doesn't work in the microsoft version terminal of python. username 1 2,748 Feb-25-2021, 05:19 PM
Last Post: Larz60+
  Reading SQL scripts from excel file and run it using python saravanatn 2 2,460 Aug-23-2020, 04:49 PM
Last Post: saravanatn
  importing a list of numbers into python script barrypyth 8 4,436 Aug-22-2020, 09:10 PM
Last Post: barrypyth
  Importing python data to Textfile or CSV yanDvator 0 1,720 Aug-02-2020, 06:58 AM
Last Post: yanDvator

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020