编译我的代码时内核不断崩溃

Kernel constantly crashes while compiling my code

我目前正在尝试获取葡萄牙大陆的驱动网络,这是一个多边形。然而,最后一行代码的内核崩溃了。在 ubuntu 终端它说; 'Created graph with 4,901,116 nodes and 9,503,596 edges in 101.64 seconds',几秒钟后内核给我以下消息:'Kernel Restarting The kernel for Desktop/osmnx_project.ipynb appears to have died. It will restart automatically'

import geopandas as gpd 
import pandas as pd 
from shapely.geometry import Point, LineString, Polygon 
import networkx as nx 
import osmnx as ox 
import matplotlib.pyplot as plt 
from descartes import PolygonPatch 
from IPython.display import IFrame 
ox.config(log_console=True, use_cache=True)

place = 'Portugal'

G = ox.gdf_from_place(place)

exploded_G = G.explode()

exploded_G['area'] = exploded_G.area
exploded_G.sort_values(by='area', inplace=True)

Portugal= exploded_G.iloc[-1]['geometry']

g = ox.graph_from_polygon(polygon = Portugal, network_type = 'drive')

任何人都可以帮我弄清楚到底出了什么问题,或者是否有办法简化我的代码以使其更轻更快。我怀疑这可能是 RAM 问题,但我的计算机有 16GB RAM

提前致谢。

对我来说这确实是一个 RAM 问题。

参考similar issue on GitHub,下面是建议的解决方案。

Don't use Jupyter notebook. Use a simple .py script. There are known problem with notebook. It doesn't allow cuda to deallocate resources once the session is over which creates problems.