Details on installing and using Pycharm for webapp development

Prerequisites

  • The instructions below are pretty Mac-o-philic, but should work for most other Unices.
  • There are usually several ways to accomplish the steps required below. Your mileage may vary. Google is your friend for problems and troubleshooting. Unless you are a wizard or possess other superpowers, you would be wise not to stray from these instructions any more than necessary, as if you do it will be more of a challenge to winch you out of the weeds if something goes wrong.
  • VPN access:  install Cisco client, and ensure you have CalNet credentials, see  http://www.lib.berkeley.edu/Help/vpn_2009_mac.html
  • XCode "Command Line Tools" installed for your OS.  This is a hassle -- you have to sign up to be an Apple developer, download at least a couple hundred MBs of code. Etc. Try starting at: https://developer.apple.com/downloads/.  (It's possible that it might be more easily downloaded via the App Store; one can try https://itunes.apple.com/us/app/xcode/id497799835?mt=12, or search Google for "xcode app store" -  Aron) You can install the entire XCode tool set, but it is huge and not necessary for what we are doing.  If you have a recent version of the Mac OS X (e.g. Mavericks), you will normally be prompted if you attempt to use a Tool from the set but it is not installed.  This is an easy way to get the CTL code in this particular case.
  • Git:  you may already have this if after installing the XCode CLT above, but if not – git  (v1.9 or higher, unless you are running Lion, in which case you may have to install v1.8.4.2) installed and working,  see http://sourceforge.net/projects/git-osx-installer/
  • Several of the webapps expect to query the CSpace postgres database directly. If your project contains such webapps, you'll need one (or alas both) of the Python postgres bindings (pygresql or psycopg2).  These in turn will only install if you have the necessary client code (or Postgres itself) install on the target system.  Recent versions of the Mac OS (10.8.x Mountain Lion and beyond?) come with Postgres installed and you need only ensure that the installers can find it.  We have found that inserting the following line in ~/.profile works (NB: you'll need to verify the version of Postgres ("9.x") that is installed.)

    cat ~/.profile
    # Postgres
    PATH="/Library/PostgreSQL/9.1/bin:${PATH}"
    
    # need to reload environment...logout and login or
    source ~/.profile
  • Pip: there are lots of ways to install Python packages, and you'll probably have to install a few. So get pip working, try, e.g. "sudo easy_install pip" on your Mac...
  • Get PyCharm Professional (http://www.jetbrains.com/pycharm/download/) : CollectionSpace has a license key, so don't worry about that: you can start up the 30-day trial version and add the key later.  (The Community version does not support Django)  If you have only Java 7 (and not also Java 6) available on your OS X system, you might need to follow these instructions (not Maverick-specific; they also apply to Mac OS X 10.8 Mountain Lion): http://www.sergiolopes.eu/2013/12/fix-eclipse-ide-pycharm-not-loading-on-osx-mavericks/

Resolving specific Python dependencies and getting stuff from GitHub

Once you have PyCharm installed and working*, you can simply:

  • git clone (or fork) the project you want to work on from GitHub
  • (sudo) pip install <whatever python modules you don't have installed, perhaps even django>
  • configure the authentication backend (i.e. create sqlite db...)
  • configure webapps for your "deployment" (defaults will mostly work)
  • fire up a server!

* "working" means that not only have you downloaded and installed PyCharm (v2.7 or higher), but that you have started it up and cleared all the initial hurdles; that you have verified that you have 
For example, the following steps should get the pahma_project working for you:
# install django, if necessary
sudo pip install django
# resolve other Python dependencies (various Python modules)
# The ones below are the ones needed for UCJEPS and PAHMA
# NB: you'll also need lxml/elementtree, usually already installed with Python
sudo pip install solrpy
sudo pip install pillow
sudo pip install pygresql # see note about about pg_config and install Postgres dependencies

# OK! now get the code
git clone https://github.com/cspace-deployment/pahma_project.git
cd pahma_project/

# copy the example config files to config 
# (the following only works for pahma; other project will need to build whatever config
# files are needed for their webapp suite.
cp autosuggest/pahmaExampleAutosuggest.cfg config/autosuggest.cfg
cp imagebrowser/pahmaExampleImagebroswer.cfg config/imagebrowser.cfg
cp imageserver/pahmaExampleImageserver.cfg config/imageserver.cfg
cp ireports/pahmaExampleIreports.cfg config/ireports.cfg
cp publicsearch/pahmaExampleSearch.cfg config/search.cfg
cp uploadmedia/exampleUploadmedia.cfg config/uploadmedia.cfg

# edit the above files to point to the server(s) you want
# you can do this editing in PyCharm
vi ... vi ... vi ... vi

# BMU needs the following hardcoded directory, for now
mkdir /tmp/upload_cache

# there is just a bit of Django configuration needed:
# initialize the sqlite db (for authentication), run the server
# NB: if using PyCharm, and you should, be you can do both of the
# following from PyCharm
python manage.py syncdb
# if you like can run the development server from the command line.
# Normally, however, you would run it from within PyCharm
python manage.py runserver
# server is now running on http://127.0.0.1:8000
# try, e.g. http://127.0.0.1:8000/ireports/

Other PyCharm configuration

  • For some reason, once you open a Django project in PyCharm it is not able to figure out itself where the settings.py file is. You have to tell it (under Preferences).
  • Also, you may have to mess with Edit Configurations... under the Tools menu: you need to specify the interpreter where you installed all the modules, etc.
  • Then, you should be able to select Tool > Run ('your_project') and exercise  your webapps locally.
  • If you are using any of the webapps that access Solr, make sure you have Solr properly installed and running.