如何从独立的 python 安装中在 venv 中安装 selinux 包
我已经从源代码构建了 python3.8.12 并将其安装在一台没有其他 python 的机器上的 /python3 中。没有“系统”包。 (它是 rocky8.5 linux)
现在我从该 python 创建并激活一个 venv:
/python3/bin/python -m venv myvenv
source myvenv/bin/activate
现在我从本地存储库安装此 venv 中的软件包
pip install -r requirements.txt --index-url=file:///python3/pypkgs/simple
该存储库是使用 pip2pi 构建的。这一切都是为了完整的气隙部署而设计的。
现在我无法导入 selinux,因为它显然不知道 venv 中的 selinux,而是在系统中搜索。
(myvenv) [root@node1]# python -c "import selinux"
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/root/myvenv/lib/python3.8/site-packages/selinux/__init__.py", line 104, in <module>
check_system_sitepackages()
File "/root/myvenv/lib/python3.8/site-packages/selinux/__init__.py", line 100, in check_system_sitepackages
raise Exception(
Exception: Failed to detect selinux python bindings at ['/python3/lib/python3.8/site-packages']
我使用 selinux 包作为示例,因为这是我当前面临的问题。不确定这是否是一个更广泛的问题。尚未进行详尽的测试,但没有与任何其他包出现问题。
I have built python3.8.12 from source and installed it in /python3 on a machine with no other python anywhere. there are no "system" packages. (it is rocky8.5 linux)
Now I create and activate a venv from that python:
/python3/bin/python -m venv myvenv
source myvenv/bin/activate
Now I install packages in this venv from a local repository
pip install -r requirements.txt --index-url=file:///python3/pypkgs/simple
The repository was built with pip2pi. this is all being designed for full airgap deployments.
Now I cannot import selinux as it is apparently not aware of the selinux in the venv, and is instead searching the system.
(myvenv) [root@node1]# python -c "import selinux"
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/root/myvenv/lib/python3.8/site-packages/selinux/__init__.py", line 104, in <module>
check_system_sitepackages()
File "/root/myvenv/lib/python3.8/site-packages/selinux/__init__.py", line 100, in check_system_sitepackages
raise Exception(
Exception: Failed to detect selinux python bindings at ['/python3/lib/python3.8/site-packages']
I use the selinux package as an example because it is the issue I am currently faced with. Not sure if this is a wider problem yet. Haven't tested exhaustively, but have not had issue with any other package.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,我想我已经成功了。不知道这个修复有多可怕。
首先,我将 selinux 安装到系统 /python3 (显然你不能在 venv 中使用 selinux - 必须是系统级的?)
然后我将 /python3/bin/python 硬编码到这一行: https://github.com/pycontribs/selinux/blob/321d66619ed59bec00a9dc6216ce417d7befec41/selinux/__init__.py#L76
Ok I guess I got it working. Not sure how horrendous of a fix this is.
First, I installed selinux to the system /python3 (apparently you can't use selinux within a venv - has to be system level?)
And then I hardcoded my /python3/bin/python to this line: https://github.com/pycontribs/selinux/blob/321d66619ed59bec00a9dc6216ce417d7befec41/selinux/__init__.py#L76