Wednesday, November 28, 2012

Eclipse in ubuntu

There are so many posts out there on installing eclipse on Ubuntu, that I decided to take the plunge. I had been troubled by having to manage two repos, but since I mainly use PyDev and Android SDK, neither of which are in the Ubuntu repository, so it was either deal or try to go it alone. I'm happy to report that eclipse 4.2, aka juno, is running great in Quantal, no errors so far!

With Oneiric and Precise I had successfully used both Ubuntu and eclipse repositories, but with each upgrade there were always snafus; I would have to re-install some plugin and end up losing my workspace settings. Playing the repo shuffle, you never know when Ubuntu might suddenly decide to revoke or add a package, and there are so many eclipse plugins it just makes sense to me to let one system manage the dependencies. Reading up a bit here and there I began to realize that this is an issue eclipse and Linux users have addressed and that eclipse would work out of the box on Ubuntu.

So the first thing I did was completely remove eclipse from my system. I had some false starts, first off Synaptic may be a great tool but it does not remove certain dependencies the same way as the Ubuntu Software Center (USC). Same goes for `apt-get`. Too bad because using USC is slow and tedious because you can only install/remove one package at a time. But unless you want to leave a lot of detritus on disk USC does a better job at killing off orphans. That made me realize another reason for installing eclipse as add-on software, since using the Ubuntu repo installed over 100 packages! I'm trying to keep my machine uncluttered and organized so that's just ridiculous.

I did a few things different than the vast number of sites posting instructions.
  1. I created a folder called "/opt" in my home directory and untarrred my eclipse download there. I chose the Java EE version for 32-bit Linux because it has the most complete selection of useful plugin preinstalled. I decided on ~/opt instead of /opt because I'm the only user and I didn't want to deal with ownership and permissions. This is a nice compromise that doesn't clutter your system. However, in general I would recommend copying the entire package to /opt and changing ownership to root:root.
  2. I created a soft symlink to ../opt/eclipse/eclipse called "eclipse" in ~/bin. This folder is already present and is always first on your path. If I had moved eclipse to /opt, then it would be available to all users, and then each user could create a symlink from there to their private ~/bin folder. I didn't have to change the permissions, because it's already 777.
  3. This next step is the major difference between what I did and what I've seen posted everywhere. I created a desktop file in ~/.local/share/applicatons called "eclipse.desktop" with the following. I looked into both gnome-panel and alacarte (ne main menu), but I ruled them out because the desktop file is so easy to create, and both of these tools are for true gnome desktops not Unity, and also seemed outdated. There is ample help on putting applications in the desktop. A couple of notes: ~ is not expanded, so use your complete path, X-Ayatana is the name of the Unity group, if you want to add extra commands and I had to export the eclipse xpm icon as a png file because it didn't work in the Unity dash.

    [Desktop Entry]

  4. I started eclipse from the dash and pinned it to the launcher. Then followed the customary procedures to update and install packages from within eclpse. From the menu select help > check for updates, and then help > install new software. Note: I have started help using the internal browser (default) and it works fine. My system already has both libwebkitgtk-1.0.0 and libwebkitgtk-3.0.0 so I didn't have to install or remove anything; eclipse help just worked out of the box. I have read numerous reports regarding this issue (eclipse crashes when help window opened), so evidently it has been solved.
So there you go. If you are on the fence, and tired of managing two repositories, I hope I've convinced you that it's okay to install eclipse as an add-on and it will work fine, and not break your system.

Monday, November 26, 2012

Install Add On Software and Create GTK+ Desktop File

Unfortunately not all of the software that you want will be in your linux distro. The most common examples of these are the awesome Sublime Text 2 editor and the bloated but ubiquitous eclipse IDE. Actually eclipse is in most linux distro repositories, but only a limited set of plugins are available, and eclipse uses its own repository system to update and install plugins which is in principle incompatible with your distro's packaging system. For example, if you install eclipse 3.8 from the Ubuntu Quantal Quetzal repo, you can not update it from the eclipse repository, and if you install the PyDev plugin using their repository through the eclipse packaging system, when your upgrade to the next Ubuntu version, your plugins will not work and you will have to reinstall them. If you are okay with this, then you may be alright, but you will have some extra work to do come upgrade time, and you will need to keep track of what is installed via the official repo and what is being maintained by eclipse's repos, because neither can keep track of the other, and they are all for the most part dumped in the /home/<username>/.eclipse/ directory.

Linux actually has a protocol for installing software add-ons, if you decide that what's in your distro's repository is not enough for you. There are a few options.

  1. Find a PPA (Personal Package Archives for Ubuntu), add it and then install the package with apt-get. This will most likely install the package in /usr/, /usr/bin/, /usr/lib/, ... and take care of configuration and creating a desktop file so that you the application will appear in the unity dash (on Ubuntu) and you can add it to the launcher or launch files from Nautilus. This works for Sublime Text 2. PPA's are often listed on Launchpad.
  2. Build the code from source using autotools and it should install in /usr/local/, /usr/local/bin/, /usr/local/lib/, /usr/local/include/, ... but of course you will need to make sure that the application's dependencies are all satisfied and do not conflict with your distro. This can be a tough row to hoe.
  3. Find a pre-compiled package and drop it into your system's /opt directory, which is designated specifically for add-on software not provided by the system's package repositories. An alternative often used and actually my preference is to extract the new package into your home directory.  This works, but to avoid cluttering $HOME I add a folder called ~/opt and drop the add-ons in there. Again, it is up to you to make sure that the software's dependencies are satisfied. For example, eclipse requires some jdk, whether it is from Oracle or the openJDK project, and it will need to be a version within the range specified by the add-on software, e.g. jdk >= 7.0 in the case of eclipse.
Now you need to integrate the add-on software into your system. Again you have some choices and it seems that there is some debate about what is the best course to take.
  1. The easiest thing to do is to run the application from the console, and don't integrate it into your desktop (Gnome) or file system browser (Nautilus), by opening a terminal window and typing ./<executable>. You may need to change the permissions first by using sudo chmod 755 <executable>.
  2. Another option that doesn't require you to edit your desktop files is to add the folder to your path, however, this may cause problems if there are filename conflicts, e.g. your system already has a libz.a but your new software does too. One safe way to deal with this is to add  the new directory to the end of your path, or create a special shell for it. This way your default system files will always be used.
  3. Create a symlink to /home/<username>/bin/ which is always first on your path. This is my preferred method for several reasons. First it will survive an update because your personal profile is not altered during upgrades. Second, it only affects you, and not other users if you share your machine. Of course if your intent is to make the application usable for all users, then either you need to add it to all profiles or make a symlink to /usr/bin/. However, links in /usr/bin/ will probably not survive an upgrade because this is system file territory
  4. Create a gtk desktop file in /home/<username>/.local/share/applications/, as described in Desktop files: putting your application in the desktop menus, which again is my preferred method. I wrote a post on eclipse in Ubuntu that has an example of a desktop file. The reasons are the same as above. First it survives an upgrade and second it only affects you. You can customize the desktop file to have as many actions as you want, for example to have an option to open a new window by right clicking directly from the launcher icon, or to list all of your current eclipse profiles so that you can launch them directly. The desktop file is very flexible. You should now be able to find your application in the Unity dash (on Ubuntu) and once it runs you can lock it to the launcher. Also if you add the %f option after the location of the executable in the desktop file, then it will be available to Nautilus as well. Then you can right click and see other applications that can open a file associated with your new application. See this Ask Ubuntu answer on how to install the Sublime Text 2 editor. A lot of people have recommended editing the system wide desktop files, which are in /usr/share/applications/ but I don't recommend this as it will not survive an upgrade.
In general, I tend to be more conservative when it comes to editing system files and directories, preferring to keep my customization localized to my profile, and only deviating from that when absolutely necessary. But you may have a different use case which will necessitate a different approach.

Monday, November 19, 2012

PyGTK with Christoph Gohlke and GTK all in one bundle for x64 systems

This is very straightforward.

  1. Download and install PyGTK, Py2Cairo and PyGObjects from Christoph Gohlke's website. Note, do not install pycairo, as Gohlke clearly states it is not compatible with PyGTK.
  2. Create a folder called "runtime" in `C:\Python27\Lib\site-packages\gtk-2.0`.
  3. Download and install the GTK all in one bundle for 64-bit systems from Gnome. Make sure that it is the same version as PyGTK that you installed from Christoph Gohlke's site, which was version 2.22 upon writing.
  4. Extract the GTK files to the "runtime" folder created in step 2.
  5. Add the runtime folder to your python path, and/or the path environment variable of any shells that you want to have access to GTK
Note: It is not strictly necessary for the location of the runtime folder in step 2 to be in the Python27 file system, it could be in your` /home/bin`, `/local/bin`or `C:\` directory or where ever you want it, as long as it is on your path.

Python x64 Package Extensions with pip, MSVC 2008 Express & SDK 7

[UPDATE 2014-11-13] Free x86 and AMD64 (x86-64) VC90 c-compilers for Python-2.7 are now available from Microsoft. The free VC90 compilers can be used to install package source that contains c-extensions using either pip, setuptools or distutils. For example, pip install dulwich will build and install the Python Git implementation which contains several speedups as c-extensions.

[UPDATED 2012-02-04, 2014-04-18] You can skip this if you fix your vcvarsall.bat to point at the correct paths.

If you try `user@machine ~$ pip install package` from a bash shell or even `C:\Users\user>C:\Python27\Scripts\pip.exe install package` on a 64-bit MS Windows machine with the 64-bit version of Python installed, then you are likely to get a traceback from `` that `vcvarsall.bat` only returned `path` but it was also looking for `lib`, `libpath` and `includes`. Oh well.

Because you know that your version of Python 2.7 was compiled with MS Visual C++ 2008 (aka VC90), you might try to use pip in the VC90 command prompt, since it loads the variables for you, but then you will get the following linker error:
fatal error LNK1112: module machine type 'x64' conflicts with target machine type 'X86'
In a virgin cmd.exe shell you might try to run vcvarsall.bat amd64 to see if it works, but then you will see that it doesn't, when you get this discouraging stifling message:
The specified configuration type is missing.  The tools for the configuration might not be installed.
Then you might put this into Google and eventually you will find that MVSC 2008 Express doesn't support 64-bit compilation without Windows SDK 7 (see this post to find out where you can download this). Luckily, that has it's own nifty environment, run it from the start menu and change to 64-bit compilers and release mode by typing ...
> setenv /x64 /release
... and watching the screen font color change from yellow to green. Fun! Distutils would also like you to tell it not to bother looking around for vcvarsall, and just use the SDK environment by setting two environment variables:
> set MSSdk=1
Also, you will need to have both Python27 and Python27\Scripts on your path before you run the SDK 7 CMD shell, or distutils will still fail. Unfortunately you can't add this by editing the path after starting the shell. The easiest way to do this is to right click on the My Computer icon on the desktop, select the Advanced tab and then click the Environment Variables button near the bottom. This will bring up the Environment Variables window. Add a new user variable for your personal profile by clicking the New button in the upper pane, and then type PATH in the Variable name: box and C:\Python27;C:\Python27\Scripts in the Variable value: box. Note the semicolon in between the 2 paths, if you've never edited your path before, this is the path separator on MS Windows. Then click OK, OK and OK. The changes are immediate for new CMD shells. Your local PATH is appended to the end of the system PATH.

Now try `pip install package` again and if you're lucky, voila, pip says, "Sucessfully installed package". Thanks pip! I tried this with dulwich, and it installed no problem.

There is some nifty info in the Python distutils docs and the Cython folks also have some nice 64-bit extensions help too.

Friday, November 16, 2012

Google drive hog

Hard to believe but every time Google drive windows app syncs it creates a 34mb temp directory, with a partial python library! It quickly adds up. Screw that, uninstall! How come dropbox has no issues?

Friday, November 9, 2012

Shell binaries needed for virtualenvwrapper

[UPDATED 2013-02-07]

You will need fmt from coreutils, make and mktemp. You also need iconv and intl libraries. Your best bet in Git bash is to install base MSYS* (part of MinGW) and then copy or link those files from /c/mingw/msys/1.0/bin/ to your Git bash home bin folder ~/bin since it will always be first on its PATH.

Do not use GnuWin32 because mktemp is broken (see bug), you don't need all 99 coreutils binaries (just fmt) and ideally you want binaries compiled for a POSIX environment (Git bash is built with MSYS),  although the gnuwin32 make binary does work in Git bash, and so does fmt. See my post for the differences between MinGW, MinGW-w64 and GnuWin32.

Coincidentally, make will also be useful for building HTML and pdftex from Sphinx rst files.

*Since, like many other MS Windows users, I've been migrated to Windows7 x64, I now recommend using MinGW-w64 instead of MinGW (aka mingw32). See my post on setting up MSYS home for virtualenvwrapper for more info.

Wednesday, November 7, 2012

Sphinx make latexpdf for MS Windows

Sphinx is an amazing documentation tool. I was up and running with gorgeous html in minutes! But generating a pdf took a little longer to figure out because IMHO on Windows using any open source is always a challenge.

  1. Install Sphinx (1.1.3) - just use pip, easy_install, or setup, whatever you prefer.
    • user@user ~$ pip install sphinx
  2. This will probably also install Pygments and Jinja-2, I can't remember.
  3. Install MikTex package repository binary. This takes care of downloading and updating your LaTeX binaries. Alternately install TeX Live and Lua TeX Windows binaries. I haven't tested this so not sure how well it works, but essentially should be the same as MikTeX since it's the same source.
  4. You will need a working make binary. The easiest one is from GNUwin32, but I would recommend installing MSYS either from MinGW or MinGW-w64. Alternately you could use Cygwin, but that's a different ballgame.
  5. After you've run sphinx-quickstart from the tutorial, type make latexpdf and voila. If you used MikTeX, it will ask you to install several LaTeX packages.
Another option is to go straight to pdf with rst2pdf. First install reportlab binary from the cheese factory. Then use pip to install rst2pdf.
Fork me on GitHub