The PyCharm console

The PyCharm console is another fundamental part of PyCharm. In essence, it's the Python REPL with autocompletion and variable watch (which we will get into later). Right now, let's take a look at what the console offers us:

The PyCharm console

You can of course invoke the same action from the Find Action and Search Everywhere search boxes. This opens up the following:

The PyCharm console

Most buttons are self-explanatory, except for the two indicated by the arrows. The first is what I like to call variable watch; in essence, this shows you all the variables in your console (by pressing it, you toggle it):

The PyCharm console

New variables and the changes in variables are shown in blue:

The PyCharm console

The Variable Watch button is even more powerful, but that's a topic for Chapter 6, Debugging.

The second button after variable watch is actually pretty useful; it's a history of all the commands you've entered into your console throughout the project, so even if you close PyCharm or even shut down your system, the history will have dutifully recorded all the Python statements that you have entered:

The PyCharm console

Console configuration

Now let's head over to a few of the options that we have for our Python console:

Console configuration

With reference to the preceding screenshot, with [1], we can define our environment variables:

Console configuration

With this, you can now see the environment variables in the console (make sure that you restart your console):

Console configuration

With that out of the way, you can set the path to your interpreter with [2], and provide additional arguments with [3]. The working directory can be specified with [4]. Enabling [5] simply adds your project root to the PYTHONPATH:

Console configuration

You can also add your source directories to your PYTHONPATH by enabling [6]. You can make a directory a source directory by doing this:

Console configuration

With that, when you open up your console with [6] enabled, you can see that PyCharm adds the directory to the PYTHONPATH, and hence, you can import files from that directory:

Console configuration

As you can see, you can also get code completion for the .py file inside the src directory.

Last but not least, we come to the Starting script, [7]. With this, you can specify the Python code that the interpreter will run at every launch. Note that you also get code completion here:

Console configuration

With this, you can see it imported:

Console configuration

Tip

If you want to use IPython in PyCharm, all you have to do is install the IPython package, and PyCharm will automatically launch the IPython interpreter for you when you launch the console.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.22.181.81