Geopandas与Spyder版本兼容冲突及input命令替代方案求助
问题描述
在Spyder里跑Geopandas模块时卡壳了:
- Spyder 4.2.5能正常兼容Geopandas,但一用
input()命令就崩溃,查了下这个bug在Spyder 5.3已经修复 - 升级到Spyder 5.3及以上版本后,Geopandas又没法正常工作了,两头为难
试跑的代码如下:
def Coditions_R3(): print("This is R3") def Coditions_R4(): print("This is R4") System = input('Please Enter drone system: \n' ) print(System) if (System == 'R3'): Coditions_R3() elif (System == 'R4'): Coditions_R4()
解决方案
一、让Geopandas适配高版本Spyder
- 对齐Python环境:升级Spyder后,确保用的是之前跑Geopandas的那个虚拟环境(比如conda环境),别混着用系统Python和虚拟环境
- 重装Geopandas:在当前Spyder对应的环境里,彻底卸载现有Geopandas和它的依赖包(fiona、shapely这些),再重新装最新稳定版:
用pip的话:
用conda的话:pip uninstall geopandas fiona shapely -y pip install geopandasconda remove geopandas fiona shapely -y conda install geopandas -c conda-forge - 核对依赖版本:检查Geopandas的依赖包(fiona、shapely、pyproj等)版本和当前Python、Spyder版本是否兼容,用
pip list或conda list查看,有冲突就装指定的兼容版本
二、替代input()命令的方案(针对Spyder 4.2.5)
如果暂时不想升级Spyder,换个方式替代input()就能避免崩溃:
- 用IPython控制台手动赋值:先把函数部分跑起来,然后直接在控制台里输入
System = 'R3'(或者你需要的输入值),再执行判断逻辑 - 从文本文件读输入:把要输入的内容写到
input.txt里,代码里直接读这个文件:def Coditions_R3(): print("This is R3") def Coditions_R4(): print("This is R4") # 从input.txt读取输入内容 with open('input.txt', 'r') as f: System = f.read().strip() print(System) if System == 'R3': Coditions_R3() elif System == 'R4': Coditions_R4() - 用Spyder变量编辑器:提前在变量编辑器里创建
System变量并赋值,代码直接用这个变量就行
内容的提问来源于stack exchange,提问作者Sumana
相关产品推荐
相关产品推荐

