Poetry安装/添加包报'PythonInfo'无version_nodot属性问题问询
问题现象
将Poetry升级至1.1.14稳定版后出现环境处理异常:安装pandas、pynvim等无明确规律的包时,会抛出'PythonInfo' object has no attribute 'version_nodot'错误,Poetry基本无法正常使用,报错堆栈如下:
Creating virtualenv testpoetry-g4SgMX0R-py3.8 in C:\Users\<username>\AppData\Local\pypoetry\Cache\virtualenvs AttributeError 'PythonInfo' object has no attribute 'version_nodot' at ~\AppData\Roaming\pypoetry\venv\lib\site-packages\virtualenv\create\via_global_ref\builtin\cpython\cpython3.py:122 in python_zip 118│ "python{VERSION}.zip" and "python{VERSION}._pth" files. User can 119│ move/rename *zip* file and edit `sys.path` by editing *_pth* file. 120│ Here the `pattern` is used only for the default *zip* file name! 121│ """ → 122│ pattern = "*python{}.zip".format(interpreter.version_nodot) 123│ matches = fnmatch.filter(interpreter.path, pattern) 124│ matched_paths = map(Path, matches) 125│ existing_paths = filter(method("exists"), matched_paths) 126│ path = next(existing_paths, None)
升级到Poetry预览版后,即使配置virtualenvs.prefer-active-python = true强制指定当前conda环境,Poetry仍然会访问pypoetry\venv\路径下的组件触发上述报错,无法正常使用。
触发原因
- 这是Poetry 1.1.14版本的已知通用兼容问题,大量Windows平台开发者升级后都遇到了相同报错,不属于个人环境配置错误。
- 根因是Poetry 1.1.14打包时没有锁定
virtualenv依赖版本,高版本virtualenv移除了PythonInfo对象的version_nodot属性,但Poetry 1.1.14内置的虚拟环境创建逻辑没有同步适配该变更,调用属性时直接抛出AttributeError。 - 配置
virtualenvs.prefer-active-python = true仅指定Poetry创建项目虚拟环境时使用的基础Python解释器,不会改变Poetry启动时优先加载自身安装目录(即%APPDATA%\pypoetry\venv\)下依赖包的逻辑,因此即使指定了conda环境,仍然会加载不兼容版本的virtualenv触发报错。
排查思路与解决方案
- 排查方法:执行
poetry debug:info查看当前Poetry实际加载的依赖路径、Python解释器路径、虚拟环境配置项,确认virtualenv包的加载位置是否为Poetry自带venv目录下的不兼容版本。 - 方案1:降级Poetry自带环境的virtualenv到兼容版本
打开命令提示符执行以下命令即可修复:
该版本virtualenv保留了cd %APPDATA%\pypoetry\venv\Scripts .\pip.exe install virtualenv==20.13.4version_nodot属性,和Poetry 1.1.14完全兼容,执行完成后重新运行包安装命令即可恢复正常。 - 方案2:升级Poetry到1.2及以上正式版本
Poetry 1.2正式版已经修复了该virtualenv版本兼容问题,升级后不需要额外调整配置即可正常识别conda环境、创建虚拟环境,注意不要使用存在逻辑残留的早期预览版。
内容的提问来源于stack exchange,提问作者Huug.
相关产品推荐
相关产品推荐

