This tutorial is a very brief overview of how to use PyCharm with Pyramid. PyCharm is an Integrated Development Environment (IDE) for Python programmers. It has numerous features including code completion, project management, version control system (git, Subversion, etc.), debugger, and more.
This tutorial is a continually evolving document. Both PyCharm and Pyramid are under active development, and changes to either may necessitate changes to this document. In addition, there may be errors or omissions in this document, and corrections and improvements through a pull request are most welcome.
This guide was written for PyCharm 2.7.3, although many of the topics apply for PyCharm 3. In addition there are now two editions for PyCharm 3, a Professional and a free Community Edition. Furthermore, PyCharm 3 includes support for Pyramid, making installation and configuration of Pyramid much easier.
To get started with Pyramid in PyCharm, we need to install prerequisite software.
You can download installers for Mac OS X and Windows, or source tarballs for Linux, Unix, or Mac OS X from python.org Download. Follow the instructions in the README files.
PyCharm is a commercial application that requires a license. Several license types are available depending on your usage.
Pyramid is an open source project, and on an annual basis fulfills the terms of the Open Source License with JetBrains for the use of PyCharm to develop for Pyramid under the Pylons Project. If you contribute to Pyramid or the Pylons Project, and would like to use our 1-year license, please contact the license maintainer stevepiercy in the #pyramid channel on irc.freenode.net.
Alternatively you can download a 30-day trial of PyCharm or purchase a license for development or training purposes under any other license.
Download PyCharm and follow the installation instructions on that web page.
Launch the PyCharm application.
From the Start Up screen, click Create New Project.
If the Start Up screen does not appear, you probably have an existing project open. Close the existing project and the Start Up screen will appear.
In the Create New Project dialog window do the following.
A new window appears, “Python Interpreters”.
If you already have setuptools installed, you can skip this step.
In the Python Interpreters window with the just-created virtual environment selected in the top pane, in the lower pane select the Packages tab, and click the Install button. The Available Packages window appears.
In the Available Packages window, in the search bar, enter “setuptools”. Select the plain old “setuptools” package, and click the Install Package button and wait for the status message to disappear. PyCharm will install the package and any dependencies.
Repeat the previous step, except use “pyramid” for searching and selecting.
When PyCharm finishes installing the packages, close the Available Packages window.
In the Python Interpreters window, click the OK button.
In the Create New Project window, click the OK button.
If PyCharm displays a warning, click the Yes button. PyCharm opens the new project.
By cloning the Pyramid repository, you can contribute changes to the code or documentation. We recommend that you fork the Pyramid repository to your own GitHub account, then clone your forked repository, so that you can commit your changes to your GitHub repository and submit pull requests to the Pyramid project.
In PyCharm, select VCS > Enable Version Control Integration..., then select Git as your VCS and click the OK button.
See Cloning a Repository from GitHub in the PyCharm documentation for more information on using GitHub and git in PyCharm.
We will refer to the cloned repository of Pyramid on your computer as your “local Pyramid repository”.
In order to contribute bug fixes, features, and documentation changes to Pyramid, you must install development and documentation requirements into your virtual environment. Pyramid uses Sphinx and reStructuredText for documentation.
In PyCharm, select Run > Edit Configurations.... The Run/Debug Configurations window appears.
Click the “+” button, then select Python to add a new Python run configuration.
Name the configuration “setup dev”.
Either manually enter the path to the setup.py script or click the ellipsis button to navigate to the pyramid/setup.py path and select it.
For Script parameters enter dev.
Click the “Apply” button to save the run configuration.
While we’re here, let’s duplicate this run configuration for installing the documentation requirements.
In the PyCharm toolbar, you will see a Python icon and your run configurations.
First select “setup dev”, and click the “run” button (the green triangle). It may take some time to install the requirements. Second select “setup docs”, and click the “run” button again.
As of this writing, PyCharm does not yet have a command line interface to a shell. So there are some things that require you to go into a shell to enter commands. This next step requires doing just so.
Unfortunately, the author was unable to figure out how to generate docs in PyCharm using either a “Python docs” or “Python” run configuration. If anyone knows, please submit a pull request.
You will now be ready to hack in and contribute to Pyramid.
To configure the template languages Mako and Jinja, see the PyCharm documentation Templates.
To configure the template language Chameleon, see Creating and Registering File Types. Specifically for Chameleon, we want to associate XML to the *.pt extension.
The information for this section is derived from Creating a Pyramid Project and adapted for use in PyCharm.
Within PyCharm, you can start a project using a scaffold by doing the following.
We will create another run configuration, just like before.
We will create yet another run configuration. [If you know of an easier method while in PyCharm, please submit a pull request.]
When will creation of run configurations end? Not today!
You can also reload any changes to your project’s .py or .ini files automatically by using the Script parameters development.ini –reload.
See the PyCharm documentation Running and Debugging for details on how to debug your Pyramid app in PyCharm.
First, you cannot simultaneously run and debug your app. Terminate your app if it is running before you debug it.
To debug your app, open a file in your app that you want to debug and click on the gutter (the space between line numbers and the code) to set a breakpoint. Then select “MyProject pserve” in the PyCharm toolbar, then click the debug icon (which looks like a green ladybug). Your app will run up to the first breakpoint.