PyCharm 2017.3.1

We have a couple of fixes and small improvements for you in PyCharm 2017.3.1. Update now on the website.

New in this version:

  • Several issues with running Python modules (-m) were resolved: running modules remotely, showing command line after running
  • Further issues with running code over SSH were resolved: they can now connect to IPv6 hosts from macOS, don’t misinterpret ProxyCommand: none, and correctly parse the HostKeyAlgorithms option (Connecting to a Python interpreter over SSH is only supported in PyCharm Professional Edition)
  • Code insight for SQLAlchemy was improved, the issue with ‘incorrect call arguments’ has been fixed.
  • And more, see the release notes for details

If you use multiple JetBrains applications, you can use JetBrains Toolbox to make sure all your JetBrains IDE’s stay up to date. PyCharm is also available as a snap package. If you’re on Ubuntu 16.04 or later, you can install PyCharm by using this command:

sudo snap install [pycharm-professional|pycharm-community] --classic

Posted in Release Announcements | Tagged | 5 Comments

Developing in a VM with Vagrant and Ansible

One of the things that could make developing cloud applications hard, would be differences between the dev environment and the production environment. This is why one of the factors of the twelve factor app is maintaining dev-prod parity. Today we’ll start a blog series about developing cloud applications, and we’ll discuss how to set up a local development environment using Vagrant.

We’ll use these technologies for this application:

  • Vagrant
  • Ansible
  • Flask
  • Virtualenv
  • Ubuntu

Today we’ll just create a simple Flask application that’ll say ‘Hello world’. In the next post in this series, we’ll introduce a larger application that we’ll deploy to AWS in a future post.

If you want to follow along at home, you can find the code from today’s blog post on GitHub. See the commit history there to see the progress from the beginning to the end.

Getting Started

So let’s create a project, and get started. If you want to follow along, you’ll need to have Vagrant, Virtualbox, and PyCharm Professional Edition installed on your computer.

Open PyCharm, and create a new pure Python project.

The first step will be to set up the Vagrant VM, and configure the necessary items. In the project folder, run vagrant init -m bento/ubuntu-16.04. You can run commands within PyCharm by opening the terminal (Alt + F12).

This generates a Vagrantfile that only contains the base box that we’re using. If we run vagrant up at this point, we’d get a plain Ubuntu server box. For our project we’ll need to install some things and expose some ports though, so let’s add this to the Vagrantfile:

The ansible_local provisioner will install Ansible on the Ubuntu VM and then run it there, this means we don’t need to install Ansible on our host computer. Ansible lets us describe the desired state for a computer, and will then make the necessary changes to achieve that state. So let’s have a look at what’s necessary to install Python 3.6 on the VM.

Provisioning a VM with Ansible

Ansible works with Playbooks. These are YAML files that describe what state should be applied to what machines. Let’s create setup.yml, and try to install Python 3.6:

A playbook is a list of plays on the top level. We can configure per play which hosts we want to apply it to, whether we need to become another user, and a list of tasks. In our example, we apply the play to all hosts: there’s only one host in the Vagrant setup, so that’s easy enough. We also set become to yes, which has the effect of running our tasks with sudo.

The tasks are the way we can configure the desired state of our VM. We can name our tasks to make it easier for us to see what’s going on, but Ansible doesn’t technically need it. The task we have here is just an instruction for Ansible to use the apt module, which is bundled with Ansible. We specify three options to the apt module:

  • The name of the package we’re interested in
  • The state we’d like the package to be in: present on the machine
  • Update the apt cache before installing

This last option basically means that Ansible will run apt update before running apt install, if necessary.

If you’re thinking, isn’t this just a very hard way to write sudo apt update && sudo apt install python3.6, at this point you’re right. However, the value of Ansible is that you’re not describing actions, but you’re describing a desired state. So the second time you run Ansible, it detects Python 3.6 is already installed, and it won’t do anything. Idempotence is one of Ansible’s core principles. Another key benefit is that you can version control changes to server configuration.

So let’s run vagrant up (Ctrl+Shift+A to Find action, and then type vagrant up), and we should have a VM with Python 3.6!

Trouble in Paradise

Unfortunately, Python 3.6 isn’t available from Ubuntu’s default package repositories. There are several ways to resolve this situation, the easiest would be to find a PPA (Personal Package Archive) which has Python 3.6.

A PPA which is mentioned in many places on the internet is Jonathon F’s PPA. So how would we go about adding this PPA using Ansible? Turns out there are two modules that can help us out here, apt_key and apt_repository. Apt_key allows us to specify the public key associated with the repository, to make sure any releases we get are really from Jonathon. And apt_repository then adds the repository to the apt configuration. So let’s add these two tasks to the playbook, before the install task (Ansible runs tasks in the order specified):

Now run vagrant provision (or Tools | Vagrant | Provision), to rerun the playbook. After completing, we should see the summary:

At this point, let’s create a requirements.txt with the libraries we’ll use today, in this case, just Flask:

Most Linux distributions use the system interpreter themselves, that’s one of the reasons for virtualenvs being best practice. So let’s create a virtualenv, and then install these packages. As the python-3.6 package didn’t include pip, we’ll first need to install pip. Then, using pip, we’ll need to install virtualenv into the system interpreter. After that we’ll be able to create a new virtualenv with the requirements we specify. To do this, specify at the end of the playbook:

First, we’re using the apt module to install pip. Then, we’re using Ansible’s pip module to install the virtualenv package. And finally we’re using the pip module again to now create the virtualenv, and then install the packages in the newly created virtualenv. Vagrant automatically mounts the project directory in the /vagrant folder in the VM, so we can refer to our requirements.txt file this way.

At this point we have our Python environment ready, and we could continue going the same way to add a database and anything else we might desire. Let’s have a look to see how we can organize our playbook further. Firstly, we’ve now hardcoded paths with ‘vagrant’, which prevents us from reusing the same playbook later on AWS. Let’s change this:

The first thing we can do is define variables for these paths. If the variable syntax looks familiar, that’s because it is: Ansible is written in Python, and uses jinja2 for templating.

If we were to add database plays to the same playbook, we’re mixing things that we may want to separate later. Wouldn’t it be easier to have these Python plays somewhere we can call them, and have the database plays in another place? This is possible using Ansible roles. Let’s refactor this playbook into a Python role.

Ansible roles are essentially a folder structure with YAML files that are used to specify the things necessary for the role. To refactor our plays into a Python role, we just need to create several folders: $PROJECT_HOME/roles/python/tasks, and then place a file called main.yml in that last tasks folder. Copy the list of tasks from our playbook into that file, making sure to unindent them:

Afterwards, specify in the playbook which role to apply:

That’s all there’s to it! To make sure everything runs smoothly still, run vagrant provision once more to make sure everything is applied to the VM.

Running Code from PyCharm

Now that we have a provisioned VM ready to go, let’s write some code!

First let’s set up the Python interpreter. Go to File | Settings | Project Interpreter. Then use the gear icon to select ‘Add Remote’, and choose Vagrant. PyCharm automatically detects most settings, we just need to put the path to the Python interpreter to tell PyCharm about the virtualenv we created:

Vagrant Interpreter

 

Now create a new script, let’s name it server.py and add Flask’s Hello World:

Make sure that you use the host='0.0.0.0' kwarg, as Flask by default only binds to localhost, and we wouldn’t be able to access our application later.

Now to create a run configuration, just navigate to the script as usual, and select ‘Single instance only’ to prevent the app not starting when the port is already in use:

Basic Flask Run Config

By marking the run configuration as ‘single instance only’ we make sure that we can’t accidentally start the script twice and get a ‘Port already in use’ error.

After saving the run configuration, just click the regular Run or Debug button, and the script should start.

Flask Running

In the next blog post we’ll have a look at an application where we build a REST API on top of a database. Continue reading now!

Posted in Tutorial | Tagged , , , , , , | 4 Comments

PyCharm 2017.3.1 RC

We have a couple of fixes and small improvements for you in PyCharm 2017.3.1, if you’d like to already try them, you can now get the release candidate from the confluence page.

New in this version:

  • Several issues with running Python modules (-m) were resolved: running modules remotely, showing command line after running
  • Further issues with running code over SSH were resolved: they can now connect to IPv6 hosts from macOS, don’t misinterpret ProxyCommand: none, and correctly parse the HostKeyAlgorithms option (Connecting to a Python interpreter over SSH is only supported in PyCharm Professional Edition)
  • Code insight for SQLAlchemy was improved, the issue with ‘incorrect call arguments’ has been fixed.

To try this now, get the RC from confluence. You can also update from within PyCharm, just make sure that your update channel is set to ‘EAP’ or ‘RC’ (in Help | Check for Updates).

If you use multiple JetBrains applications, you can use JetBrains Toolbox to make sure all your JetBrains IDE’s stay up to date. PyCharm is also available as a snap package. If you’re on Ubuntu 16.04 or later, you can install PyCharm by using this command:

sudo snap install [pycharm-professional|pycharm-community] --classic --candidate

Posted in Early Access Preview | Tagged , | Leave a comment

PyCharm Edu 2017.3 Release Candidate

PyCharm Edu is getting ready for the next major release with Release Candidate build 173.4048.

Get PyCharm Edu 2017.3 RC

You are probably wondering why we’re switching to 2017.3 version from the previous version 4.0. By aligning the PyCharm Edu versioning and release timetables with PyCharm and other JetBrains products, we want to focus more on delivering continuous value. This is the third release this year, so it is natural to use the 2017.3 version for it.

PyCharm Edu 2017.3 new features

Learners will find:

  • An enhanced Stepik integration with progress synchronization and public courses import included. Now you can start any Python course on Stepik, and then switch to PyCharm Edu, import the course without losing any of your progress.
  • Filtering the list of courses with tags, for better navigation and focus on the courses you’re interested in.
  • Compare with Answer action, which should help balance out the challenge of the more difficult tasks and avoid too much frustration.

Educators will find:

  • Much clearer UI for course creation and preview.
  • New interpreter settings screen, which makes interpreter and virtualenvs configuration much easier.
  • PyPI and Conda modes for those, who want to install PyPI packages into Conda envs.

Learn more about the new features and download PyCharm Edu 2017.3 RC from our website.

If you are using a recent version of Ubuntu (16.04 and later) you can also install PyCharm Edu using snap:


We are looking forward to getting your feedback in our issue tracker or in the comments.


Your PyCharm Edu Team

Posted in Education, Release Announcements | Tagged , | Leave a comment

Webinar Recording: “Putting Type Hints to Work” with Daniel Pyrathon

Tuesday’s “Putting Type Hints to Work” webinar with Daniel Pyrathon went very, very well. Daniel covered a difficult topic, starting with a small bit of code and gradually introducing type hinting to cover real-world coding scenarios. And lots of good questions from an audience that stayed the whole time.

Specifically, Daniel covered:

  • Type hints
  • Type checkers
  • Live coding a banking application
  • Review of 3 other tools that use type annotations

The recording is 1 hour 8 minutes. If you have any questions about the material, post them here and we’ll either try to answer or ask Daniel to pitch in. Thanks to Daniel and thanks to everyone that participated.

-PyCharm Team
The Drive to Develop

Posted in Video, Webinar | 1 Comment

PyCharm Edu: First Impressions from One Learning Journey

Every learning journey is unique. The good thing is no learner is alone. Many others are keeping diaries of their stories and learning journeys and sharing them with the world. They can be a great source of help and motivation so you can stay on track and keep your motivation high.

If you’re just beginning the Introduction to Python course in PyCharm Edu on your way to become a programmer, please meet David Watson, Marketing Copywriter at JetBrains. David is self-learning how to program and sharing his progress, along with tips and highlights, on our Team blog.

Here’s a sample tip from David about an Introduction to Python course task:

My advice for this would be to copy out some of the code snippets to revise on after and also to try and write out the code from scratch… Maybe you think this is easy… seriously try and write out one of the tasks from scratch with no guidance. It is pretty difficult, but this type of exercise really forces you to engage with the information. Also at this point, it helps to test things out and get things wrong, if you have got the answer, yet don’t understand what a piece of code is doing in all of this, it is a perfect chance to see its effect by simply testing for yourself.

I guess that was a challenging one, but all the more useful for it. Find other interesting highlights in David’s recent post Developing the basics : Programming myself, week one.

The whole series so far includes:

Share your story too and you may find other pilgrims and soulmates to inspire and be inspired by!


Your PyCharm Edu Team

Posted in Education | Tagged | Leave a comment

PyCharm 2017.3 is out now!

PyCharm 2017.3 Released

PyCharm 2017.3 is here: it’s faster, more usable, and better for data science.

Download now

  • PyCharm 2017.3 brings many performance improvements: Python indexing is twice as fast, JavaScript indexing is up to 40% faster, configuring SSH interpreters is much faster (in some cases over 100x), and more!
  • We’ve worked hard to make creating and selecting Python interpreters easier. For example, PyCharm 2017.3 will remember if you prefer to put your virtualenv in your project folder, or in a separate folder (like your WORKON_HOME folder).
  • A new scientific mode, which puts all the tools you need for data science at your fingertips (Scientific mode is only available in PyCharm Professional Edition)
  • We’ve built an all new HTTP client for those of you who build (REST) APIs. You can now write a request in a .http file, and then run it straight from the editor (Web development features are only available in PyCharm Professional Edition)
  • Django 2.0 will be out soon, and we’re happy to announce that PyCharm 2017.3 fully supports the new version (Django support is only available in PyCharm Professional Edition)
  • PyCharm 2017.3 supports running Python modules (python -m <module name>)
  • We’ve added support for SSH config files: if you’re using a complex setup with jump hosts, you can now connect to your machines effortlessly using the same config that you use on the command line (SSH is only supported in PyCharm Professional Edition)

And much more, have a look at our What’s New page, or get PyCharm 2017.3 now and try it yourself.

Posted in Release Announcements | 38 Comments

PyCharm 2017.3 RC

PyCharm 2017.3’s EAP phase has come to an end, and we’re happy to announce the Release Candidate for PyCharm 2017.3

Get PyCharm 2017.3 RC

Improvements in This Version

  • Django project creation will no longer lead to a NullPointerException (Django support is only available in PyCharm Professional Edition)
  • A debugger issue with having -m as a script parameter was fixed
  • SFTP deployment with an SSH config has been fixed (Remote features are only available in PyCharm Professional Edition)
  • HiDPI on Windows had issues during the EAP, and is now fixed
  • And more, have a look at the release notes for details

If these features sound interesting to you, try them yourself:

Get PyCharm 2017.3 RC

If you are using a recent version of Ubuntu (16.04 and later) you can also install PyCharm EAP versions using snap:

sudo snap install [pycharm-professional | pycharm-community] --classic --candidate

If you already used snap for the previous version, you can update using:

sudo snap refresh [pycharm-professional | pycharm-community] --classic --candidate

The Release Candidate is not an EAP build. You will need a license for PyCharm 2017.3 RC Professional Edition, if you don’t have one you will get a 30-day trial when you start it.

If you run into any issues with this version, or another version of PyCharm, please let us know on our YouTrack. If you have other suggestions or remarks, you can reach us on Twitter, or by commenting on the blog.

Posted in Early Access Preview | Tagged , | Leave a comment

Results of the Django/PyCharm Fundraising Effort 2017

We’re happy to report that our second iteration of the Django/PyСharm fundraising campaign – which we ran this summer – was a huge success. This year we helped raise a total of $66,094USD for the Django Software Foundation! Last year (2016) we ran a similar campaign which resulted in a collective contribution of $50,000USD to the cause. We’re happy we could raise even more money this year for the Django community!

If you missed the campaign here’s the essence of the past promotion: For 3 weeks this summer, Django developers could effectively donate to Django Software Foundation by purchasing a new individual PyCharm Professional annual subscription at 30% off, with all proceeds from the sales going to the Django Software Foundation. Read more details here.

All the money raised goes toward Django outreach and diversity programs: supporting DSF, the Django Fellowship program, Django Girls workshops, sponsoring official Django conferences, and other equally incredible projects.

We want to say huge thanks to the DSF for their active collaboration and making this fundraiser happen. We hope that in 2018 we’ll be able to make this yearly event even more successful!

The DSF general fundraising campaign is still on-going, and we encourage everyone to contribute to the success of Django by donating to DSF directly.

If you have any questions, get in touch with us at fundraising@djangoproject.com or JetBrains at pycharm-support@jetbrains.com.

Posted in Sales and Promotions | Tagged | Leave a comment

PyCharm 2017.3 EAP 10

This week’s early access program (EAP) version of PyCharm is now available from our website:

Get PyCharm 2017.3 EAP 10

The release is getting close, and we’re just polishing out the last small issues until it’s ready.

Improvements in This Version

  • kwargs autocompletion for Model.objects.create(). Django support is only available in PyCharm Professional Edition
  • An issue that would cause PyCharm to fill multiple log files per minute has been fixed
  • Docker Run configurations have been improving steadily throughout the EAP phase, in this version ports that are used in a binding but haven’t been exposed yet will be auto-exposed (Docker support is available only in PyCharm Professional Edition)
  • And more, have a look at the release notes for details

If these features sound interesting to you, try them yourself:

Get PyCharm 2017.3 EAP 10

If you are using a recent version of Ubuntu (16.04 and later) you can also install PyCharm EAP versions using snap:

sudo snap install [pycharm-professional | pycharm-community] --classic --edge

If you already used snap for the previous version, you can update using:

sudo snap refresh [pycharm-professional | pycharm-community] --classic --edge

As a reminder, PyCharm EAP versions:

  • Are free, including PyCharm Professional Edition EAP
  • Will work for 30 days from being built, you’ll need to update when the build expires

If you run into any issues with this version, or another version of PyCharm, please let us know on our YouTrack. If you have other suggestions or remarks, you can reach us on Twitter, or by commenting on the blog.

Posted in Early Access Preview | Tagged | 1 Comment