Friday, 26 July 2013

Installing Python modules without root privileges

It seems I'm doomed to work on centrally-administered Linux systems without root privileges. I've already had to write about similar problems before. I'm on a much more up-to-date distribution (link OpenSUSE) these days, so LaTeX and out-of-date software are generally no longer problems, but I often find myself wanting to install one or another nifty Python package for my work. Luckily, it turns out someone out there is thinking of people like me. The standard distribution mechanism of Python packages includes a method to install a package in your user space. The official description is here but here are the basics.

All the packages in the Python Package Index are installed with a setup script, always setup.py. Usually, you could install these packages by downloading them, extracting them, then changing to the new directory and typing

sudo python setup.py install

These now include the option to install to your user space by instead entering

python setup.py install --user

By default, this creates a root-like tree under ~/.local/. With that done, you're basically good to go! Path variables seem to be updated and you can import them in Python, IPython or scripts. It's always handy to test by entering

python -c "import python-package"

at the command line and watching for errors.

All that said, there's a known conflict with the default settings in OpenSUSE and RedHat. (I'm not sure if it applies to other RPM-based distributions.) This can be fixed by adding the argument --prefix== to our command. So the full command becomes

python setup.py install --user --prefix==

That's it! As a closing note, this method also carries the handy benefit of following your around as you login to different computers, presuming they have the same architectures and Python packages. This happens to be pretty handy when either offloading work onto other computers in a network, or using a cluster. Just be sure to set up the appropriate environment variables if they aren't automatically loaded.

Monday, 15 July 2013

Transfer files to and from Android phone wirelessly with Samba

I regard as very noughties the use a cable to transfer files to and from your phone. Wireless is now definitely the way. Most of the time, you probably already do this by virtue of tools like Winamp's music syncing or Dropbox's automatic photo upload but sometimes a guy just wants to, you know, copy some files. Fortunately, for Android, there's a great means to this end: Samba Filesharing for Android. In short, it turns your phone into a Windows-compatible file server. But, since Samba is an open platform and implemented on many other operating systems, it's easily accessible on Linux too.

All you need to do is download the app, set up the basic requirements (e.g. username and password) and start the service. Your phone should then appear as a network drive. In Windows, this involves selecting ANDROID (or whatever you named the device) from the Network tree in a file manager. On selecting the phone, you'll be prompted for the credentials you set up. You're then free to transfer files to your heart's content!

In Ubuntu, you'll find the network drive in the file manager under Browse network > Workgroup. On opening the device, you'll be prompted for the login credentials. Then you should be good to go. If you get an error message like "Failed to retried share list from server" (as I did), you probably need to install Samba. You can do so through your favourite package manager. The package name is (surprisingly enough) samba so sudo apt-get install samba will do.

In theory, it's also possible to mount the Samba device on the Linux filesystem but I haven't gotten that to work. There's a utility called smbfs, which is designed to do just this, and you can find some information here but I only ever get a "permission denied" error. I'd be interested to hear from anyone who has used this system successfully.