More languages, more power: Python support

Posted on by Anastasia Kazakova

Hi,

CLion is known to be a cross-platform IDE for C and C++. However, the first CLion 1.5 EAP build brought the Swift support to CLion and made IntelliJ-based Swift IDE on Linux possible. Recent CLion EAP build added support for Python. Let’s take a look at the features.

Initial setup

Getting started with Python in CLion is way more easier than starting with Swift, since the plugin is already bundled into the IDE and is on by default. All you need is to install Python SDK and point CLion to the Python interpreter for your project:
python_interpreter
Since CLion is using CMake project model as a basis, you still need to have a proper CMake project, and then can mix Python and C/C++.

Rem. In case of working with Python in CLion due to PY-18231 and PY-18221 we do recommend to set run.processes.with.pty to false in CLion’s registry:

  • in Find Action dialog (Shift+Ctrl+A on Linux/Windows, ⇧⌘A on OS X) type Registry,
  • in the registry type run.processes.with.pty to find the parameter,
  • untick the parameter there.

This is necessary for correct Python console and Python run/debug functioning.

We also observed several problems with debugger on Windows, when using Python from Cygwin. So better install it from here.

Features

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.

You may notice quite a lot of new settings available if filter them typing ‘python’:
python_settings

Python plugin in CLion provides:

  • Python code parsing and highlighting. Colors & Fonts settings will help you to configure your favourite scheme.
  • Python code built-in code formatter together with the separate set of Python code style settings that support you code style preferences.
  • Code completion, file structure view and various navigation actions:
    python_goto_class
  • Find Usages in Python code.
  • Live Templates for generating widely-used code samples with ease:
    python_live_templates
  • Refactorings, including Rename, Change Signature, Extract Variable/Parameter/Constant/etc. and more.
  • A huge list of code intentions and inspections with quick fixes to make your code better and raise its quality:
    python_quick_fix
  • Quick documentation:
    python_quick_doc
    and various external documentation resources.
  • Python console: you can start it from Tools | Python Console or Find Action dialog, alternatively you can execute any Python code in console by simply pressing Alt+Shift+E.
  • Run and debug for Python configurations.
  • Unit testing.

Short demo below will demonstrate you some of the features:
https://www.youtube.com/watch?v=Cmd6M8l2nSs

Download the build and give it a try. Share your feedback in the comments section below. We’ll be glad to hear what you think about the Python support in CLion.

And in case you are interested in more PyCharm features, find a set of video tutorials covering PyCharm functionality and features here.

Sincerely yours,
The CLion Team

Comments below can no longer be edited.

26 Responses to More languages, more power: Python support

  1. Yury V. Zaytsev says:

    January 21, 2016

    YAY!!!11 for Python support in CLion. I find it a pretty sad that Cython support doesn’t seem to be included though. One important reason why you would want to deal with Python from inside CLion anyways is obviously in order to work on idiomatic Python bindings for your C++ software (or bindings where you need to be in control of very low level stuff for performance reasons). In this case, Cython (possibly on top of some autogenerator) is clearly the way to go. No support for Cython == low productivity in this scenario 🙁

    • Anastasia Kazakova says:

      January 21, 2016

      Agree, that could be a very useful case. Currently Cython is included into PyCharm Professional Edition, however we’ll consider it for CLion: https://youtrack.jetbrains.com/issue/CPP-5652. Feel free to upvote.

      • Yury V. Zaytsev says:

        January 21, 2016

        Thanks, Anastasia!

      • Ivan Smirnov says:

        January 22, 2016

        +1 here, if using Python with C++, in most likelihood you’ll end up wrapping the extensions in Cython, would be great to see (at least a basic) support for Cython

  2. Martin Pecka says:

    January 21, 2016

    Now, CLion has become the best and single IDE for developing in ROS (Robot Operating System)

  3. Dmitry Romanov says:

    January 21, 2016

    Wow! You are doing a great job! Thank you!

    I would also like to see Cython support here. I think it is ok moving it from PyCharm pro because CLion is not free too.

    • Anastasia Kazakova says:

      January 22, 2016

      That’s why we’ll consider it for sure, however need to find some team resources first.

  4. NoName says:

    January 21, 2016

    lua/luaJIT support would be awesome, since it’s used a lot as embedded language in c/c++ programs.

    • Anastasia Kazakova says:

      January 22, 2016

      There is a 3rd party Lua plugin in the repository. However, it doesn’t work correctly since there is no way to point to the Lua SDK in CLion for it. We’ve submitted an issue to the plugin author and logged it all here: https://youtrack.jetbrains.com/issue/CPP-1277

  5. Thomas Johnson says:

    January 21, 2016

    Can you use CLion to debug C/C++ Python extensions?

    • Anastasia Kazakova says:

      January 22, 2016

      No, I’m afraid this is currently not supported. Please, pay attention to the following ticket: https://youtrack.jetbrains.com/issue/CPP-5652

      • Thomas Johnson says:

        January 22, 2016

        Cython support isn’t quite the same as C/C++ extension support, right? I was talking more about something like python extensions built with Boost::Python or directly with the Python API like in https://docs.python.org/2/extending/extending.html

        • Anastasia Kazakova says:

          January 22, 2016

          So you mean you want to debug C++ function calls, am I right? This will require cross-language resolve. We’ve created the corresponding feature request (https://youtrack.jetbrains.com/issue/CPP-5649) as it’s not on in CLion now. Feel free to upvote.

  6. Olof Edlund says:

    February 6, 2016

    When should one use PyCharm and when should one use CLion with regards to Python?

    I’m mainly a C++ developer (work) and I’m using CLion but I’m about to dabble with Raspberry Pi for fun at home and I don’t know which IDE to choose.

    I’m guessing PyCharm probably is a better platform for pure Python development but I’m used to CLion and I wouldn’t mind to learn things on how I might be able to use Python in conjunction with C++ at work.

    • Anastasia Kazakova says:

      February 6, 2016

      Python plugin in CLion is not for pure Python dev, PyCharm is a better option for this, since it supports a lot of Python specific features/frameworks/tools/etc. However, if you have a mixed C/C++ and Python project, or use Python for some code generation, etc. scripting in your C/C++ projects, then CLion is a choice for you.

  7. Chris says:

    March 2, 2016

    I’m getting: “Error running error=7, Argument list too long” when trying to run a python program in the clion terminal.

    EAP Build: 145.184.4, JRE: 1.8.0_76-release-b18 amd64

    • Anastasia Kazakova says:

      March 3, 2016

      Could you please share which program are you trying to run? How do you do that? Can you run it the same way from the usual terminal (not in CLion)?

  8. Giles says:

    September 6, 2018

    Want to be able to use “Project Structure” in CLion to set a python source folder. Looks like it’s missing from CLion. I can find and set it in PyCharm but alas get unresolved references in CLion. Is there a way (aside from altering the python path env to include the dir) to do this?
    (There’s not much that can’t be coded with Rust + Python)

    • Anastasia Kazakova says:

      September 6, 2018

      CLion doesn’t have Project Structure window as PyCharm does. But the same functionality is available in CLion in the context menu on the file if you call it in the project view, and it’s called Mark Directory as | Project Sources and Headers.

      • Don Griffin says:

        August 7, 2019

        (CLion 2019.1) Doing that does not fix complaints on imports of my python code. If I Mark Directory as | Library Files, the imports work and Go To Definition seems to work. Is there a right-er way?

        • Anastasia Kazakova says:

          August 7, 2019

          If that works for you, then why not. We probably have to investigate deeper on how Mark Directory As affects other languages than C++ in CLion.

  9. Alexander Johnson says:

    May 8, 2019

    I’ve tried several times over the last couple of years to make CLion resolve my Python imports. I always fail. I’m tired of using it as a crippled text editor.

    Let’s say I have a directory in my project called src/lib/python. All I want is some setting in CLion which is equivalent to adding this directory to my PYTHONPATH. In other words: I want CLion to resolve references to code in src/lib/python/foo when I call “import foo” from any another Python script in the project (including tests). How do I do this?

    • Anastasia Kazakova says:

      May 8, 2019

      Do you have a CMake project?

      • Alexander Johnson says:

        May 9, 2019

        I don’t. It’s a mixed project containing several different languages. I’m using CLion for the remote toolchain support. There’s a Makefile, but no CMakeLists.txt.

        I read yesterday that CLion has a bug where it won’t give you all the options on the context menus (IE: mark directory as source root) if CMake isn’t set up for the project. On a whim, I tried manually editing the project’s .iml file to include src/lib/python as a source root and test/lib/python as a test root since the GUI options were missing. This worked.

        I’m extremely pleased to finally have autocomplete suggestions and ‘go to source’ functionality for my own code!

        • Anastasia Kazakova says:

          May 9, 2019

          Unfortunately, this is now not supported. CLion can work only with CMake, compilation database or Gradle projects. It requires a project model to get all the information about the files in project, their compilation options, flags, header search paths, etc. to be able to resolve the code correctly and provide code insights.

Subscribe

Subscribe for updates