2

I ssh to a server running Debian Linux (Release 6.0.2) to run my python scripts. The python version installed on the server is 2.6.6. It is installed in /usr/bin/python2.6 (and symbolically linked to /usr/bin/python). I'm very new to Linux. I want to install python 2.7.8 on the server without effecting, and in a way transparent, to other users of the server. What is the best way to do this? My idea was to install in /usr/bin/python2.7 so that I can use run my scripts as below:

$python2.7 myScript.py

But I'm not fully aware how such an installation will effect other users. Also if I want to install packages (like cv2) how should I go about doing it for my version of python

Sanket
  • 746
  • 3
  • 13
  • 26

1 Answers1

1

I think you'd better to install with compiling python 2.7.8 in your home directory. That's definitely clear for the others. 'update-alternatives' command makes system default python version change.

In my case, I made hidden directory '.opt' on my account. Then downloaded and extracted source code from python.org (https://www.python.org/ftp/python/2.7.8/Python-2.7.8.tgz) with below command.

$ cd $HOME
$ mkdir -p .opt
$ wget https://www.python.org/ftp/python/2.7.8/Python-2.7.8.tgz
$ tar zxvf Python-2.7.8.tgz

It'll make Python-2.7.8 directory on your account home. So change directory Python-2.7.8.

$ cd Python-2.7.8

Please configure with 'prefix' option. In my case '--prefix=$HOME/.opt'.

$ ./configure --prefix=$HOME/.opt

It'll be configured with setting at your home directory. After than you can 'make' and 'make install'.

$ make && make install

If there are no errors, you can find directories for python binaries in .opt directory. $HOME/.opt/bin/python is new one. Please set path environment variable in your profile in .bashrc or .profile.

$ echo "export PATH=$HOME/.opt/bin:$PATH" >> $HOME/.bashrc

It'll be works only for your account.

Jachin
  • 66
  • 4
  • If you can't be satisfied for the installation, you can just delete the directories and path settings in .bashrc. – Jachin Jul 29 '14 at 18:07
  • But what if I want to install new modules for python, like cv2, for my version of python? Any idea how do I do that? – Sanket Jul 29 '14 at 22:37
  • Before to use cv2, there are some python libraries are needed by cv2. setuptools, numpy, nose – Jachin Jul 30 '14 at 01:49
  • 1
    Before to use cv2, there are some python libraries are needed by cv2. setuptools, numpy, nose So try to install that packages with below commands. setuptools: $ wget https://bootstrap.pypa.io/ez_setup.py -O - | python nose: $ wget https://pypi.python.org/packages/source/n/nose/nose-1.3.3.tar.gz $ tar zxvf nose-1.3.3.tar.gz $ cd nose-1.3.3 $ python setup.py install $ cd $HOME numpy: $ wget http://downloads.sourceforge.net/project/numpy/NumPy/1.8.1/numpy-1.8.1.tar.gz Cause limitation of comment, I need to cut this comment. – Jachin Jul 30 '14 at 01:56
  • Or your system already have cv2 module on system path, please follow this post. http://stackoverflow.com/questions/19876079/opencv-cannot-find-module-cv2 – Jachin Jul 30 '14 at 02:05