在develop mod中从windows上的pypy virtualenv卸载python包失败

2024-05-17 17:55:51 发布

您现在位置:Python中文网/ 问答频道 /正文

TL;DR:从使用tox创建的pypy环境中运行python setup.py develop --uninstall会导致异常:error: [Error 32] The process cannot access the file because it is being used by another process: c:\users\shach\code\pydocstyle\.tox\pypy\site-packages\funniest.egg-link。在

大家好

我有一组针对python包的集成测试,它们执行以下操作:

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

测试正在由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运行文件可以正常工作:

^{pr2}$

但是当我从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:

我想问题可能在于develop和{}都是从同一个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检查是否有进程保存该文件。{{cd26>,然后在

更新3:

在关闭CMD并打开一个新命令后仍会发生。在

更新4:

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


Tags: pyinfotoxeggsetuplinkcodepypy
2条回答

TL;DR:不要直接使用setup.py,使用pip install -e .。在

问题似乎出在windows上的setuptools。所发生的情况是,egg-link文件在被删除之前只打开和关闭了几行,而windows无法处理这一点。在

不知何故,pip确实能处理这种情况,我会在有更多信息时更新。在

我在setuptools中打开了一个issue。在

从描述来看,似乎在pypy setup.py develop uninstall运行的某个地方,一个文件或目录正处于打开状态,这会阻止在windows上删除它。您可以尝试使用“-X track resources”参数(pypy -X track-resources setup.py develop uninstall)运行pypy,该参数应通知您是否在关闭资源之前释放了包含资源的对象。有时,扫描s - open(path).read()这样的代码就足以找到问题所在,该代码将泄漏文件描述符,直到垃圾回收器运行、注意到ghost对象并将其删除。代码应该使用上下文管理器;with open(path) as fid: s = fid.read()

相关问题 更多 >