简体   繁体   English

out of home folder .pyc文件?

[英]Out of home folder .pyc files?

If I place my project in /usr/bin/ 如果我将项目放在/ usr / bin /

will my python interpreter generate bytecode? 我的python解释器会生成字节码吗? 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/ 我已将其打包为从我的Ubuntu ppa安装的.deb文件,因此安装项目的明显位置是/ 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? 肯定有很多python项目安装在Ubuntu(显然是其他发行版),他们如何处理这个问题?

Thanks 谢谢

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. 关于/usr/bin的脚本,如果您以无权写入/usr/bin的用户身份执行脚本,则不会创建.pyc文件,据我所知,那里不是任何其他缓存机制。

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. 我所看到的是Ubuntu中的常见做法是在/usr/bin使用小脚本,甚至没有.py扩展名。 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. 他们只是导入一个库并调用某种library.main.Application().run()方法,这就是全部。

Note that the library is installed in a different path and that all library files are byte compiled for different python versions. 请注意,库安装在不同的路径中,并且所有库文件都是针对不同的python版本进行字节编译的。 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. 如果你的包中不是这种情况,那么你必须检查setup.py和你的debian文件,因为那不是应该的样子。

.pyc/.pyo files are not generated for scripts that are run directly. 不为直接运行的脚本生成.pyc / .pyo文件。 Python modules placed where Python modules are normally expected and packaged up have the .pyc/.pyo files generated at either build time or install time, and so aren't the end user's problem. 放置Python模块通常需要和打包的Python模块在构建时或安装时生成.pyc / .pyo文件,因此不是最终用户的问题。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM