[Django]-PermissionError: [Errno 1] Operation not permitted: '/Users/<local_path>/venv/pyvenv.cfg'

4๐Ÿ‘

I was facing the same problem and after a few searching i found a error with cron permissions.

This is how i solved:

  • Go to System Preferences -> Security & Privacy โ€“ Privacy -> Full Disk
    Access

  • Click on the + icon to add an item

    If the lock appears locked, click on him to unlock with your user password

  • Press Command + Shift + G to open a dialog

  • Type /usr/sbin/cron and press Enter

  • Search and select the cron file and click Open

Okay, now it should work.

๐Ÿ‘คPatrick Freitas

2๐Ÿ‘

The reason for the PermissionError is that the Python virtual environment is placed in the user directory.
If you put the virtual environment in a system directory, such as /opt, there will be no problem. See example below:

$ sudo mkdir /opt/myvenv
$ cd /opt/myvenv
$ sudo python3 -m venv .venv

$ mkdir ~/workspaces/myapp
$ cd ~/workspaces/myapp
$ cat <<EOF> demo.py
> with open('/Users/username/workspaces/myapp/demo.txt', 'a+') as f:
>     f.write('Hello, cron.\n')
> EOF

$ crontab -e

$ crontab -l
* * * * * /opt/myvenv/.venv/bin/python /Users/username/workspaces/myapp/demo.py  >> /Users/username/workspaces/myapp/demo.log 2>&1

$ ls -al
total 24
drwxr-xr-x    5 username  staff   160B  6 20 09:24 .
drwxr-xr-x  136 username  staff   4.3K  6 20 09:18 ..
-rw-r--r--    1 username  staff     0B  6 20 09:23 demo.log
-rw-r--r--    1 username  staff   117B  6 20 09:23 demo.py
-rw-r--r--    1 username  staff    11B  6 20 09:24 demo.txt
๐Ÿ‘คh2appy

Leave a comment