4

I am interested in a reliable and robust procedure for collecting python package and dependencies for the Psychopy library into a single collection or environment to make a self-contained and maintainable installation. As well it would be good to have some general recommendations on the recommended way to do this since googling Nixos and Python yields a number of approaches, some of which use poorly documented function e.g. myEnvFun

Psychopy is a python package used for psychology experiments. It has several dependencies, most of which are python packages, but not all (e.g. AVbin); and most of which are in the nixos package collection, but not all (pyo and py-parallel).

My goal would be to be able to get all the needed pieces together and have a functioning psychopy environment with a single installation request. I have figured out how to get psychopy installed, but the path's don't play nicely.

For example if the following is saved as ~/pkg/psychopy/default.nix

let
  pkgs = import <nixpkgs> {};
in
{stdenv ? pkgs.stdenv, python ? pkgs.python, fetchurl ? pkgs.fetchurl}:

with pkgs;
buildPythonPackage {
  name = "psychopy";

  src = fetchurl {
    url = http://sourceforge.net/projects/psychpy/files/PsychoPy/PsychoPy-1.82.02.zip;
    md5 = "52309280bdca4408970aab0952c674e4";
  };

  buildInputs = [
    python27
  ];
} 

One can run nix-env -f ~/pkg/ -iA psychopy and Psychopy will be installed, but it will not be easily useable because the path to the psychopy library is not seen by any system wide python2 installation, or even the python version that is installed as part of the build inputs.

This leads to the following questions that though they are specifically about psychopy would apply more generally to python and Nixos.

  1. Is the recommend practice to install python packages that exist in the nixos expression collections (e.g. numpy and scipy) once as system or user wide packages or with each particular experimental library?
  2. If one wishes to bundle together a python collection with more than one library outside the nixos expression channel (e.g. psychopy and pyo and pyparallel) what is the recommended procedure? And how does this change if some non-python software is required, e.g. in this case AVbin (which actually has installation instructions that refers to paths that are not standard in Nixos to my understanding, i.e. /usr/lib)?
  3. Can some discussion of handling paths in Python with the context of Nixos be shared?
Jaroslav Bezděk
  • 6,967
  • 6
  • 29
  • 46
brittAnderson
  • 1,428
  • 11
  • 25
  • I think AVbin might no longer be needed with recent changes to the movie stimulus. I guess most people use Anaconda and Erik Kastman created an install recipe for PsychoPy here: https://github.com/kastman/conda-recipes although that could stand to be updated. – Michael MacAskill Sep 27 '15 at 19:57
  • @MichaelMacAskill My hope was that nixos might offer a nice way to create a standard portable linux version within a lab where standard command could be used to create standard machines. Nixos in principle gives the advantage of not just having a psychopy stand-alone, but everything else too. So, while it is good to know that avbin is not required, and that the wiki needs updating, it still leaves open the issue of how to set-up the nixos config.nix Thanks. – brittAnderson Sep 28 '15 at 00:13

1 Answers1

2

myEnvFun is deprecated, where did you read about it?

Answers:

  1. It's recommended to create environments with nix-shell, you should be able to run it inside ~/pkg/psychopy/ and get $PYTHONPATH populated.

    The idea behind Nix is not to have any global sets of packages, but rather environments for each need.

  2. By just declaring AVBin as build dependency it should be enough. Note that your users will need to install Nix. If you want to avoid that, you'll need to write a wrapper that will do something similar to nix-shell.

  3. There isn't much going on here. All Nix packages are build in isolated chroots. Nix has a concept called setup hooks, which are executed for each package in the dependency tree. So for Python packages https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/interpreters/python/2.7/setup-hook.sh#L15 is called in order to populate $PYTHONPATH. For command line programs we then wrap the resulting script with $PYTHONPATH hardcoded.

For discussion it's best to join Freenode IRC channel #nixos

iElectric
  • 5,633
  • 1
  • 29
  • 31
  • Features on the wiki page here: https://nixos.org/wiki/Python and in comments from January here: https://github.com/NixOS/nixpkgs/issues/5623 The bottom line is that I am in over my head, and maybe should wait for things to stabalize and documentation to improve, but I think others would benefit from an answer that spells out the step for creating such an environment using python 27, numpy , and some unpackaged library like psychopy since none of the "google-able" sources are consistent. – brittAnderson Sep 28 '15 at 00:22