Search code examples
pythonubuntupippyyaml

How to pip install compiled libraries like PyYAML without root access on ubuntu


I am having a terribly difficult time getting the Python module PyYAML to install / compile. I am working in a constrained linux environment (Ubuntu 14.04, I do not have root). I don't think the issue is unique to PyYAML beyond the fact that it is the first library I've needed that requires gcc extensions to build.

I have managed to apt-get the following packages in a user folder because I cannot write to root owned folders but could try others if that makes more sense.

  • python2.7-dev
  • python3-dev

I've modified a few environment variables that have allowed me to get a partially operational python environment. The apt-get target install is ${DEPS_DIR}/apt:

export PYTHONHOME="${DEPS_DIR}/apt/usr"
export PYTHONIOENCODING=utf8
export CPATH="${DEPS_DIR}/apt/usr/include/python2.7:${DEPS_DIR}/apt/usr/include"
export PATH="${DEPS_DIR}/apt/usr/local/bin"

I suspect I'm missing one or more variables or have paths in the wrong order to make this work properly. Most searches on SO for the issue I'm seeing take for granted you can just sudo install.

This is the specific error I'm seeing when trying to pip install PyYAML:

In file included from ext/_yaml.h:2:0, from ext/_yaml.c:271: /usr/include/yaml.h:633:1: note: expected ‘yaml_char_t *’ but argument is of type ‘char *’ yaml_mapping_start_event_initialize(yaml_event_t *event, ^ x86_64-linux-gnu-gcc: internal compiler error: Killed (program cc1) Please submit a full bug report, with preprocessed source if appropriate. See for instructions. error: command 'x86_64-linux-gnu-gcc' failed with exit status 4

I am using pip -V 9.0.1 and python -V is 2.7.6. I tried to get virtualenv and wrapper installed at one point but didn't seem to really get it working like I can on my laptop.


Solution

  • For some of the more troublesome python dependencies, there are oftentimes additional packages that can be installed locally to avoid some of the extension compilation issues.

    The two libraries both have system packages that avoid needing to compile:

    apt-get python-yaml
    apt-get python-websocket