You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过pip安装只读目录下的Python包且无需本地复制文件夹

问题描述

我尝试安装位于只读挂载目录下的Python C扩展包,pip默认会在包所在路径下创建build子目录执行构建,因挂载目录无写入权限导致安装失败。

执行安装命令:

pip install /mnt/remote/pkgname

完整报错日志如下:

Processing /mnt/remote/pkgname
  Preparing metadata (setup.py) ... done
Using legacy 'setup.py install' for pkgname, since package 'wheel' is not installed.
Installing collected packages: pkgname
  Attempting uninstall: pkgname
    Found existing installation: pkgname 1.0.0
    Uninstalling pkgname-1.0.0:
      Successfully uninstalled pkgname-1.0.0
    Running setup.py install for pkgname ... error
    ERROR: Command errored out with exit status 1:
     command: /path/to/venv/bin/python3.8 -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/mnt/remote/pkgname/setup.py'"'"'; __file__='"'"'/mnt/remote/pkgname/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-84ofxq5a/install-record.txt --single-version-externally-managed --compile --install-headers /path/to/venv/include/site/python3.8/pkgname
         cwd: /mnt/remote/pkgname/
    Complete output (6 lines):
    running install
    running build
    running build_ext
    building '_pkgname' extension
    creating build
    error: could not create 'build': Read-only file system
    ----------------------------------------
  Rolling back uninstall of pkgname
  Moving to /path/to/venv/lib/python3.8/site-packages/_pkgname.cpython-38-x86_64-linux-gnu.so
   from /tmp/pip-uninstall-6pwxs8h_/_pkgname.cpython-38-x86_64-linux-gnu.so
  Moving to /path/to/venv/lib/python3.8/site-packages/pkgname-1.0.0.egg-info
   from /path/to/venv/lib/python3.8/site-packages/~lclib-1.0.0.egg-info
ERROR: Command errored out with exit status 1: /path/to/venv/bin/python3.8 -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/mnt/remote/pkgname/setup.py'"'"'; __file__='"'"'/mnt/remote/pkgname/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-84ofxq5a/install-record.txt --single-version-externally-managed --compile --install-headers /path/to/venv/include/site/python3.8/pkgname Check the logs for full command output.

已尝试组合使用-e、--target <dir>、--src等参数,均未解决报错。

需求

是否有方法可以无需将该文件夹复制到本地即可完成包的编译安装?

补充说明

该问题在pip官方仓库已有长期讨论,目前临时解决方案是使用已弃用的参数执行命令:

pip install --use-deprecated=out-of-tree-build /mnt/remote/pkgname

但该标识将在pip 22.1版本停止生效,仍需要长期可用的解决方案。

内容的提问来源于stack exchange,提问作者augustomen

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.29 11:24:02