PyCharm 2017.2 Help

Cython Speedups

Installing Python extension

PyCharm's debugger is written in Python. Python is an interpreted language, which means that instructions have to be translated to machine code as the code is being run.

This costs time, and therefore it isn't as fast as the compiled code. Thankfully, Python supports compiled C-extensions through Cython. PyCharm ships with C versions of debugger code, which you can compile to make debugging in PyCharm faster.

If you have a large code base, using this speedup extension is reasonable.

The actions required to get additional speedups, depend on your platform:

macOS and *NIX

When the users start the debugger session, the notification pop-up window appears. The users just need to click the Install link there:

/help/img/idea/2017.2/py_install_cython_package.png
Windows

You don't need to do anything. We've bundled precompiled extensions, so you're already using them.

Troubleshooting

I get the error message 'Python.h: no such file or directory'

You need header files and static libraries for Python dev in order to compile Cython extensions. Use your package manager to install them system-wide.

For example, you can use the following command:

sudo apt-get install python-dev
for Python 2.x,
sudo apt-get install python3-dev
for Python 3.5, or
sudo apt-get install python3.6-dev
for Python 3.6

I get the error message 'Command 'gcc' failed with exit status 1

You need a C compiler in order to build Cython extensions for the debugger.

Using Cython Speedups without PyCharm UI

If one wants to manually compile Cython speedups, he/she should not use the PyCharm UI.

On macOS, use the following command:

/Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6 /Applications/PyCharm.app/Contents/helpers/pydev/setup_cython.py build_ext --inplace

On Ubuntu, use the following command:

/usr/bin/python3 /<PYCHARM_INSTALLATION_PATH>/helpers/pydev/setup_cython.py build_ext --inplace

Note that your paths should be adjusted to your particular local system.

See Also

Language and Framework-Specific Guidelines:

External Links:

Last modified: 17 August 2017