pip install not accessible in shortcut
dragoncoder047 opened this issue · comments
From Apple's point of view, the extension and the app are two different apps, with different downloads and directories. The extension does not have access to what has been installed in the app, the app cannot access the extension main directory. Both have access to a shared directory, which is where the extension runs by default (it's ~shortcuts
or $GROUP
).
To answer your main question: you need to install packages in a place where the extension can access them, ~shortcuts/Library/lib/python3.11/site-packages
.
To do this:
- either copy
~/Library/lib/python3.11
to~shortcuts/Library/lib/python3.11
(pro: fast and easy, con: you might be copying a lot of packages you don't need), or: - set the environment variable
PYTHONUSERBASE
to~shortcuts/Library
, then re-install the packages you need.
When the extension runs, it uses the Python packages in ~shortcuts/Library
.
Ok, seems simple enough. Do you know if it is possible in iOS to make a symlink so I don't have to keep copying files over?
Symlinks won't work over different apps (for security reasons), hard links will work (use ln
instead of ln -s
) but you can only hard link files, not directories. However, if you don't want to keep copying files over, you can set PYTHONUSERBASE
to ~shortcuts/Library
in the app (using the .profile
or .bashrc
files) and have both the app and the extension access the same shared directory.
Symlinks won't work over different apps (for security reasons), hard links will work (use
ln
instead ofln -s
) but you can only hard link files, not directories. However, if you don't want to keep copying files over, you can setPYTHONUSERBASE
to~shortcuts/Library
in the app (using the.profile
or.bashrc
files) and have both the app and the extension access the same shared directory.
Ok, I added export PYTHONUSERBASE= ~shortcuts/Library
to my .profile and restarted a-Shell then reinstalled yt-dlp but now when I run the shortcut it says "problem communicating with the app".
In-extension Shortcuts have a hard time limit of 5 seconds (enforced by the system). "There was a problem communicating with the app" usually means: the Shortcut went over the time limit, and the system terminated it (it could also mean that the shortcut went over the memory limit or the CPU usage limit, but the time limit is much more likely).
You can also run yt-dlp
inside the app, then call the command open shortcuts://
to go back to the shortcut and execute more actions. There are already several shortcuts running yt-dlp
that use this trick.
In-extension Shortcuts have a hard time limit of 5 seconds (enforced by the system). "There was a problem communicating with the app" usually means: the Shortcut went over the time limit, and the system terminated it (it could also mean that the shortcut went over the memory limit or the CPU usage limit, but the time limit is much more likely).
It's not the time limit because I get that error after about half a second.
Also, I can't run the command in the app because I need this shortcut to run as an automation, completely in the background.
@holzschu Setting the python userbase path is not helpful. Many shortcuts need to access different folders at different times, both in extension mode and in app mode in the same shortcut. A more efficient and simple way would be to add to the a-shell shortcuts commands the option to explicitly set the folder where do you want to execute the action or load/save a file. If the folder has not been authorized by the user yet, you can explicitly ask for permissions to the user the first time a certain folder is asked access. Can you do it?
I'm going to punt on this issue: instead of trying to run Python commands in extension, the new version of the app (currently in TestFlight: https://testflight.apple.com/join/REdHww5C ) has the ability to run Shortcuts commands "in the app but in the background", so you can run all the Python commands from the app, completely in the background. That should help.
Running all code in background? That is absolutely great news! What a pity that we cannot install software that uses LLMs like OpenAI, that would have made a-Shell a powerhouse!
I'm going to punt on this issue: instead of trying to run Python commands in extension, the new version of the app (currently in TestFlight: https://testflight.apple.com/join/REdHww5C ) has the ability to run Shortcuts commands "in the app but in the background", so you can run all the Python commands from the app, completely in the background. That should help.
How do you enable this? I’ve tried setting “run in app” to true and “show when run” to false, but the shortcut still opens a-Shell to run the command. I’ve tried the TestFlight version and the latest on the AppStore (1.15.0). I’m also using iOS 15.8.2 if that makes a difference.
Yes, the user interface has changed since the first message:
- "run in App": will always open the app.
- "run in Extension": does not open the app, but now has access to the app internal files and parameters.
- "show when run" is a settings by Apple that displays a window with the results of the shortcut before displaying the results of the shortcut in another window.
I see. This means that running scripts in the background still has a time limit, right?
Yes, and also a memory limit, I'm afraid.