简体   繁体   English

如何执行位于我的Python软件包安装目录中的二进制文件(没有sudo)

[英]How can I execute a binary file located in the installation directory of my Python package (without sudo)

Let's say I have a Python package structure like that: 假设我有一个像这样的Python包结构:

top-level/
    __init__.py
    utilities.py
    myscript.py
    binaryfile
LICENSE.txt
MANIFEST.in
README.rst
setup.cfg
setup.py

When I installed the package it will be located in: 安装软件包时,它将位于:

/usr/local/lib/python2.7/dist-packages/mypackage/

and the path of binary file will be: 二进制文件的路径为:

/usr/local/lib/python2.7/dist-packages/mypackage/binaryfile

My question is: How can I execute this binary file that located under /usr/local/... without root privileges (without sudo) from a script located in my package. 我的问题是:如何执行位于/usr/local/...下的二进制文件, 没有来自我程序包中脚本的root特权 (无sudo)。

I'm using my package as a console script so instead of using: 我使用我的软件包作为控制台脚本,所以没有使用:

sudo mypackage

to run my package, I wanna use only: 运行我的包,我只想使用:

mypackage

You want to give execute permission to normal users, so running 您想将执行权限授予普通用户,因此运行

sudo chmod +x /usr/local/lib/python2.7/dist-packages/mypackage/binaryfile

once should make it possible for normal users to execute it. 一次应该使普通用户可以执行它。

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

相关问题 如何在没有sudo的情况下执行python OpenCV程序? - How do I execute python OpenCV programs without sudo? 如何在不使用文件中的相对导入的情况下从不同目录中的 Python 脚本执行文件(导入其他模块)? - How can I execute a file (that imports other modules) from a Python script in a different directory without using relative imports in the file? 如何将 package 之外的文件附加到我的 Python package - How can I attach a file outside the package to my Python package 无法使用sudo python,但我可以在没有sudo的情况下使用python - Unable to sudo python but I can python without sudo 我怎样才能执行这个 Python 包? - How can I execute this Python package? Python 模块如何访问位于另一个目录(项目和构建包)中的数据文件? - How can a Python module access data files located in another directory (project and built package)? 如何修复python安装? - How can I fix my python installation? 我可以拥有我的Python OS X“ site-packages”目录的所有权(以避免“ sudo”)吗? - Can I take ownership of my Python OS X 'site-packages' directory (to avoid 'sudo')? 在没有sudo的情况下为Python安装包时如何避免权限被拒绝 - how to avoid Permission denied while installing package for Python without sudo 如何在没有sudo的情况下安装python-tk包? - How to install python-tk package without sudo?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM