PyCharm 2017.1.2 out now

PyCharm 2017.1.2 is out now! Get it from our website

Some of the things we’ve improved:

  • We’ve been working hard on resolving regressions in our new test runners, if you’ve had an issue with the 2017.1 test runners, please upgrade to this version.
  • The problem with SFTP deployment has been resolved
  • Fixes for the Debugger, Django and Docker
  • And several other bugs were fixed: read our release notes for details

If you have any feedback about this version of PyCharm, please let us know! You can report bugs and request features on YouTrack. You can also reach us by leaving a comment on this blog post, by tweeting us at @pycharm or leaving a comment on our Facebook page.

PyCharm Team
-The Drive to Develop

Posted in Release Announcements | Tagged | 3 Comments

Webinar Recording: Visual Debugging

Our April 25th webinar on Visual Debugging went quite well: just over 1 hour, a lot of fun, and covered nearly all of the topics. The recording is now available on YouTube. Additionally, the code and slides used are available in a GitHub repository.

“Visually Debugging” is a theme that we plan to touch on repeatedly during 2017. For example, we have tutorial proposals for DjangoCon and EuroPython that expand on the topics in this webinar, conducted in a hands-on, 3-hour format.

About Visual Debugging

PyCharm puts a visual face on debugging and we’d like to help more developers take the plunge and debug. In this webinar, Paul Everitt, PyCharm Developer Advocate, introduced the debugger and went through many of the essentials in the context of writing a 2d game.

This webinar was aimed at developers who have never used the debugger, but even those familiar with PyCharm’s visual debugging will learn some new tricks and see some deeper usages.

Video Contents

1. (3:05) Debugging without PyCharm’s debugger: print and pdb
2. (6:18) First use of the debugger (and the Cython speedups)
3. (12:18) Interactive use
4. (19:47) Breakpoints
5. (29:16) Stepping
6. (40:43) Watch expressions
7. (44:11) Stack Frames
8. (48:17) Debugging during testing
9. (50:22) Attaching to processes
10. (52:11) Extracting type information
12. (58:52) Extra credit: Debugging JavaScript in Node and Chrome, configure stepping, keyboard shortcuts, show execution points, mute breakpoints, inspect watch value

Keep up with the latest PyCharm news on our blog and follow us on Twitter @PyCharm.

Posted in Video, Webinar | Leave a comment

PyCharm 2017.1.2 Release Candidate

Today we announce the PyCharm 2017.1.2 Release Candidate build #171.4249. The list of bug fixes and improvements for this build can be found in the release notes.

Some highlights of the PyCharm 2017.1.2 RC are:

  • A number of important fixes for the debugger
  • Fixes for the test runner
  • Fixes for Django and Docker support
  • and much more

Please give PyCharm 2017.1.2 RC a try before its official release and please report any bugs and feature request to our issue tracker.

Posted in Early Access Preview | Tagged | 5 Comments

Docker-Compose: Adding a Database Service

This tutorial continues where the previous Docker-Compose tutorial left off. If you haven’t read it yet, read about getting Docker-Compose and Flask running in PyCharm first. Like the first tutorial, this one was made on macOS, and although Linux should be similar there may be small differences. Unfortunately, Docker Compose currently isn’t supported on PyCharm for Windows.

We’ll continue by making a Flask version of the hottest web app from the 90s, a guest book:

Guest Book App

If you’d like to play along at home, or just have a look at the full code. You can find the code on GitHub. The code in the ‘master’ branch is for the previous tutorial, switch to the ‘with-database’ branch for the code for this tutorial.

Adding the Database

The first thing we need to do is to tell Docker that we would like to have a database as well. So let’s add a postgres service to our compose file. We do this by adding a service, we’ll use the postgres image from Docker hub, and configure it using environment variables. Read the postgres image’s description on Docker Hub for more information on its configuration:

We’ll also link the database from our web service, so we’re sure that the database is started whenever we start the web service.

Setting Up the Database

The next step is to connect PyCharm to the database. We exposed port 5432 in the compose config to ensure that we can connect to it from our host machine.

The first step is to build our containers, let’s open the terminal in PyCharm (press Alt+F12), and run docker-compose up --build.

After Docker Compose has started the containers, we can connect to it in the databases panel. Open it in View | Tool Windows | Database. Then, add a database connection to a PostgreSQL database:

Now we can configure the connection using the credentials we used in our compose file:

PostgreSQL connection settings

Keep in mind that by default the postgres image will name the database after your username.

If you’re having connection trouble: read the output of the docker-compose up command in the terminal to see if any issues occurred. And if everything looks right, also use lsof -i tcp:5432 and verify whether docker is listening on port 5432.

Now that we’ve got a connection, let’s add a table for our guest book. To make our app fit in slightly better in this century, we’ll add a 140 character limit to the posts. Our table definition should look like this:

  • id – int – primary key – serial (auto increment)
  • author – varchar(50)
  • comment_text – varchar(140)
  • posted_at – timestamp

Let’s use PyCharm’s database integration to create this table: 

Guestbook table

After creating the table, we can copy the DDL for the table into an SQL file by using the generate and copy DDL option from the context menu:

After we’ve copied it, create a new file ‘schema.sql‘, and paste it there (Cmd+V). We will just leave it there, if you’d like to learn more about executing these files using Flask, see the Flask documentation.

Writing the Application

Let’s create a simple page where the user can see recent posts, and post something new. We’ll need to connect to the database, so firstly we should add psycopg2 to the requirements file. You could of course use an ORM, but I actually like SQL, so I’ll just use psycopg2 directly. Let’s also add ‘humanize’ to the requirements so we can display the time in a nicer way.

After we’ve added the requirements, we need to rebuild the containers: the requirements are installed in one of the early steps in our Dockerfile. Let’s open the terminal (Alt+F12 within PyCharm), and run docker-compose build.

If we want to make PyCharm aware of the new packages in the Docker container, we need to reload the interpreter paths: go to Settings | Project | Project Interpreter, then use the ‘…’ button next to the selected interpreter and click ‘More’: Interpreter overview

Then, at the bottom of the interpreter overview, click the interpreter path button:

Go to Interpreter Paths

On the paths window, click ‘Reload paths’. It will look like nothing happened, but the paths will be reloaded after you’ve closed the settings windows:

Reload Paths

And then click ‘Close’ on all of the windows you’ve just opened, PyCharm will now index the new packages.

Now that’s done, we can start to expand our Flask app. First, I’ll add get_db and close_db functions to connect and disconnect from PostgreSQL, see the Flask documentation for more details. To see my implementation, have a look at GitHub.

Let’s rename the hello_world route to show_guestbook, and add some code:

Keep in mind that when you’re writing SQL in PyCharm, you can get code completion by pressing Alt+Enter, and then choosing “Inject language or reference”, and then selecting “PostgreSQL”. Similarly, we’ll add an add_post route to add a post to the guestbook:

Note how we’re inserting the user input in the tuple provided as a second argument to cursor.execute(). Please don’t ever interpolate user input directly, it leads to bad things.

To see the template and CSS file, check out GitHub.

At this point the Flask app is ready, and we can use the PyCharm ‘run’ and ‘debug’ buttons to use the run configuration we set up in the previous tutorial:

Debugging Flask in Docker Compose

Let us know what you’re developing with Docker Compose in the comments!

PyCharm Team
-The Drive to Develop

Posted in Tutorial | Tagged | 1 Comment

Webinar: “Visual Debugging” on April 25

Are you a Python developer who knows you should use the debugger, but don’t yet? Or perhaps you are familiar with debugging, but know there is more productivity if you’d spend some time to learn?

pycharm_webinar_Visual_Debugging

PyCharm puts a visual face on debugging and we’d like to help more developers take the plunge and debug. In this webinar, Paul Everitt, PyCharm Developer Advocate, introduces the debugger and goes through many of the essentials in the context of writing a 2d game:

– Debugging without PyCharm’s debugger: print and pdb
– First use of the debugger (and the Cython speedups)
– Breakpoints
– Using the console/IPython at a breakpoint
– Exception and Conditional breakpoints
– All flavors of stepping through code, including filters
– Moving through stack frames
– Setting watches
– Django/Jinja2 template debugging
– Attaching to processes
– Debugging during testing
– Viewing numpy/pandas data frames
– Extracting type information

This webinar is aimed at developers who have never used the debugger, but even those familiar with PyCharm’s visual debugging will learn some new tricks and see some deeper usages.

Paul Everitt is the PyCharm Developer Advocate at JetBrains. Before that, Paul was a co-founder of Agendaless Consulting and a co-founder of Zope Corporation, taking the first open source application server through $14M of funding. Paul has bootstrapped both the Python Software Foundation and the Plone Foundation. Prior to that, Paul was an officer in the US Navy, starting in Python and launching www.navy.mil in 1993.

Posted in Uncategorized | 2 Comments

PyCharm 2017.1.1 Available Now

PyCharm 2017.1.1 is out now! Get it from our website

Some of the things we’ve improved:

  • The font rendering problem has been resolved
  • Many issues in the debugger, code inspections, and test runners have been fixed, including several additional issues since the last release candidate
  • Automatic deployment for new remote projects is now configured correctly
  • Remote Jupyter notebooks tweaks
  • And more: read our release notes for details

If you have any feedback about this version of PyCharm, please let us know! You can report bugs and request features on YouTrack. You can also reach us by leaving a comment on this blog post, by tweeting us at @pycharm or leaving a comment on our Facebook page.

PyCharm Team
-The Drive to Develop

Posted in Release Announcements | Tagged | 8 Comments

PyCharm 2017.1.1 RC out now

We’ve been fixing a lot of bugs, and are getting closer to the 2017.1.1 release. If you’d like to try this version before we release it, you can get it now from our confluence page.

Some of the things we’ve improved:

  • The font rendering problem has been resolved
  • Many issues in the debugger, code inspections, and test runners have been fixed
  • Automatic deployment for new remote projects is now configured correctly
  • Pyramid improvements
  • Remote Jupyter notebooks tweaks
  • And more: read our release notes for details

If you have any feedback about this version of PyCharm, please let us know! You can report bugs and request features on YouTrack. You can also reach us by leaving a comment on this blog post, by tweeting us at @pycharm or leaving a comment on our Facebook page.

PyCharm Team
-The Drive to Develop

Posted in Early Access Preview | Tagged | 5 Comments

PyCharm Edu: The Adaptive Python Course

Back in 2016, we partnered with Stepik to announce a brand-new Python course. It adapted to each student’s level of knowledge and interest and helped them stay more motivated and productive while learning Python. This course was the first step towards adopting Adaptive Learning, which we believe is one of the key trends in the future online education.

After an adoption period, we’ve fixed all the issues in the latest PyCharm Edu 3.5.1. The Adaptive Python course is now polished and ready to use! Let’s explore it in more detail.

The Adaptive Python Course

To start the course, go to File -> New Project -> Educational and choose Adaptive Python from the list:adaptive_python_1

Continue reading

Posted in Cool Feature | Tagged | 1 Comment

Docker-Compose: Getting Flask up and running

A couple of issues were resolved in PyCharm 2017.1, and Docker for Mac should now work out of the box. In this blog post we’ll show you how to set up a project with Docker Compose on a Mac. If you’re on Linux, the process is very similar. Unfortunately, we don’t support Docker Compose on Windows at this time. If you’re using Docker Compose on Windows, please let us know in the comments.

In this tutorial we’ll show how to create a very simple ‘Hello World’ Flask application, and then how to run it within a Docker container. For the full code, and to follow along, see GitHub: https://github.com/ErnstHaagsman/flask-compose.

First things first

Before we get started, let’s check a couple of things: make sure you are using PyCharm 2017.1 Professional Edition or later. Docker support is not available in PyCharm Community Edition. Then, please ensure your Docker and Docker Compose are up to date. To check, open a terminal, and run docker -v, and docker-compose -v:

Docker and Compose Versions

Then, although it is the default setting in PyCharm 2017.1, it never hurts to check that your Docker API URL (Preferences | Build, Execution, Deployment | Docker) is set to unix:///var/run/docker.sock.

Docker Settings

Now we can create a new Flask project. Let’s create a virtualenv so that PyCharm can stub out our Flask project before we have Docker configured. You can create a Virtualenv by using the ‘…’ button next to the interpreter dropdown.

Create a Flask Project

Dockerizing Flask

After you click create, you should see the standard “Hello World” Flask template. So let’s see if we can get Flask to show us “Hello World” from a Docker container. To do this, we’ll add four files:

  • requirements.txt, just put “Flask==0.12” here to install Flask
  • Dockerfile, where we will set up the Python environment for the Flask app
  • docker-compose.yml to set up how to run the Dockerfile, and add a database
  • docker-compose.dev.yml to make some changes for local development

In the Dockerfile, we’ll use the ‘python:3’ image, expose port 5000, install packages from requirements.txt, and afterwards copy the rest of our project into /app. See the full file on GitHub.

Then, we’ll create a Compose file where we define the Flask app as our only service (for now). Just use build: . to make Docker Compose build the container from the Dockerfile.

Docker will bake our code into the image, and that way the image is self-contained. If we wanted to, we could stop here and rebuild our image whenever we change the code. It makes development quite a bit faster to mount our code with a volume. So we’ll create an additional Compose file to do that while we’re developing.

In docker-compose.dev.yml, all we’re doing is adding a volume mapping for .:/app for the web service. This overlays the code in the container with a volume, making sure that code changes are applied immediately. Keep in mind that you will need to rebuild the image before pushing it anywhere.

Now that everything is configured, let’s quickly run docker-compose up in the Terminal to make sure that works. Open the terminal with Alt+F12 (in PyCharm) and run docker-compose up.

Docker-compose up on the terminal

As we can see, Docker built our container, and Flask is running! Let’s go and check out our ‘Hello World’ message!

A trap for young players!

Safari couldn't open the page

What happened here? Didn’t docker say that Flask was running?

For security reasons, many modern web frameworks actually limit incoming connections to only come from localhost. This means that our Flask app is running, but only accessible from within the Docker container, not from our Mac host. The easiest way to fix this is to add host='0.0.0.0' as a keyword argument to app.run() in flask-compose.py:

Flask, exposed

This change tells Flask to listen not only to requests from localhost (in this case the docker container), but on all network connections. In the case of our container this means we can access it from our host, and depending on configuration from other computers in our network.

If we now stop our container (Ctrl+C in the PyCharm Terminal), and rebuild it by running docker-compose up --build. We can see in the Docker Compose output that Flask is now listening on 0.0.0.0 instead of 127.0.0.1:

Flask is listening on 0.0.0.0

And reloading the page in Safari actually shows ‘Hello World’ now. So let’s stop the container (Ctrl+C in the Terminal), and then configure PyCharm.

Configuring PyCharm

To make our project run using a PyCharm run configuration, we need to set the project interpreter to the Docker Compose service. We can do this from the Project interpreter page in preferences: Preferences | Project: <Project Name> | Project Interpreter.

Click the little button next to the interpreter dropdown (the white one, not the blue one), and choose “Add Remote”. If you don’t see “Add Remote” here, you may be using PyCharm Community Edition, which doesn’t support remote interpreters.

Add Remote Interpreter

Now choose “docker-compose”, and almost everything will be pre-configured, I only had to add the docker-compose.dev.yml configuration to the list. We need to add it manually as this isn’t part of a standard docker project. You can do this with the ‘+’ button underneath the list of configuration files.

Compose Configuration in PyCharm

Now, we should set up the path mapping. We are inserting all our project code into the container’s “/app” directory. So let’s add this on the Project Interpreter screen, use the ‘…’ button next to the Path mappings field to change them.

Path mappings

After you close the preferences window, you can just use the regular Run and Debug buttons to start and debug your project:

Debugging Flask within Docker

To celebrate, let’s change “Hello World!” to “Hello from Docker within PyCharm!”

Flask in Docker-Compose

And that’s all there’s to it! Have fun developing with Docker Compose! If you’d like to learn more, you can read the second part of this tutorial about adding a database service.

PyCharm Team
-The Drive to Develop

Posted in Tutorial | Tagged | 21 Comments

PyCharm 2017.1 Out Now: Faster debugger, new test runners, and more

PyCharm 2017.1 is out now! Get it now for a much faster debugger, improved Python and JavaScript unit testing, and support for the six library.

  • The Python debugger got forty times faster for Python 3.6 projects, and up to two times faster for older versions of Python
  • We’ve added support for the six compatibility library
  • Unit test runners for Python have been rebuilt from the ground up: you can now run any test configuration with PyCharm
  • Are you a full stack developer? We’ve improved our JavaScript unit testing: gutter icons indicating whether a test passed and support for Jest, Facebook’s JS testing framework (only available in PyCharm Professional edition)
  • Zero-latency typing is now on by default: typing latencies for PyCharm 2017.1 are lower than those for Sublime Text and Emacs
  • Support for native Docker for Mac – no more need to use SOCAT! (only available in PyCharm Professional edition)
  • And more!

Get PyCharm 2017.1 now from our website

Please let us know what you think about PyCharm! You can reach us on Twitter, Facebook, and by leaving a comment on the blog.

PyCharm Team
-The Drive to Develop

Posted in Release Announcements | Tagged | 33 Comments