Pycharm无法识别路径中的Cython模块 [英] Pycharm does not recognize Cython modules located in path

查看:277
本文介绍了Pycharm无法识别路径中的Cython模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这两行代码:

from libc.stdlib cimport malloc, calloc, realloc, free

from optv.tracking_framebuf cimport TargetArray

第一个未由PyCharm突出显示(2016.2 Ubuntu 14.04上的.3 Professional)作为未解决的引用,但第二行以红色下划线突出显示为未解决的引用。

The first one is not highlighted by PyCharm (2016.2.3 professional on Ubuntu 14.04) as unresolved refference but the second line is highlighted in red underline as unresolved refference.

我的 TargetArray 类位于 tracking_framebuf.pxd 文件中,该文件位于 /usr/local/lib/python2.7/dist-packages/optv中/ 以及同名的.c,.pyx,.so文件。

My TargetArray class is located in tracking_framebuf.pxd file which is located in /usr/local/lib/python2.7/dist-packages/optv/ along with .c, .pyx, .so files with the same name.

我插入了 / usr /本地/lib/python2.7/dist-packages/optv / /usr/local/lib/python2.7/dist-packages / 与python解释器关联的路径,但错误消息仍在编辑器中显示。

I inserted /usr/local/lib/python2.7/dist-packages/optv/ and /usr/local/lib/python2.7/dist-packages/ paths to be associated with python interpreter, but the error messages are still apearing in the editor.

尽管错误消息,使用此命令成功将文件(以及其他文件)进行了cythonized安装程序y脚本:

Despite the error messages the file (along with others) is cythonized successfully using this setup.py script:

# -*- 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']}
)

Am我在消除这些错误消息的方式中缺少某些东西,并且能够查看放置在路径中的.pxd文件的内容?

Am I missing something on my way to get rid of these error messages and being able to view the contents of the .pxd files i place in the path?

推荐答案

通过在PYTHONPATH中添加 /usr/local/lib/python2.7/dist-packages / 可以解决此问题,方法是:

The problem was solved by adding /usr/local/lib/python2.7/dist-packages/ to PYTHONPATH by:

文件->设置->项目->项目结构->添加内容根。

File --> Settings --> Project --> Project Structure --> Add Content Root .

这篇关于Pycharm无法识别路径中的Cython模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆