I have these two lines of code:
from libc.stdlib cimport malloc, calloc, realloc, free
from optv.tracking_framebuf cimport TargetArray
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.
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.
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.
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 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?
The problem was solved by adding /usr/local/lib/python2.7/dist-packages/
to PYTHONPATH by:
File --> Settings --> Project --> Project Structure --> Add Content Root .
By default, PyCharm will ignore Cython imports unless they are part of a search path. If the module folder is white, this is a smoking gun:
If the folder is white, then add it to the search path:
For some reason sometimes PyCharm does not actually add directories marked as "Sources Root" to the Python path. Fix this by switching this on.
Notice the "Starting Script" in the image below. I assume that manually adding these lines to your Python script would also achieve the same result.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With