首页 > 解决方案 > 在 PyCharm 中,如何在导入的 Cython 扩展代码中换行

问题描述

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

from scipy.interpolate.interpnd import LinearNDInterpolator

我想运行一个 Python 脚本调用函数并在函数的第 304 行LinearNDInterpolator设置一个断点。我怎样才能做到这一点?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()

标签: pythonpycharmcython

解决方案


编辑 - 示例代码适用于我减去错误的注释行

在此处输入图像描述

所以我自己测试了这个。

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

在PowerShell中

python -m site

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

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

__all__ = ['test'] <- breakpoint there

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

在此处输入图像描述


推荐阅读