gpt4 book ai didi

python - 无法在开发模式下从 Windows 上的 pypy virtualenv 卸载 python 包

转载 作者:可可西里 更新时间:2023-11-01 14:22:26 25 4
gpt4 key购买 nike

TL;DR: 从使用 tox 创建的 pypy 环境运行 python setup.py develop --uninstall > 导致异常:错误:[错误 32] 进程无法访问该文件,因为它正被另一个进程使用:c:\users\shach\code\pydocstyle\.tox\pypy\site-packages\最有趣的蛋链接

大家好,

我有一组用于执行以下操作的 python 包的集成测试:

  1. 调用 python setup.py develop(使用 subprocess.check_call)
  2. 运行包的所有测试
  3. 调用 python setup.py develop --uninstall(再次使用 subprocess.check_call)

测试由 tox 运行。在 python 版本 2733343536 上一切正常,但代码在 pypy 上失败。

我不会在此处包含 setup.py 和项目文件,您可以假设它们没问题。我使用显示的最小包复制了此 here它仍然有效(失败?)。

为了重现,我创建了一个运行以下命令的 python 脚本:

import shlex
import subprocess

subprocess.check_call(shlex.split('python setup.py develop'))
print('----------')
subprocess.check_call(shlex.split('python setup.py develop --uninstall'))

使用系统上安装的常规 pypy 运行该文件工作正常:

C:\Users\shach\code\bla\funniest>pypy test.py
running develop
running egg_info
writing funniest.egg-info\PKG-INFO
writing dependency_links to funniest.egg-info\dependency_links.txt
writing top-level names to funniest.egg-info\top_level.txt
reading manifest file 'funniest.egg-info\SOURCES.txt'
writing manifest file 'funniest.egg-info\SOURCES.txt'
running build_ext
Creating c:\python\pypy\site-packages\funniest.egg-link (link to .)
Adding funniest 0.1 to easy-install.pth file

Installed c:\users\shach\code\bla\funniest
Processing dependencies for funniest==0.1
Finished processing dependencies for funniest==0.1
----------
running develop
Removing c:\python\pypy\site-packages\funniest.egg-link (link to .)
Removing funniest 0.1 from easy-install.pth file

C:\Users\shach\code\bla\funniest>

但是当我从 tox 环境为 pypy 运行它时:

C:\Users\shach\code\bla\funniest>tox
GLOB sdist-make: C:\Users\shach\code\bla\funniest\setup.py
pypy inst-nodeps: C:\Users\shach\code\bla\funniest\.tox\dist\funniest-0.1.zip
pypy installed: cffi==1.10.1,funniest==0.1,greenlet==0.4.12,readline==6.2.4.1
pypy runtests: PYTHONHASHSEED='122'
pypy runtests: commands[0] | python test.py
running develop
running egg_info
writing funniest.egg-info\PKG-INFO
writing dependency_links to funniest.egg-info\dependency_links.txt
writing top-level names to funniest.egg-info\top_level.txt
reading manifest file 'funniest.egg-info\SOURCES.txt'
writing manifest file 'funniest.egg-info\SOURCES.txt'
running build_ext
Creating c:\users\shach\code\bla\funniest\.tox\pypy\site-packages\funniest.egg-link (link to .)
funniest 0.1 is already the active version in easy-install.pth

Installed c:\users\shach\code\bla\funniest
Processing dependencies for funniest==0.1
Finished processing dependencies for funniest==0.1
----------
running develop
Removing c:\users\shach\code\bla\funniest\.tox\pypy\site-packages\funniest.egg-link (link to .)
error: [Error 32] The process cannot access the file because it is being used by another process: c:\users\shach\code\bla\funniest\.tox\pypy\site-packages\funniest.egg-link
Traceback (most recent call last):
File "test.py", line 6, in <module>
subprocess.check_call(shlex.split('python setup.py develop --uninstall'))
File "C:\Python\pypy\lib-python\2.7\subprocess.py", line 186, in check_call
raise CalledProcessError(retcode, cmd)
CalledProcessError: Command '['python', 'setup.py', 'develop', '--uninstall']' returned non-zero exit status 1
ERROR: InvocationError: 'C:\\Users\\shach\\code\\bla\\funniest\\.tox\\pypy\\bin\\python.EXE test.py'
___________________________________ summary ___________________________________
ERROR: pypy: commands failed

C:\Users\shach\code\bla\funniest>

这是我用来重现的 tox.ini:

[tox]
envlist = pypy
[testenv]
commands=python test.py

我确定我对该目录具有读/写权限,但我有点失去理智了。

它在 linux 上工作得很好。可能是因为您可以删除正在使用的文件(inodes 等):^)

更新 1:

我认为问题可能在于 developdevelop --uninstall 都是从同一个 python 文件运行的,并且某些资源没有被正确清理(可能是一个打开的文件锁定了 egg-link),所以我手动运行了它:

C:\Users\shach\code\bla\funniest>.tox\pypy\bin\activate.bat

(pypy) C:\Users\shach\code\bla\funniest>pypy setup.py develop
running develop
running egg_info
writing funniest.egg-info\PKG-INFO
writing dependency_links to funniest.egg-info\dependency_links.txt
writing top-level names to funniest.egg-info\top_level.txt
reading manifest file 'funniest.egg-info\SOURCES.txt'
writing manifest file 'funniest.egg-info\SOURCES.txt'
running build_ext
Creating c:\users\shach\code\bla\funniest\.tox\pypy\site-packages\funniest.egg-link (link to .)
funniest 0.1 is already the active version in easy-install.pth

Installed c:\users\shach\code\bla\funniest
Processing dependencies for funniest==0.1
Finished processing dependencies for funniest==0.1

(pypy) C:\Users\shach\code\bla\funniest>pypy setup.py develop --uninstall
running develop
Removing c:\users\shach\code\bla\funniest\.tox\pypy\site-packages\funniest.egg-link (link to .)
error: [Error 32] The process cannot access the file because it is being used by another process: c:\users\shach\code\bla\funniest\.tox\pypy\site-packages\funniest.egg-link

(pypy) C:\Users\shach\code\bla\funniest>

仍然失败:(

请指教!

沙查尔。

更新 2:

我尝试使用 Sysinternal 的 Process Explorer 和 nada 检查是否有进程持有该文件。我手动运行 pypy setup.py develop,然后在 Process Explorer 中检查并确保该文件未在任何进程中打开,然后运行 ​​pypy setup.py develop --uninstall 并引发了同样的错误。

更新 3:

关闭CMD再打开一个新的CMD后仍然发生。

更新 4:

重启机器不能解决这个问题!什么-----?

最佳答案

从描述来看,似乎在运行 pypy setup.py develop --uninstall 的某处,文件或目录处于打开状态,这会阻止它在 Windows 上被删除。您可以尝试使用“-X track-resources”参数运行 pypy (pypy -X track-resources setup.py develop --uninstall) 如果持有资源的对象在资源已关闭。有时扫描 s - open(path).read() 之类的代码可能足以发现问题,该代码会泄漏文件描述符,直到垃圾收集器运行、注意到幽灵对象并删除它。代码应该使用上下文管理器; 以 open(path) 作为 fid:s = fid.read()

关于python - 无法在开发模式下从 Windows 上的 pypy virtualenv 卸载 python 包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46401252/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com