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!

13
27 comments

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
Avatar
Permanently deleted user

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

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
Avatar
Permanently deleted user

Thanks I will try that.

0
Avatar
Permanently deleted user

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. :-)

 

15
Avatar
Permanently deleted user

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

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

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

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

2
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

@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.

1
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

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....

1

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

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.

9

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

3

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.

21

I +1 this feature request

4
Avatar
Permanently deleted user

I am a long time supporter of JetBrains products and periodically I put an eye on this issue to check if there is any update. I used to have a licence for CLion until last year, and I was using PyCharm community since a long time, unfortunately the  choice of keeping many different IDEs with partially overlapping functionality has become a non-sense to me and consequently, since last year, I moved to VSCode.
This has been quite a difficult choice because JetBrains products are clearly higher end solutions for professionals and I was ok with the price, as other people already told it would have been ok even to pay a double subscription in order to get a full featured all in one product (i.e. via plugins).
I think my situation is pretty common for people working in educational robotics, basically I need both scientific and web develpment features of PyCharm pro for quick sensor data analysis and GUI development respectively and C++ and full Rust support from CLion for low level programming.
I can see many other business where such combination of language support and features would be appreciated i.e. algo trading systems and scientific computing.
Now, considering that CLion already has a plugin with community features of PyCharm why don't you take this last step and offer a full plugin available for some additional money? 

17

I will probably switch to VSCode as well because of this.

4

I second that this is a problem. I'm developing a scientific simulation package with Python and C combined. I used VS code until it had a breaking bug recently, which forced me to use the community edition of PyCharm for a while, and I found it superior in many ways as a Python IDE. I actually considered suggesting to purchase a license for the team to my managers.

But then I realized the lack of C functionality, which basically broke my workflow. No linting, no proper highlight, not even basic tools... And this made me switch back to VS Code once that bug was fixed. It's a shame, really.

Also, I would be much more ready to pay for an all-in-one IDE, that combines tools for a wide set of languages and use cases, just like VS Code. I wouldn't mind too much if the price was higher, or if certain language plugins would need additional license purchases. I prefer the convenience of having a single IDE for everything, without the need to set up each IDE individually.

1

wanted to add one single cpp file to my python project in pycharm and work on it.

after all these years of using pycharm, just realized it doesnt even offer to create files with cpp extension.

came across this thread.

it is 2021 and nothing has been done.

reading about visual studio code.

 

also, since the really beginning of using pycharm, going through jetbrains site i find it really unusual to see an editor per language. just now, there are 11 ides on jetbrains.com ...

it should be one common ide, then the user can upgrade plugins or other things depending on their needs. unless there is a major reason to push for this separation.

 

 

2

@Soufiane Belharbi

If I'm just a bit cynical, I'd say it's money - so if you need a mixed Java+C, Python+C, Python+Java etc. project, you gonna need to pay twice. I don't see any other reason: the functionality is like 90% overlapping, and the core is the same. And even this would be easy to keep - instead of IDEs, just sell plugins for the core IntelliJ editor.

VS Code, Atom and most modern IDEs all can support multiple languages - often hundreds of them - on roughly the same level via plugins, and especially VS Code is rapidly evolving as a Python IDE. And it's (mostly) FOSS. Unless Jetbrains starts to move in the direction of unifying their editors, I don't see them still being superior in the near future.

1

Nagygeri11

to be honest, in my draft of the comment above, i wrote the reason could be `finance`, as you said it money. then i removed it .... i thought maybe it is too much.

but i lean toward this reason. while everyone is building ides that supports multiple languages, they went the other way and build a ide per language!!!! they are going backward.

last night,  i did a quick search about vsc, it supports a large panel of languages easily. but, it seems it doesnt have an easy synch with remote, or using remote interpreter.... but i didnt try it yet, so that's just from research, i have to confirm. but, everything is managed using plugins. you want to work with python you just install a plugin to color your code, and more.

 

did search in pycharm about cpp stuff plugin, not even a single result.

did install clion, python is missing the professional plugins for ssh remote... even if you have a license for pycharm.

clion and pycharm has almost the same functionalities... it is like they were forked from the same code...

 

 

0

@Soufiane Belharbi

I strongly agree with you. I did this research 2 years ago and still have no idea why the Jetbrains did not "merge" Pycharm and CLion in one single tool. I am working on Python and C/C++ codes at the same time and from my best practices when you need to manage these codes in two different tools it is increasing support complexity.  So I just switched from Pycharm to Visual Studio Code development (it was a hard design for me because Pycharm is a great tool). When you are starting with VS Code, the SSH remote connectivity looks messy, but it is only due to changing developing environment. You have a lot of WIKI's for VS Code SSH development. You can use Python and C/C++ debugger and different types of code inspections.

Good Luck.

 

 
1

Hi, guys! Is there any update for this feature?

1

I've been using IntelliJ products for over 5 years now. I paid for the Ultimate version for several years because it was the most versatile, and I've also been paying for the "All Products" package for just over two years. I've faced numerous issues that have never been fixed. Some of these problems have been open for years and were also reported by other users.

Now I've run into yet another issue that's been unresolved for years. I think it's time to stop using IntelliJ products for good. Well, at least I'll use them until next year since I've already paid, which gives me enough time to learn something else.

It's really a shame, to be honest.

0

Please sign in to leave a comment.