Apple launches Apple Store app in India

The Apple Store app provides customers with the most personalized way to shop for Apple’s innovative lineup of products and services. Learn more >

You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Python Scripts in Virtual Environments in Background macOS

Hello all.


I have successfully driven myself nuts with this. Title says what I'm trying to accomplish. Using 2 services - 1. wiki Drazzilb08/daps and 2. local Kometa.


These install pretty similarly and are invoked similarly but I can't seem to blend them together. I have tried too many things to enumerate here but they include: running the python command with nohup, running with disown, making a LaunchAgent plist that calls a sh script to run the commands, all to no avail. I have tried specifically also to adapt the Kometa plist to the daps but I don't understand what this one does so...

The plist I'm trying to understand

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
 <key>Label</key>
 <string>com.YOUR_USERNAME.kometa</string>
 <key>ProgramArguments</key>
 <array>
     <string>sh</string>
     <string>-c</string>
     <string>kometa-venv/bin/python kometa.py --config /path/to/kometa-config/config.yml</string>
 </array>
 <key>UserName</key>
 <string>YOUR_USERNAME</string>
 <key>WorkingDirectory</key>
 <string>/PATH/TO/KOMETA</string>
</dict>
</plist>

Which gets invoked peculiarly to me

cd ~/Library/LaunchAgents/
launchctl bootstrap gui/YOUR-USER-ID com.YOUR_USERNAME.kometa.plist

And doesn't seem to work. How can I best accomplish 2 python scripts in background in their respective virtual environments at startup running macOS 14.7.2


I'd appreciate any advice!

Mac mini, macOS 14.7

Posted on Jan 18, 2025 11:31 AM

Reply
3 replies

Jan 18, 2025 12:13 PM in response to rothnd

rothnd wrote:

Title says what I'm trying to accomplish.

It does not.

Using 2 services - 1. wiki Drazzilb08/daps and 2. local Kometa.

I went to both site and I still have no idea what these things do.

These install pretty similarly and are invoked similarly but I can't seem to blend them together.

Blend them together in what way? What do they do?

I have tried too many things to enumerate here but they include: running the python command with nohup, running with disown, making a LaunchAgent plist that calls a sh script to run the commands, all to no avail.

The first step is always getting something running properly in an interactive Terminal session. Any kind of background operation is going to be wildly different. But that doesn't change the fact that you have to be able to run it manually first. Until you can do that, you will never make any further progress.


Assuming you can run them manually, please describe how you would do that, and what that would do for you.

I don't understand what this one does so...

Tell me about it.


The plist I'm trying to understand
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.YOUR_USERNAME.kometa</string>
<key>ProgramArguments</key>
<array>
<string>sh</string>
<string>-c</string>
<string>kometa-venv/bin/python kometa.py --config /path/to/kometa-config/config.yml</string>
</array>
<key>UserName</key>
<string>YOUR_USERNAME</string>
<key>WorkingDirectory</key>
<string>/PATH/TO/KOMETA</string>
</dict>
</plist>
Which gets invoked peculiarly to me
cd ~/Library/LaunchAgents/
launchctl bootstrap gui/YOUR-USER-ID com.YOUR_USERNAME.kometa.plist
And doesn't seem to work.

Of course not. It's wrong in at least 3 different ways.

How can I best accomplish 2 python scripts in background in their respective virtual environments at startup running macOS 14.7.2

At startup or login? Are these services used by a single user, or are they supposed to be available to all users?


What command lines would you execute if you just wanted to run it manually in Terminal?

Jan 18, 2025 1:27 PM in response to etresoft

Sorry I'm too confused myself. So I have a group of scripts run by the main.py script of daps. Right now my problem is with using a plist to load main.py so it's always running/accessible and so that it has access to an rclone exec.


I invoke the main.py manually with

cd /Users/nathan/daps
source .venv/bin/activate
python3 /Users/nathan/daps/main.py

which seems to work fine. However, when I attempt to load main.py in the background and it makes its call to rclone, rclone fails (command not found).


My updated plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
 <key>Label</key>
 <string>com.nathan.daps</string>
 <key>ProgramArguments</key>
 <array>
     <string>sh</string>
     <string>-c</string>
     <string>.venv/bin/python3 main.py</string>
 </array>
 <key>WorkingDirectory</key>
 <string>/Applications/daps</string>
</dict>
</plist>

Python Scripts in Virtual Environments in Background macOS

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.