python - 以编程方式从存储库进行 pip install 会导致错误 "No such file or directory"

标签 python python-3.x windows pip

在 win 10 上,我正在安装到 py 3.6 venv。从终端

pip install --upgrade git+git://github.com/larochew/py_daemoniker.git@cfd8a669975c217f6df7063be8cb8fbc08b5f0df#egg=daemoniker

工作正常:

Connected to pydev debugger (build 192.5728.105)
  Running command git clone -q git://github.com/larochew/py_daemoniker.git 'C:\Users\user\AppData\Local\Temp\pip-install-g9do107m\daemoniker'
Collecting daemoniker
  Cloning git://github.com/larochew/py_daemoniker.git (to revision cfd8a669975c217f6df7063be8cb8fbc08b5f0df) to c:\users\user\appdata\local\temp\pip-install-g9do107m\daemoniker
  Running command git checkout -q cfd8a669975c217f6df7063be8cb8fbc08b5f0df
Installing collected packages: daemoniker
    Running setup.py install for daemoniker: started
    Running setup.py install for daemoniker: finished with status 'done'
Successfully installed daemoniker-0.2.3

但是从代码来看:

try:
    from pip import main as pipmain
except:
    from pip._internal import main as pipmain

pipmain.main(['install', '--upgrade', 'git+git://github.com/larochew/py_daemoniker.git@cfd8a669975c217f6df7063be8cb8fbc08b5f0df#egg=daemoniker'])

结果:

Collecting daemoniker
  Cloning git://github.com/larochew/py_daemoniker.git (to revision cfd8a669975c217f6df7063be8cb8fbc08b5f0df) to c:\users\user\appdata\local\temp\pip-install-64iunozy\daemoniker
  Running command git clone -q git://github.com/larochew/py_daemoniker.git 'C:\Users\user\AppData\Local\Temp\pip-install-64iunozy\daemoniker'
  Running command git checkout -q cfd8a669975c217f6df7063be8cb8fbc08b5f0df
ERROR: Could not install packages due to an EnvironmentError: [Errno 2] No such file or directory: 'C:\\Users\\user\\AppData\\Local\\Temp\\pip-req-tracker-qu0hrtol\\9eeeef850bab53900fe60a86b33217ba700f6f3907aadc10a37ed11f'

虽然正常的软件包安装没有错误。

最佳答案

由于我需要在 Windows 下通过代码静默安装需求,下面的代码就达到了目的:

        subprocess.check_call(
            [executable, '-m', 'pip', 'install', '--upgrade', '-r', config['requirements_file']],
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE
        )

如果没有 stdout=subprocess.PIPE 来自 pip 的 stdout 将转到当前进程。此外,这不会在 win 中创建终端。感谢 @sinoroc 评论的引导

关于python - 以编程方式从存储库进行 pip install 会导致错误 "No such file or directory",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58997311/

相关文章:

windows - Freepascal 刷新 Windows 下每个输出的标准输出?

python - 没有这样的文件或目录 : . ../part.0.parquet

python - C 程序比 Python 子进程更快

python - 动态地将数组中的值分配给字典

c - 在 C 中使控制台窗口变大

c - 为什么代码在 Linux 上运行而不在 Windows 上运行?

python - Numpy 数组填充随机数,这样您只需沿 x/y 轴将值更改 1

Python 可以运行 while 循环直到 RuntimeError : maximum recursion depth exceeded while calling a Python object

c++ - OpenCV 3.2 for python with CUDA in Windows

python-3.x - Flask SQLalchemy 无法使用 Unix 套接字连接到 Google Cloud Postgresql 数据库