在PyCharm中,如何在导入的Cython扩展代码中的行处断开

时间:2019-01-03 00:35:33

标签: python pycharm cython

我正在尝试检查以下Python代码中调用的函数LinearNDInterpolator

from scipy.interpolate.interpnd import LinearNDInterpolator

我想运行一个Python脚本调用功能LinearNDInterpolator,并在line 304 of function LinearNDInterpolator处设置一个断点。我该怎么办?

我正在使用PyCharm。我无法“进入” LinearNDInterpolator的代码。以下是我正在运行的示例脚本。

import numpy as np
from scipy.interpolate.interpnd import LinearNDInterpolator
import matplotlib.pyplot as plt

x = np.linspace(-1,1,100)
y =  np.linspace(-1,1,100)
X, Y = np.meshgrid(x,y)

def f(x, y):
    s = np.hypot(x, y)
    phi = np.arctan2(y, x)
    tau = s + s*(1-s)/5 * np.sin(6*phi) 
    return 5*(1-tau) + tau

T = f(X, Y)
# Choose npts random point from the discrete domain of our model function
npts = 400
px, py = np.random.choice(x, npts), np.random.choice(y, npts)

fig, ax = plt.subplots(nrows=2, ncols=2)
# Plot the model function and the randomly selected sample points
ax[0,0].contourf(X, Y, T)
ax[0,0].scatter(px, py, c='k', alpha=0.2, marker='.')
ax[0,0].set_title('Sample points on f(X,Y)')

# Interpolate using three different methods and plot
i = 0
method = 'linear'
#for i, method in enumerate(('nearest', 'linear', 'cubic')):
ip = LinearNDInterpolator((px, py), f(px,py))
Ti = ip((X, Y))
r, c = (i+1) // 2, (i+1) % 2
ax[r,c].contourf(X, Y, Ti)
ax[r,c].set_title('method = {}'.format(method))

plt.show()

1 个答案:

答案 0 :(得分:0)

编辑-示例代码对我有用,减去注释掉的错误行

enter image description here

所以我自己测试了这个。

找到site-packages文件夹以找到scipy源文件

在Powershell中

python -m site

对我来说,这个文件夹是 C:\ Program Files(x86)\ Python37-32 \ Lib \ site-packages \ scipy

打开pycharm中的 init .py文件,并将断点设置在代码的第一行

__all__ = ['test'] <- breakpoint there

运行>调试>进入我的代码

enter image description here