[英]Failure to uninstall a python package from a pypy virtualenv on windows in develop mode
TL; DR:從使用tox
創建的pypy
環境中運行python setup.py develop --uninstall
pypy
導致異常: 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軟件包提供了一組集成測試,該集成測試可以執行以下操作:
python setup.py develop
(使用subprocess.check_call
) python setup.py develop --uninstall
(同樣,使用subprocess.check_call
) 測試由tox
。 一切正常的Python版本罰款27
, 33
, 34
, 35
和36
,但是代碼失敗的pypy
。
我不會在此處包括setup.py
和project文件,您可以認為它們很好。 我已使用此處顯示的最小包復制了此文件,並且它的工作原理相同(失敗?)。
為了重現,我創建了一個運行以下命令的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>
但是當我從pypy
的tox
環境運行它時:
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
和develop --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檢查是否有保存該文件的Process Explorer
。 我手動運行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 -X track-resources setup.py develop --uninstall
運行pypy,它應在關閉資源之前通知您是否釋放了持有資源的對象。 有時掃描s - open(path).read()
類s - open(path).read()
代碼可能足以發現問題,該代碼將泄漏文件描述符,直到垃圾收集器運行,注意到虛幻對象並將其刪除為止。 該代碼應使用上下文管理器; with open(path) as fid: s = fid.read()
TL; DR:不要直接使用setup.py
,請使用pip install -e .
。
看來問題setuptools
在Windows的setuptools
中。 發生的是, egg-link
文件在被刪除之前僅打開和關閉了幾行,而Windows無法處理。
pip
確實可以處理這種情況,我將在有更多信息時進行更新。
我在setuptools中打開了一個問題 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.