Setting up Pycharm on OSX (older versions)

Richard Larkin edited this page Mar 10, 2016 · 1 revision
Clone this wiki locally

Installing PyCharm for Kivy (older versions)

This page stores instructions for installing older version of PyCharm and Kivy, kept for the sake of completeness. These version are no longer supported and we strongly recommend you use the latest versions of both. Instruction for the current versions can be found here.

Setting up Kivy 1.8 with PyCharm 4 on OS/X

  1. Open your project in PyCharm
  2. Run -> Edit Configurations -> Environment Variables Where to click to edit variables

  3. Add entries for the several required variables. required enviornment variables

  4. If you have a non-standard installation, you can get the updated environment variables by running the kivy script interactively:
    example using kivy shell

Setting up Kivy 1.9.0 with PyCharm 4.5 EAP on OS X 10.10.3

  1. Install Kivy 1.9.0

    We assume you have copied the Kivy.app folder as found in Kivy-1.9.0-rev3-osx.dmg into the /Applications folder.

  2. Make kivy known to PyCharm

    Add a link to the kivy package in the site-packages folder of the interpreter that kivy uses:

    cd /Applications/Kivy.app/Contents/Resources/venv/lib/python2.7/site-packages
    ln -s /Applications/Kivy.app/Contents/Resources/kivy/kivy kivy
    

    PyCharm scans the site-packages folder to help you with auto-complete. We'll check this in a later step.

  3. Configure a Project Interpreter

    • Start PyCharm.

    • Close any project you may have open (File->Close Project).

    • At the bottom of the Welcome screen, choose Configure -> Preferences. (Alternatively, press CMD-,).

    • In the Default Preferences window, choose Default Project -> Project Interpreter.
      Click the clog icon in the upper right corner, and in the drop-down list, choose More...
      In the Project Interpreters window, click the plus icon, and in the drop-down list, choose Add Local.

    • In the Select Python Interpreter window, delete the path of the currently selected python interpreter (in my case, this was /usr/bin/python) and navigate to (or copy that path into the address bar):

    /Applications/Kivy.app/Contents/Resources/python
    
    • Click OK to close the Select Python Interpreter window.
      Optional: give the interpreter a nicer name, by clicking the pencil icon in the Project Interpreters window: in the Edit Python Interpreter window's Name field, add 'KIVY' between 'Python' and '2.7.6'. This will make the kivy interpreter more easily recognizable later on.

    • Click OK to close the Project Interpreters window.

    • Click Apply at the bottom of the Default Preferences window.

    • Click OK to close the Default Preferences window.

  4. Set the interpreter of your project

    • Either open a project you already created, or create a new one. Here, I will create a new one (a Pure Python project).
    • In the pane that appears after choosing New Project, in the drop-down list that accompanies the Interpreter field, select the KIVY interpreter we created in the preceding step.
      Click the Create button.
    • If you chose to open an existing project: open up the PyCharm-EAP->Preferences... menu in the main menu (or use CMD-,); in the Preferences window choose Project: *your_existing_project*->Project Interpreter and use the drop-down list to select the KIVY interpreter. Click Apply and then click OK.
  5. Check that auto-complete works

    Create a new Python file in your project and start typing, e.g. let's begin with an import: import kiv and note the pop-up. Yay!

  6. Configure a Run/Debug configuration

    From the main menu bar of PyCharm, choose Run->Edit Configurations...

    • In the Run/Debug Configurations, click the plus icon (or, use the keyboard shortcut CMD-N), and choose Python from the drop-down list to create a new configuration.
      Note that the Python interpreter field already shows the KIVY interpreter filled in.

    • Fill out the Name, Script, and other fields you would normally need to fill.

    • Click the ellipsis icon (...) that accompanies the Environment variables field.

    • In the Environment Variables field, use the plus icon or CMD-N keyboard short-cut to add the following environment variables -- as found in /Applications/Kivy.app/Contents/Resources/script -- (you can copy the whole block and paste it with the clipboard icon):

    PYTHONPATH=/Applications/Kivy.app/Contents/Resources/kivy:${PYTHONPATH}
    GST_PLUGIN_SCANNER=/Applications/Kivy.app/Contents/Resources/gst-plugin-scanner
    GIO_EXTRA_MODULES=/Applications/Kivy.app/Contents/Frameworks/GStreamer.framework/Versions/Current/lib/gio/modules
    LD_PRELOAD_PATH=/Applications/Kivy.app/Contents/Resources/lib
    GST_PLUGIN_SYSTEM_PATH=/Applications/Kivy.app/Contents/Frameworks/GStreamer.framework/Versions/Current/lib/gstreamer-1.0
    KIVY_HOME=/Applications/Kivy.app/Contents/Resources/.kivy
    GTK_PATH=/Applications/Kivy.app/Contents/Frameworks/GStreamer.framework/Versions/Current
    DYLD_FALLBACK_LIBRARY_PATH=/Applications/Kivy.app/Contents/Resources/lib
    GST_REGISTRY=/Applications/Kivy.app/Contents/Resources/gst.registry
    

    Note: because of the link we created in the site-packages folder, I think the PYTHONPATH adaptation is not needed (need to check)
    Note: I filed an issue with respect to seemingly non-existing ${SCRIPT_PATH}/lib folder usage
    Note: I'm not sure if KIVY_HOME is somehow overridden to be ${USER}/.kivy where I find my Kivy configuration settings and log files.

    • Finally click the Apply button and then the OK button in the Run/Debug Configurations window.