Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Out of home folder .pyc files?

Tags:

python

linux

If I place my project in /usr/bin/

will my python interpreter generate bytecode? If so where does it put them as the files do not have write permission in that folder. Does it cache them in a temp file?

If not, is there a performance loss for me putting the project there?

I have packaged this up as a .deb file that is installed from my Ubuntu ppa, so the obvious place to install the project is in /usr/bin/

but if I don't generate byte code by putting it there what should I do? Can I give the project write permission if it installs on another persons machine? that would seem to be a security risk.

There are surely lots of python projects installed in Ubuntu ( and obviously other distros ) how do they deal with this?

Thanks

like image 612
Caustic Avatar asked Dec 31 '25 00:12

Caustic


1 Answers

Regarding the script in /usr/bin, if you execute your script as a user that doesn't have permissions to write in /usr/bin, then the .pyc files won't be created and, as far as I know, there isn't any other caching mechanism.

This means that your file will be byte compiled by the interpreter every time so, yes, there will be a performance loss. However, probably that loss it's not noticeable. Note that when a source file is updated, the compiled file is updated automatically without the user noticing it (at least most of the times).

What I've seen is the common practice in Ubuntu is to use small scripts in /usr/bin without even the .py extension. Those scripts are byte compiled very fast, so you don't need to worry about that. They just import a library and call some kind of library.main.Application().run() method and that's all.

Note that the library is installed in a different path and that all library files are byte compiled for different python versions. If that's not the case in your package, then you have to review you setup.py and your debian files since that's not the way it should be.

like image 100
jcollado Avatar answered Jan 02 '26 14:01

jcollado