简体   繁体   English

如何在 Mac OS 升级后恢复我的 Python cron 作业?

[英]How do I restore my Python cron jobs after my Mac OS upgrade?

I recently upgraded to Mac Big Sur and have noticed my Python 3.8 cron jobs have stopped working.我最近升级到 Mac Big Sur 并注意到我的 Python 3.8 cron 作业已停止工作。 Under my own account in a bash shell, I can run this without issues...在我自己的 bash shell 帐户下,我可以毫无问题地运行它...

davea$ cd /Users/davea/Documents/workspace/article_project; source ./venv/bin/activate; python3 manage.py check_duplicates 

In my crontab, I had this set up, which used to work before the upgrade...在我的 crontab 中,我进行了这个设置,它在升级之前可以工作......

*/5 * * * * /bin/bash -l -c 'cd /Users/davea/Documents/workspace/article_project; source ./venv/bin/activate; python manage.py check_duplicates >> /Users/davea/logs/record2.txt 2>&1'

However, after the upgrade, I'm noticing my command is never run and I see this issue in my log file但是,升级后,我注意到我的命令从未运行,我在日志文件中看到了这个问题

/Library/Frameworks/Python.framework/Versions/3.8/bin/python3: can't open file 'manage.py': [Errno 1] Operation not permitted

These are the permissions/groups on my "manage.py" file...这些是我的“manage.py”文件中的权限/组...

davea$ ls -al manage.py 
-rwxrwxr-x 1 davea staff 866 Apr 15  2019 manage.py

What else do I need to do to get my cron job to run again?我还需要做什么才能让我的 cron 工作再次运行?

Turns out with the new Mac OS there is an extra level of permissions that need to be enabled.事实证明,新的 Mac OS 需要启用额外级别的权限。 In System Preferences, under Security and Privacy, I clicked the Privacy tab, and then added "cron" to the "Full disk Access" list在系统偏好设置的安全和隐私下,我点击隐私选项卡,然后将“cron”添加到“全盘访问”列表中

在此处输入图像描述

then the cron jobs ran without the permissions error.然后 cron 作业在没有权限错误的情况下运行。

I think in this case, python3 is considered as "any user" and with the -rwxrwxr permission it only have right to read the file, try to run chmod 775 manage.py in your folder to add permission to manage.py to be executed by "any user" (rigths should be set to -rwxrwxr ), hope it can help.我认为在这种情况下,python3 被视为“任何用户”,并且具有-rwxrwxr权限,它只有读取文件的权限,尝试在您的文件夹中运行chmod 775 manage.py以添加要执行的manage.py权限由“任何用户”(rigths 应设置为-rwxrwxr ),希望它可以提供帮助。 EDIT: technically, read permission should be enough for python to run a file, but I can't see another reason why this error would appear, and I would be interested if you find one编辑:从技术上讲,读取权限应该足以让 python 运行文件,但我看不出出现此错误的另一个原因,如果你找到一个我会感兴趣的

This looks like a SIP or other mac-specific access permissions error, especially since it was right after an upgrade.这看起来像是 SIP 或其他特定于 mac 的访问权限错误,尤其是因为它是在升级之后。 Could be: https://osxdaily.com/2018/10/09/fix-operation-not-permitted-terminal-error-macos/可能是: https://osxdaily.com/2018/10/09/fix-operation-not-permitted-terminal-error-macos/

I've also had lots of problems working with venvs with cron, could be related to this: https://stackoverflow.com/a/7031758/13113166我在使用 cron 使用 venv 时也遇到了很多问题,可能与此有关: https://stackoverflow.com/a/7031758/13113166

It's also weird that the error comes from /Library/Frameworks/Python.framework/Versions/3.8/bin/python3 when i think it should come from your venv if it's activated correctly.错误来自/Library/Frameworks/Python.framework/Versions/3.8/bin/python3也很奇怪,而我认为如果正确激活它应该来自您的 venv。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何停止将Mac OS X上的Python安装放到主目录中? - How do I stop Python install on Mac OS X from putting things in my home directory? 如何在 Docker Compose 容器中升级到 Python3+ - How do I upgrade to Python3+ in my Docker Compose Container 如何在OS X 10.6.8上还原我的System Python 2.6 - How to restore my System Python 2.6 on OS X 10.6.8 在装有 Catalina OS 的 Mac 上,如何最好地升级到 python 3? - How is it best to upgrade to python 3 on a Mac with Catalina OS? 加载环境var时,如何以cron身份运行python命令? - How do I run my python command as a cron while loading my environment vars? 如何在 mac os 上将我的 python 项目共享到没有 python 的计算机? - How can I share my python projects to the computers without python on mac os? 如何在我的mac上运行这个比特币python模型(通过PlanB)? - How do I run this bitcoin python model (by PlanB) on my mac? 如何更新我的 Mac 以使用最新版本的 Python? - How do I update my Mac to use the latest version of Python? 如何在Mac OS X Lion中将python 2.6设为默认值? - How can I make python 2.6 my default in Mac OS X Lion? 我尝试在 mac os 终端中运行我的 python 程序,但在我成功安装 Beautifulsoup4 后不断收到以下反馈 - I tried running my python program in a mac os terminal but keep getting the feedback below after I have successfully installed Beautifulsoup4
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM