Trying to use Cython in PyCharm,
After setting setup.py and executing it, referring to
/Users/username/PycharmProjects/cyyc/venv/bin/python3.6 /Users/username/PycharmProjects/cyyc/setup.py build_ext --inplace
Traceback (most recent call last):
File "/Users/username/PycharmProjects/cyyc/setup.py", line 8, in <module>
ext_modules=cythonize("helloworld.pyx")
File "/Users/username/PycharmProjects/cyyc/venv/lib/python3.6/site-packages/Cython/Build/Dependencies.py", line 897, in cythonize
aliases=aliases)
File "/Users/username/PycharmProjects/cyyc/venv/lib/python3.6/site-packages/Cython/Build/Dependencies.py", line 777, in create_extension_list
for file in nonempty(sorted(extended_iglob(filepattern)), "'%s' doesn't match any files" % filepattern):
File "/Users/username/PycharmProjects/cyyc/venv/lib/python3.6/site-packages/Cython/Build/Dependencies.py", line 102, in nonempty
raise ValueError(error_msg)
ValueError: 'helloworld.pyx' doesn't match any files
Process completed with exit code 1
I was told that helloworld.pyx could not be found.
(" Cyyc "
is the project name)
macOS High Sierra 10.13.6 PyCharm Professional 2018.2 (Japaneseized with Pleiades) Python3.6 Use virtualenv
Made the location of the .pyx file an absolute path.
setup.py
from distutils.core import setup
from Cython.Build import cythonize
setup(
ext_modules=cythonize("/Users/username/PycharmProjects/cyyc/helloworld.pyx")
)
It was successful, but this is inconvenient.
Review the settings of external tools.
PyCharm> Preferences> Tools> External Tools
The working directory is / venv / bin
by default, but change it to the directory containing the source files.
Here, for the time being, specify the project directory $ Projectpath $
with a macro.
As I noticed later, Referenced site 2 also set it like this.
Restored setup.py.
setup.py
from distutils.core import setup
from Cython.Build import cythonize
setup(
ext_modules=cythonize("helloworld.pyx")
)
When executed, a .so file was generated.
Maybe because the first argument is specified as FilePath
in the macro in the external tool settings, if you execute the external tool with a file other than ** setup.py ** open, that file will be the argument Is put in and fails to execute.
Recommended Posts