How to handle a mixed Python + C / C++ project?

Answered

Hi there!

 

It's quite common for Python projects to have some parts written in C/++. I couldn't find a C Plugin in PyCharm. Could someone please tell me how I should handle this?

Thanks!

17 comments
Comment actions Permalink

Hello, Felix! There is no C plugin for Pycharm but you can use CLion: https://www.jetbrains.com/clion/ with python plugin which supports all features of Pycharm Community.

0
Comment actions Permalink

I have this interest too. It would be very convenient if I could open the same project in Clion and Pycharm; is there any way to do this?  I am working on a Flask program with some C++ code using Boost.Python.

If I start a CLion project, Pycharm can't open it due to errors, and similarly if I start a Pycharm project then CLion cannot open it.

0
Comment actions Permalink

The problem is that PyCharm and CLion use the same project format , but have different module types, settings, etc. For example, PyCharm knows nothing about "CPP_MODULE" module type - it has no providers to handle it. So, it's recommended to avoid sharing the same project between PyCharm and CLion.
If you like to proceed with working on your project in both IDEs, I can suggest creating a separate project to be used in PyCharm: create a new empty PyCharm project anywhere and then add a folder where your python, etc. files are stored as an additional content root to it using Settings/Project/Directories, Add content root.

1
Comment actions Permalink

Thanks I will try that.

0
Comment actions Permalink

Hi Anna,

thanks for your answers!

> The problem is that PyCharm and CLion use the same project format, but have different module types, settings, etc. For example, PyCharm knows nothing about "CPP_MODULE" module type - it has no providers to handle it. So, it's recommended to avoid sharing the same project between PyCharm and CLion.

Couldn't this problem simply be solved if each IDE was using its own settings dir (.idea, .lion, .charm, etc.)? I already have the same problem with PyCharm and WebStorm in some projects. I think JetBrains should be more clear on this and either release an IDE which handles all languages nicely via plugins and/or release a dedicated IDE for each language in way that all of them can be used next to each other on the same projects.

I started with PHPStorm, then I needed support for other languages and switched to IntelliJ Idea Ultimate since I was told that's the IDE to go if you want to combine multiple languages. Besides having all the Java stuff (which I don't need), it worked kinda well (really loved it). But I always had the feeling that the plugins were a limited subset of what their dedicated IDE counterpart would offer. Actually there is a lot of confusion about this across the web:

https://stackoverflow.com/questions/13827214/can-intellij-idea-encapsulate-all-of-the-functionality-of-webstorm-and-phpstorm

https://www.reddit.com/r/Python/comments/3eoi3f/is_pycharm_different_from_intellij_idea_with_the/

https://stackoverflow.com/questions/3339399/comparison-of-intellij-python-plugin-or-pycharm

https://news.ycombinator.com/item?id=7868669

the list goes on...

I ended up switching from IDEA to PyCharm + WebStorm. Now I find out that in order to handle Python projects that contain some C/++ I have to use another IDE (Clion) which does not work in combination with PyCharm...So now I have to ditch PyCharm in favor of Clion and I'm back using the (limited?) Python plugin and losing the Python project creation features etc.. Will this ever have an end?

> If you like to proceed with working on your project in both IDEs, I can suggest creating a separate project to be used in PyCharm: create a new empty PyCharm project anywhere and then add a folder where your python, etc. files are stored as an additional content root to it using Settings/Project/Directories, Add content root.

This sounds odd to me.

How about releasing one single IDE that can be extended via language plugins and let the users pay for each main language plugin they need? That way all the confusion would be gone and the user wouldn't have to manage the same IDE 5 times. If this won't happen, then please provide a nice solution to make each IDE work next to each other without trouble. :-)

 

4
Comment actions Permalink

I would have to second the sentiment of one IDE to do multiple languages.

I would also recommend producing sample files like "Example: Python GUI with C++ back end," so that users can just do the work to build their programs and packages and not get caught up in the quirks on an OS, Compiler, and the tools.  That would do wonders for JetBrains business. It would empower designers to work unencumbered by the need to play with each of these tools or to have build up "seen it before" ~knowledge of the quirks. Imagine how much more productive we would be - and more important JetBrains would be to the future. :)

 

1
Comment actions Permalink

With the recent update to CLion (2018.3.3) even rudimentary Python plugin is not available so there is really no way. The other way -- Use C++ plugin in IntelliJ Ultimate -- doesn't work either. 

So there is really no way...

Is VS Code now the only game in town for combined C++/Python development?

 

 

0
Comment actions Permalink

Hi @Reg+jetbrains,

As Anna has already written, CLion supports Python via the PyCharm Community Edition for CLion bundled plugin. The feature set corresponds to the PyCharm IDE Community Edition and includes all the basic and essential Python editing features, as well as running, debugging and testing. Please find more information in the web-help (https://www.jetbrains.com/help/clion/python.html) and in our blog (https://blog.jetbrains.com/clion/2016/01/python-support-in-clion/).

Checked - the plugin is available in CLion 2018.3.3:

0
Comment actions Permalink

@Anna Falevskaya: It would be fantastic if we could get the functionality of CLion and PyCharm Professional in a single product.

0
Comment actions Permalink
Hi Wagner, could you please specify which Python features you miss in CLion? Also feel free to comment or upvote a feature request about making CLion available as IntelliJ plugin: https://youtrack.jetbrains.com/issue/CPP-4141.
0
Comment actions Permalink

@Jiri Fait: upvoted.

 

The PyCharm Professional features I miss the most in CLion are support for remote interpreters (via SSH, Vagrant, or Docker) and remote debugging.

0
Comment actions Permalink
Wagner, thanks a lot for the clarification! Please also upvote a feature request about remote debugging (https://youtrack.jetbrains.com/issue/CPP-5681) and about combining CLion and PyCharm Professional (https://youtrack.jetbrains.com/issue/CPP-13470).
0
Comment actions Permalink

So... the thing is, I have a license of Clion and Pycharm but I can't use both in the same project!? This is just nonsense...

I would like to open both IDEs in the same project without any problem.. but it seems this is a big deal for Jetbrains....

0
Comment actions Permalink

And the other things is, I am using CLion with WSL. How do I configure an python interpreter inside of CLion to use it? Because there is no such option, just in pycharm professional

0
Comment actions Permalink

Just to add to this, particularly for number crunching code, one typically starts a project in Python. Then parts are written in Cython to speed up things. And in certain cases, instead of writing cython code that calls and existing C++ library you write some C++ code and have Cython call that. Now in terms of how things should work and how they work now.

1) If you are writing pure Python code, particularly for web development, Pycharm is absolutely fantastic. I can think of a few improvements but it is the best IDE on the market.

2) If you start writing Cython code, the syntax highlighting can get iffy. There aren't a lot of useful inspections, even for errors that should be easy to catch. If I have say a typo in the name of a variable in a .pxd file that refers to a variable in a C header file, no squiggly lines in the editor or in an inspection warn me. Ditto if I've mistyped the name of a variable in a .pxd file in a pyx file. You have to compile to find typos which is not something necessary when writing straight Python, C++ in CLion or Java IntelliJ Ultimate and frankly ridiculous. You have to build your Cython code from a terminal. There are no Pycharm (including Pycharm Professional) settings that will automatically build the package (and cython code usually lives in a Python package) for you. This lack of a build step is fine for straight python package because you can do a python setup.py develop once and things just work but is problematic once you start using Cython.

3) If you actually write C++ code, things are completely fubar. Pycharm can't even syntax highlight C++ code properly. It seems to think it's Python or some such. CLion is not a panacea here because CLion requires you to have a CMakefile for the C++ project whereas when developing a Python package, the cython code is built using Python setuptools. Writing a CMakefile to build the python package would be a PITA. The way you want the package built is using python setup.py build_ext --inplace with your build steps in your setup.py file. Pycharm really should be syntax highlighting C/C++ code properly and even providing some inspections here. You usually have some C++ code, a header is wrapped in a  .pxd file and then that is called from a .pyx file so by repurposing some CLion code or some such this should be doable.

I believe once while communicating with your support someone mentioned that it seemed like web developers pay for your IDEs but people writing numerical code prefer open source tools. I would suggest this is not because of a preference but because for this use case Pycharm is an inferior tool. Visual Studio Code and even straight vim properly configured are better. If you fix this, I strongly suspect you may find people writing number crunching code buy a lot of licenses. You have added scientific mode etc but frankly these aren't particularly useful because you can't really use them for large matrices and toy features that aren't industrial strength don't really help people writing numerical code very much.

0
Comment actions Permalink

I see VS currently leading the competition with intuitive mixed debugging without any attaching to process operation.

0
Comment actions Permalink

JetBrains, kindly consider adding C/C++ support to PyCharm Professional. I started to feel the pressing need in my projects. Switching between CLion and PyCharm is not a productive idea! I suggest you take our opinions asap.

0

Please sign in to leave a comment.