holzschu / a-shell

A terminal for iOS, with multiple windows
BSD 3-Clause "New" or "Revised" License
2.51k stars 111 forks source link

pip install not accessible in shortcut #744

Open dragoncoder047 opened 5 months ago

dragoncoder047 commented 5 months ago

I pip-installed yt-dlp and it is now installed and I can access it even after quitting and restarting a-Shell. However when I try to invoke yt-dlp from a shortcut it can't find it. Am I doing something wrong?

image

image

holzschu commented 5 months ago

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:

When the extension runs, it uses the Python packages in ~shortcuts/Library.

dragoncoder047 commented 5 months ago

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?

holzschu commented 5 months ago

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.

dragoncoder047 commented 5 months ago

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.

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

image

holzschu commented 5 months ago

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.

dragoncoder047 commented 5 months ago

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.

Emasoft commented 3 months ago

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

dragoncoder047 commented 1 month ago

Update: I managed to get the yt-dlp executable into ~shortcuts/Library/bin, and can confirm it is there with a ls and grep, but it still refuses to run it. This time the error appears almost instantly.

image

holzschu commented 1 month ago

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.

Emasoft commented 1 month ago

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!

amarcolini commented 3 weeks ago

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.

holzschu commented 3 weeks ago

Yes, the user interface has changed since the first message:

amarcolini commented 3 weeks ago

I see. This means that running scripts in the background still has a time limit, right?

holzschu commented 3 weeks ago

Yes, and also a memory limit, I'm afraid.