[PYTHON] I was addicted to trying Cython with PyCharm, so make a note

Overview

Trying to use Cython in PyCharm,

  1. Basic Tutorial — Cython 0.29a0 documentation
  2. Easy to build Cython on PyCharm – Nagakute Parabola Diary

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)

environment

macOS High Sierra 10.13.6 PyCharm Professional 2018.2 (Japaneseized with Pleiades) Python3.6 Use virtualenv

What i did

Specify the absolute path

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.

Change working directory

Review the settings of external tools. PyCharm> Preferences> Tools> External Tools スクリーンショット 2018-09-03 23.11.39.png

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. スクリーンショット 2018-09-03 23.58.40.png

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.

What I noticed

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

I was addicted to trying Cython with PyCharm, so make a note
I set up TensowFlow and was addicted to it, so make a note
A note I was addicted to when creating a table with SQLAlchemy
A story I was addicted to trying to get a video url with tweepy
A note I was addicted to when running Python with Visual Studio Code
[Fabric] I was addicted to using boolean as an argument, so make a note of the countermeasures.
I got stuck trying to install various things with Mac El captain pip, so make a note
[python] A note when trying to use numpy with Cython
[Python] I tried to implement stable sorting, so make a note
A note I was addicted to when making a beep on Linux
Note that I was addicted to accessing the DB with Python's mysql.connector using a web application.
I tried to make a calculator with Tkinter so I will write it
[Python] When I tried to make a decompression tool with a zip file I just knew, I was addicted to sys.exit ()
A story that I was addicted to when I made SFTP communication with python
I stumbled upon using MoviePy, so make a note
I was addicted to scraping with Selenium (+ Python) in 2020
A story that I was addicted to at np.where
I was addicted to trying logging.getLogger in Flask 1.1.x
I want to make a blog editor with django admin
I want to make a click macro with pyautogui (desire)
What I was addicted to when dealing with huge files in a Linux 32bit environment
There was a doppelganger, so I tried to distinguish it with artificial intelligence (laughs) (Part 1)
I was addicted to multiprocessing + psycopg2
[5th] I tried to make a certain authenticator-like tool with python
A story that I was addicted to calling Lambda from AWS Lambda.
[2nd] I tried to make a certain authenticator-like tool with python
What I was addicted to with json.dumps in Python base64 encoding
[3rd] I tried to make a certain authenticator-like tool with python
Note that I was addicted to sklearn's missing value interpolation (Imputer)
I tried to make a periodical process with Selenium and Python
[Introduction] I want to make a Mastodon Bot with Python! 【Beginners】
I tried to make a todo application using bottle with python
[4th] I tried to make a certain authenticator-like tool with python
Postgres environment construction with Docker I struggled a little, so note
Homework was a pain, so I do management accounting with Python
[1st] I tried to make a certain authenticator-like tool with python
I tried to make a mechanism of exclusive control with Go
I was a little addicted to installing Python3.3 + mod_wsgi3.4 on Sakura VPS (CentOS), so a retrospective memo
When I tried to scrape using requests in python, I was addicted to SSLError, so a workaround memo
I tried to find out the difference between A + = B and A = A + B in Python, so make a note
What I was addicted to in Collective Intelligence Chaprter 3. It's not a typo, so I think something is wrong with my code.
I touched "Orator" so I made a note
How to add a package with PyCharm
I was addicted to pip install mysqlclient
I was addicted to Flask on dotCloud
Trying to handle SQLite3 with Python [Note]
I tried to make a Web API
What I was addicted to Python autorun
Python: I tried to make a flat / flat_map just right with a generator
I was addicted to running tensorflow on GPU with NVIDIA driver 440 + CUDA 10.2
A story I was addicted to when inserting from Python to a PostgreSQL table
I came up with a way to make a 3D model from a photo.
I tried to make "Sakurai-san" a LINE BOT with API Gateway + Lambda
Use Python from Java with Jython. I was also addicted to it.
I tried to make a traffic light-like with Raspberry Pi 4 (Python edition)
I get a UnicodeDecodeError when trying to connect to oracle with python sqlalchemy
[Streamlit] I hate JavaScript, so I make a web application only with Python
A note I looked up to make a command line tool in Python
I tried to make a url shortening service serverless with AWS CDK
I want to make matplotlib a dark theme
I wanted to use the find module of Ansible2, but it took some time, so make a note