evanill80
evanill80

Reputation: 157

Source file (.py) not compiling (.pyc not updated)

I'm trying to change some code in a production server, but when I test the new code it's not being executed. I think the issue is that when I upload the updated source file, it is not being compiled into a .pyc file.

-rw-r--r--  1 ubuntu ubuntu  47872 Jul 13 04:39 admin_email.py
-rw-r--r--  1 root   root    48212 Feb 10 03:12 admin_email.pyc

As you can see from the timestamps above, the .pyc file has not been updated.

Am I correct in assuming the reason the changes in admin_email.py are not being applied is because it is not being compiled? If so, can someone please offer a suggestion on how to get it to do so? Could the issue be that I need to restart the server?

Upvotes: 2

Views: 3831

Answers (3)

RemcoGerlich
RemcoGerlich

Reputation: 31270

The .pyc file is owned by the root user for some reason, and not writeable by other users. Your Python process probably runs as non-root, and can't create new .pyc files.

Either delete the old .pyc files (make a backup first), or chown them to the same user as the process that runs the .py files, and it will probably work.

Upvotes: 2

jgadelange
jgadelange

Reputation: 2582

Resetting the application probably does the trick. Since you are using gunicorn/nginx I assume you are also supervisord (if this is not the case please say so, then I can update my answer to also add that). In that case you can do sudo suporvisorctl restart <app_name> to restart the application.

Another issue that might be there, as brainless coder and Marius also stated, is that it seems the application was (at least once) ran as root, you should avoid this. You should remove the .pyc files and change the user the application runs under.

Upvotes: 4

Leb
Leb

Reputation: 15953

You can delete it if needed but it's really not. I don't see how that's the reason your code isn't executing.

.pyc files are byte codes that the python interpreter compiles the source to, so as long as you have access to the .py file you're safe to delete.

Are you running the script through shell? Did you give the file executable (+x) permission before doing so?

Upvotes: 1

Related Questions