【发布时间】:2017-09-18 16:36:02
【问题描述】:
我有这两行代码:
from libc.stdlib cimport malloc, calloc, realloc, free
from optv.tracking_framebuf cimport TargetArray
PyCharm(Ubuntu 14.04 上的 2016.2.3 专业版)未将第一行突出显示为未解析的引用,但第二行以红色下划线突出显示为未解析的引用。
我的TargetArray 类位于tracking_framebuf.pxd 文件中,该文件位于/usr/local/lib/python2.7/dist-packages/optv/ 以及同名的.c、.pyx、.so 文件中。
我插入了/usr/local/lib/python2.7/dist-packages/optv/ 和/usr/local/lib/python2.7/dist-packages/ 路径以与python解释器关联,但错误消息仍然出现在编辑器中。
尽管有错误消息,但使用此 setup.py 脚本成功地对文件(以及其他文件)进行了cythonized:
# -*- coding: utf-8 -*-
from distutils.core import setup
from Cython.Distutils import build_ext
from Cython.Distutils.extension import Extension
import numpy as np
import os
inc_dirs = [np.get_include(), '.']
def mk_ext(name, files):
return Extension(name, files, libraries=['optv'], include_dirs=inc_dirs,
pyrex_include_dirs=['.'])
ext_mods = [
mk_ext("optv.tracking_framebuf", ["optv/tracking_framebuf.pyx"]),
mk_ext("optv.parameters", ["optv/parameters.pyx"]),
mk_ext("optv.calibration", ["optv/calibration.pyx"]),
mk_ext("optv.transforms", ["optv/transforms.pyx"]),
mk_ext("optv.imgcoord", ["optv/imgcoord.pyx"]),
mk_ext("optv.image_processing", ["optv/image_processing.pyx"]),
mk_ext("optv.segmentation", ["optv/segmentation.pyx"]),
mk_ext("optv.orientation", ["optv/orientation.pyx"])
]
setup(
name="optv",
cmdclass = {'build_ext': build_ext},
packages=['optv'],
ext_modules = ext_mods,
package_data = {'optv': ['*.pxd']}
)
我在摆脱这些错误消息并能够查看我放置在路径中的 .pxd 文件的内容的过程中是否遗漏了什么?
【问题讨论】:
-
您的设置可能有问题...您是如何安装的?如果您想从非默认 Python 包文件夹运行,请尝试更改将编译后的包路径添加到环境变量
PYTHONPATH