2019.3 EAP 1

The first Early Access Program (EAP) for PyCharm 2019.3 is now available to be downloaded from our website!

New in PyCharm

Use macros as parameters to run scripts

macros

We added a new possibility to customize your script execution with macros now available to be set as parameters in the Python run configuration. Use macros such as $ClipboardContent$ to get the content of the clipboard, $FilePath$ to retrieve the file path of the open file, $ModuleSdkPath$ for the project interpreter path or $Prompt$ for a string input dialog on running the configuration to be used as parameters in your script execution.

To set them go to the Run/Debug Configurations dialog, select the script you wanna configure from the list of the Python run/debug configurations. Then, click + in the Parameters field and select a macro from the list of the available macros.

Scale and configure preview area for Jupyter notebook file

zoom-in-feature-low-rate

Scale the preview area for a Jupyter notebook file according to your needs. Either zoom in and out directly (using Ctrl (Windows) or Cmd (macOS) + mouse wheel) on the preview area or configure the default font size by opening Settings/Preferences ⌃⌥S, select Build, Execution, Deployment | Jupyter dialog, deselect Use Font Editor Size, and choose the required size in the Font Size field.

Markdown support for PyCharm Community Edition

The Markdown editor is now available for PyCharm Community Edition. Now you can expect to manage headings, apply formatting to text, use completion capabilities to add links to other project documents or images, insert code blocks for various programming languages, and visualize DOT or PlantUML diagrams all from the Community Edition.

Further improvements

  • An issue that wasn’t allowing proper autocomplete import references with same namespaces was solved.
  • Fixes were made for unexpected warnings on assignment expressions for Python 3.8.
  • Auto-imports and suggested imports now show options in an organized order.
  • We fixed an issue causing Python interpreter not to be properly set if downloaded from the Windows Store.
  • For more details on what’s new in this version, see the release notes

Interested?

Download this EAP from our website. Alternatively, you can use the JetBrains Toolbox App to stay up to date throughout the entire EAP.

If you’re on Ubuntu 16.04 or later, you can use snap to get PyCharm EAP, and stay up to date. You can find the installation instructions on our website.

Posted in Early Access Preview | Leave a comment

PyCharm 2019.2.2

PyCharm 2019.2.2 is now available. This version solves regression issues and improves Jupyter Notebook configuration experience.

New in this Version

  • Some code insight fixes were implemented for Python 3.8:
    • Now the “continue” and “finally” clauses are allowed to be used.
    • Support for unicode characters in the re module was added.
  • An error on the Python Console that was not showing documentation for functions was resolved.
  • Some issues were solved for IPython that were causing the debugger not to work properly.
  • We had some regression issues with the debugger causing breakpoints to be ignored and/or throw exceptions and the data viewer not to show the proper information and those were solved.
  • A problem that caused PyCharm to stall when a Docker server was configured as remote python interpreter was fixed.
  • An issue that was causing one remote interpreter not be used from two different machines was solved as well.
  • For Jupyter Notebook:
    • Default kernel specification selection is now based on the Python version for the module where a new notebook is created and in case the kernel specification is missing from the metadata a proper error message will be shown.
    • User selected kernel was mistakenly reseted when a notebook file was reopened and that was solved.
    • We encounter an issue that caused PyCharm to stall when switching from a non available Jupyter server to another and that was fixed.

Further Improvements

  • New compare with action feature to show database tables differences.
  • Enhanced full text search for databases now shows alphabetically ordered results.
  • Several platform issues were solved as well and much more, check out our release notes for more details.

Getting the New Version

You can update PyCharm by choosing Help | Check for Updates (or PyCharm | Check for Updates on macOS) in the IDE. PyCharm will be able to patch itself to the new version, there should no longer be a need to run the full installer.

If you’re on Ubuntu 16.04 or later, or any other Linux distribution that supports snap, you should not need to upgrade manually, you’ll automatically receive the new version.

Posted in Release Announcements | Leave a comment

Webinar: “10 Tools and Techniques Python Web Developers Should Explore” with Michael Kennedy

Building web applications is one of Python’s true superpowers. Yet, the wide-open ecosystem means there are SO MANY CHOICES for any given project. How do you know whether you’re using the right tool for the right problem?

  • Wednesday, September 25th
  • 6:00 PM – 7:00 PM CEST (12:00 PM – 1:00 PM EDT)
  • Register here
  • Aimed at intermediate Python developers

webinar2019_watch the recording-17

In this webcast, you will go on a tour of modern Python-based web techniques and tooling. We’ll see how to get the most out of your web app’s scalability with async and await. Host multi-container applications in Docker Compose. Leverage the popular and powerful JavaScript front-end frameworks when it makes sense. We’ll cover these and much more during the webcast.

Speaking To You

Michael Kennedy is the host of Talk Python to Me and co-host of Python Bytes podcasts. He is also the founder of Talk Python training and a Python Software Foundation fellow. Michael has a PyCharm course and is co-author of the book Effective PyCharm. Michael has been working in the developer field for more than 20 years and has spoken at numerous conferences.

Posted in Webinar | Tagged | Leave a comment

PyCharm 2019.2.2 Preview

PyCharm 2019.2.2 Preview is now available!

Fixed in this Version

  • Some code insight fixes were implemented for Python 3.8:
    • Now the “continue” and “finally” clauses are allowed to be used.
    • Support for unicode characters in the re module was added.
  • An error on the Python Console that was not showing documentation for functions was resolved.
  • Some issues were solved for IPython that were causing the debugger not to work properly.
  • We had some regression issues with the debugger causing breakpoints to be ignored and/or throw exceptions and the data viewer not to show the proper information and those were solved.
  • A problem that caused PyCharm to stall when a Docker server was configured as remote python interpreter was fixed.
  • Jupyter Notebooks got some fixes: kernel specification selection is now based on the Python version for the module where a new notebook is created and in case the kernel specification is missing from the metadata a proper error message will be shown.
  • An issue that caused one remote interpreter not be used from two different machines was solved as well.
  • And many more fixes, see the release notes for more information.

Getting the New Version

Download the Preview from Confluence.

Posted in Release Announcements | Leave a comment

PyCharm 2019.2.1

PyCharm 2019.2.1 is available now!

New in this Version

  • PyCharm now recognizes ctypes Arrays so now you won’t get wrong inspection messages when defining or using such arrays.
  • We had a bug that made Tensorflow’s references to be unresolved and that was also fixed.
  • The PyCharm debugger got some fixes:
    • The issue causing the debugger to hang when a syntax error was encountered was resolved.
    • When classes were given certain names, the debugger would be unable to inspect their variables, this is no longer a problem.
    • Exceptions thrown when debugging a project with multiprocessing modules will not stop the debugger anymore.
    • An issue that caused debugger functions like “Step into” to not work properly in our latest release was solved.
    • We had a bug that caused the debugger not to run normally when using Matplotlib and it was solved.
  • An error displayed when trying to run Jupyter Notebook’ cells using managed and configured Jupyter servers that was not allowing Jupyter cells to run is now resolved.
  • We improved Jupyter’s server response error messages to be more user friendly.
  • A bug we had for imported names that was causing them to be imported again after inlining a function was fixed.
  • AltGr keymaps for certain characters that were not working are now fixed.

Further Improvements

  • New SQL completion suggestions of join conditions based on column or table name match and auto-inject SQL by literals.
  • Some JavaScript and Vue.js inspection issues were resolved.
  • And more, check out our release notes for more details.

Getting the New Version

You can update PyCharm by choosing Help | Check for Updates (or PyCharm | Check for Updates on macOS) in the IDE. PyCharm will be able to patch itself to the new version, there should no longer be a need to run the full installer.

If you’re on Ubuntu 16.04 or later, or any other Linux distribution that supports snap, you should not need to upgrade manually, you’ll automatically receive the new version.

Posted in Release Announcements | Leave a comment

Python 3.8 support in PyCharm

The release of Python 3.8 brought new features to the Python coding realm. The language is evolving according to its community’s needs by addressing cases where new syntax or logic become necessary. From new ways of assigning expressions to restriction of usage of function declarations, calls, and variable assignations, this latest release presents new options to code. Of course, PyCharm couldn’t get behind, so we now support some of the major features coming with this new version.

This article will walk you through the features currently supported by our latest PyCharm release. To try them out, get the latest version of PyCharm and download the current beta release of Python 3.8 from here. From there you will just need to switch to Python 3.8 as your interpreter in PyCharm (if you’re not sure how to switch the interpreter, jump into our documentation for help).

Positional-only parameters

Function definitions are a key element when designing libraries and APIs for user consumption. The more explicit these definitions are, the easier they are to implement. One way to achieve such explicitness is by how the function can be called with its arguments. As of now, Python only had the option to define arguments as positional, keyword, or keyword-only, but with this new version we now have another way to define them by using positional-only parameters.

To use this feature, just set the arguments in your function definition and write a forward slash/ after the last positional-only argument you want to declare. This is closely analogous to the keyword-only arguments syntax, but instead of setting the arguments after the asterisk*, you do it before the slash/.

Let’s look at an example. Say, you have a function in your library that selects a value randomly from different values passed as arguments. Such values can be passed in any position and the function will return you a random choice. The semantic meaning stays the same, regardless of the order of the values in the function call. By design, you decide that those arguments should be positional-only:

positional-only-random

By doing this, you ensure that your library’s users won’t be able to call your function with the arguments’ keywords. In the past, if you renamed the arguments of your function for refactoring purposes (or any other reason), the code of your library’s users would be at risk if they were to make a function call with keyword arguments (for example, select_random(a=3, b=89, c=54)). One of the advantages of positional-only parameters is that, if you decide to change the variable names in the function definition, your library’s users won’t be affected as there are no keyword dependencies in the function calls they make to begin with.

Assignment expressions

A new way to assign values to variables is available with this latest Python version. Now, expressions can also assign values as part of their declaration, which removes the necessity to initialize variables in advance. As a result, you can make your code less verbose and add compactness, as declarations can be made within expressions in the same line.

The syntax to declare a variable consists of the walrus operator := inside an expression enclosed by parentheses. An important note is that the walrus operator is different from the equals operator. For example, comma-separated assignments with the equals operator are not the same as the ones made by the walrus operator.

One example of such usage can be a while loop with a control variable. When you use this feature, the loop’s control expression will also hold the variable definition and reassignment.

assignment-expressions

In the previous example, the ‘before’ while loop has a variable assignment before it and also inside its execution code. The ‘after’ loop has the assignment inside its control statement definition by using an assignment expression.

Final annotation and final decorator

When you design a class, you have to make sure your methods are used properly. With this new version, a final decorator and a Final type annotation are introduced to help restrict the usage of methods, classes, and variables. If needed, this feature will let you declare that a method should not be overridden, that a class should not be subclassed, or that a variable or attribute should not be reassigned.

The final decorator prohibits any class decorated with @final from being subclassed, and any method decorated with @final from being overridden in a subclass. Let’s say you have a class that declares a method and that method is being used inside the class at different points. If the user modifies that method by overriding it while subclassing, there are risks that the base class behavior might change or run into errors. To avoid this, you can use the final decorator to prevent the user from overriding such a class.

Let’s say you have a signature generator class like the following:

final-decorator-attribute

When initialized, the signature is generated through a create_signature method which is called within the __init__ constructor method. Depending on your class design, you may opt to protect your create_signature method with the final decorator so it is not overridden if subclassed. With the final decorator, you ensure that any other method that depends on this method inside the class is not affected by a method override. In this case, the __init__ constructor method is using the create_signature method. By using the final decorator, you ensure that the initialization of the class will not be affected by any change that might be introduced by subclassing.

Another thing to notice is that in this example, we use the Final attribute with the ENCODER attribute. This class attribute holds the type of string encoding used in the create_signature method. By class design, we choose to use the Final attribute because we use that value within the methods of the class and we don’t want it to be overridden as that would change the methods’ behavior.

Equals sign in f-strings

String formatting makes code more concise, readable, and less prone to error when exposing values. Variable names and values now can coexist in string contexts with the introduction of the equals sign in f-strings.

To take advantage of this new feature, type your f-string as follows: f'{expr=}' where expr is the variable that you want to expose. In this way, you get to generate a string that will show both your expression and its output.

f-strings-equals

This feature is helpful when you’d like to write variable values to your log. If you happen to use this for debugging purposes, you may want to check out PyCharm’s debugger.

Learn more

For more information about usages and examples where these features can be useful, take a look at PEP-0570, PEP-0572, PEP-0591, and bpo-36817.

We at PyCharm continue to work on supporting Python 3.8 fully, and we hope these features will come in handy for you when setting up or working with a project using Python 3.8. Support for other features should be expected in the near future, so be sure to pay close attention to our latest releases.

If you have any questions or suggestions, drop us a comment. Thanks!

Posted in Education | Leave a comment

PyCharm 2019.2.1 RC

PyCharm 2019.2.1 release candidate is available now!

Fixed in this Version

  • An issue that caused debugger functions like “Step into” to not work properly in our latest release was solved.
  • AltGr keymaps for certain characters that were not working are now fixed.

Further Improvements

  • New SQL completion suggestions of join conditions based on column or table name match and auto-inject SQL by literals.
  • Some JavaScript and Vue.js inspection issues were resolved.
  • And more, check out our release notes for more details.

Getting the New Version

Download the RC from Confluence.

The release candidate (RC) is not an early access program (EAP) build, and does not bundle an EAP license. If you get the PyCharm Professional Edition RC, you will either need a currently active PyCharm subscription, or you will receive a 30-day free trial.

Posted in Early Access Preview | Leave a comment

PyCharm 2019.2.1 Preview

PyCharm 2019.2.1 Preview is now available!

Fixed in this Version

  • The PyCharm debugger got some fixes:
    • The issue causing the debugger to hang when a syntax error was encountered was resolved.
    • When classes were given certain names, the debugger would be unable to inspect their variables, this is no longer a problem.
    • Exceptions thrown when debugging a project with multiprocessing modules will not stop the debugger anymore.
  • PyCharm now recognizes ctypes Arrays so now you won’t get wrong inspection messages when defining or using such arrays.
  • We had a bug that made Tensorflow’s references to be unresolved and that was also fixed.
  • An error displayed when trying to run Jupyter Notebook’ cells using managed and configured Jupyter servers that was not allowing Jupyter cells to run is now resolved.
  • We improved Jupyter’s server response error messages to be more user friendly.
  • And many more fixes, see the release notes for more information.

Getting the New Version

Download the Preview from Confluence.

Posted in Release Announcements | Leave a comment

Jupyter, PyCharm and Pizza

Hi there! Have you tried Jupyter Notebooks integration in PyCharm 2019.2? Not yet? Then let me show you what it looks like!

In this blog post, we’re going to explore some data using PyCharm and its Jupyter Notebook integration. First, of course, we’ll need said data. Whenever I need a new dataset to play with, I typically head to Kaggle where I’m sure to find something interesting to toy with. This time a dataset called “Pizza Restaurants and the Pizza They Sell” caught my attention. Who doesn’t love pizza? Let’s analyze these pizza restaurants and try to learn a thing or two from it.

Since this data isn’t a part of any of my existing PyCharm projects, I’ll create a new one.
Make sure to use PyCharm Professional Edition, the Community Edition does not include Jupyter Notebooks integration.

Create new PyCHarm project

Tip: When using Jupyter notebooks in the browser, I tend to create multiply temporary notebooks just for experiments. It would be quite tedious to create a PyCharm project for each of them, so instead, you can have a single project for such experiments.

I like my things organized, so once the project is created, I’ll add some structure to it – a directory for the data where I’ll move the downloaded dataset, and another directory for the notebooks.

Once I create my first pizza.ipynb notebook, PyCharm suggests to install Jupyter package and provides a link in the upper right corner to do that.

Install Jupyter package

Once the Jupyter package is installed, we’re ready to go!

The first thing that probably 90% of data scientists do in their Jupyter notebooks is type import pandas as pd. At this point, PyCharm will suggest installing pandas in this venv and you can do it with a single click:

Install Pandas

Once we have pandas installed, we can read the data from the csv into a pandas DataFrame:
df = pd.read_csv("../data/Datafiniti_Pizza_Restaurants_and_the_Pizza_They_Sell_May19.csv")

To execute this cell, hit Shift+Enter, or click the green arrow icon in the gutter next to the cell.
When you run a cell for the first time, PyCharm will launch a local Jupyter server to execute the code in it – you don’t need to manually do this from your terminal.

Let’s get to know the data. First, we’ll learn the basic things about this dataset – how many rows does it have? What are the columns? What does the data look like?

First look at the data

I have a suspicion that this data contains information only on restaurants in the US. To confirm this, let’s count the values in the country column:

Count unique values in country column

Yep, the only country presented in this dataset is US, so it’s safe to drop the country column altogether. Same goes for menus.currency and priceRangeCurrency, those values too are all the same – USD. I’ll also drop menuPageURL as it doesn’t add much value to the analysis, and key as it duplicates the information from other columns (country, state, city, etc.).

Another cleanup that I’ll do here is rename province column into states as it makes more sense in this context, and for better readability, I’ll replace the state acronyms with full names of the states.

Data cleanup

Once we’re done with cleaning the data, how about we plot it? As humans, we are better at understanding information when it’s presented visually.

First, let’s see what are the most common types of pizza we have in this dataset. Given the theme, it feels appropriate to visualize this as a pie with matplotlib :)

Pizza pie plot

Oops, where’s my pie? To have it displayed, I need to add %matplotlib inline magic command for IPython, and while I’m at it, I’ll add another magic command to let IPython know to render the plots appropriately for retina screen.

I could add these lines to the same cell and run it again, but I prefer to have this type of magic commands defined at the very beginning of the notebook.

To navigate to the very beginning of the notebook, you can use Cmd+[ (Ctrl+Alt+Left on Windows). Inserting a new cell is as easy as typing #%% (if you prefer a shortcut to insert a cell above your current one, there’s one! Option+Shift+Aon mac, or Alt+Shift+A on Windows). Now all I need to do is add the magic commands and run all cells below:

Run Below

And voila! Now we know that the most common type of pizza is Cheese Pizza closely followed by White Pizza.

Pie plot

What about the restaurants? We have their geographical locations in the dataset, so we can easily see where they are located.

Each restaurant has a unique id and can have multiple entries in the dataset, each entry representing a pizza from that restaurant’s menu. So to plot the restaurants and not the pizza, we’ll need to group the entries by restaurant id.

Unique restaurants

Now we can plot them on a map. For geographical plotting, I like to use plotly. Make sure to grab the latest version of it (4.0.0) to have plotly outputs rendered nicely in PyCharm.

Pizza restaurants on a map

What else can we learn from this data? Let’s try something a little more complicated. Let’s see what states have the most pizza restaurants in them. To make this comparison fair, we’ll count the restaurants per capita (per 100 000 residents). You can get the population data for the US and multiple other datasets at https://www.census.gov/.

Pizza restaurants per capita

And the winner is… New York!

One can think of a number of questions we can try to get answered with this dataset, like, what city has the most/least expensive Veggie Pizza? Or what are the most common pizza restaurant chains? If you want to toy with this dataset and answer these or other questions, you can grab it on kaggle and run your own analysis. The notebook used in this blog post is available on GitHub. And if you want to try it with PyCharm, make sure you’re using PyCharm 2019.2 Professional Edition.

Posted in Tutorial | Tagged , , | 3 Comments

PyCharm 2019.2 Out Now

PyCharm 2019.2 is out now: improved Jupyter Notebook experience, syntax highlighting for many more languages out of the box, initial Python 3.8 support, and much more. Download now

New in PyCharm

  • Jupyter Notebook Integration has been improved. Some of the most highly requested Jupyter Notebook features have been implemented in this version. Now you will be able run all cells with a single button click, select and configure your Jupyter server using a specific project and port to listen to, keep track of variables while debugging them by getting their current state, restart the kernel and publish notebooks from PyCharm to JetBrains Datalore .
  • Syntax highlight support for many other languages has been added. Do you work on projects where code in a different language sneaks into your project? PyCharm will now highlight the syntax of Windows .bat files, C#, C++, Groovy, Lua, Makefiles, and more.
  • We are adding support for some major Python 3.8 features. Try out positional-only parameters, variable assignment within expressions, ‘Final’ qualifier to restrict usage of methods, classes and variables, and new ways to use f-strings to present values and variables.
  • cURL format is now supported for HTTP requests. Just copy your cURL formatted request and paste it directly into your HTTP Request file for it to be converted into its format, and then feel free to modify request params, headers, or body.

Many more features, like cookies preservation between http requests and improved debugging and variable refactoring experiences. Learn more about PyCharm 2019.2 on our website

You can also find the details about our release, in the release notes.

Upgrade Now

To get the new version of PyCharm, upgrade in one of the following ways:

Do you have questions, complaints, or suggestions? Please reach out to us! Send questions to our support team, report bugs and suggestions on our issue tracker, or just connect with us on Twitter.

Posted in Release Announcements | Tagged | 2 Comments