How can I install python-dev without sudo?

You can compile your own python from the sources, and then install any modules what you want. http://docs.python.org/devguide/


I know that this is a little bit of necromancy (reviving old posts) but I faced the same issue and could not find an answer, so I'm sharing the one I found...

My solution:

I am working on an ubuntu 16.04 Desktop, with no sudo and only python 2.7 installed. I managed to setup a virtualevn without sudo (following https://stackoverflow.com/questions/9348869/how-to-install-virtualenv-without-using-sudo) and when trying to install jupyter I came across the missing "error: Python.h: No such file or directory".

My solution, not at all clean but at least confined to virtualenv and virtual python folder is:

  1. create a test directory (package_download)
  2. no-sudo@pc:~/package_download$ apt-get download libpython2.7-dev
  3. no-sudo@pc:~/package_download$ apt-get download python-dev
  4. no-sudo@pc:~/package_download$ dpkg -x libpython2.7-dev_2.7.12-1ubuntu0~16.04.1_amd64.deb .
  5. no-sudo@pc:~/package_download$ dpkg -x python-dev_2.7.11-1_amd64.deb .

This will download the library and extract them in your package_download folder. Now comes the dirty part, since pip did not allow me to target this location, I added this files to where they belong, inside the virtualenv folder...

  1. Merge "~/package_download/usr/bin" with the bin directory inside your virtual python installation folder (the one that you used to install virtualenv and create your enviroment) but do not replace any file.
  2. Merge "~/package_download/usr/lib" with the lib directory inside your virtual python folder. No conflicts here.
  3. Copy the contents of "~/package_download/usr/include/python2.7" to your include/python2.7/ folder, no conflicts here. This is actually the most dirty part, since we are modifying the install folder of the virtual python (this do not needs sudo, since is a no-sudo virtual python).
  4. Copy the folder "~/package_download/usr/include/x86_64-linux-gnu" to your include/python2.7/ folder. Copying folders no problem here...

now run your virtual env:

  1. no-sudo@pc:~/running_virtualenv$ source bin/activate
  2. (running_virtualenv)no-sudo@pc:~/running_virtualenv$ pip install jupyter
  3. enjoy...

If you found that your include/python2.7/ is a symbolic link then you have mistaken the virtualenv folder with the virtual python folder. (Thanks @andrzej1_1 for finding this issue)