Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Switch between Python versions as non root

Tags:

python

I just installed Python 2.7 in our server, they had 2.4 installed before hand.

After I built the new version, my path is still pointing to the old version of python, do you know an easy way to change this.

I do not have sudo permissions nor root access.

like image 257
Leon palafox Avatar asked Mar 11 '26 08:03

Leon palafox


2 Answers

Because you are on the server and don't have root permissions, the best choice for you is to use virtualenv

Build Python 2.7, for example, as following:

$ ./configure --prefix=~/mydir
$ make
$ make install

Download virtualen.py file and run:

$ ~/mydir/bin/python virtualenv.py my_environment

This will create an isolated Python 2.7 environment for you inside my_environment directory.

To activate it run source my_environment/bin/activate and that's it. Now python executable will be your Python 2.7. Additionally you will have pip installed and thus can easily install any additional libraries into your environment.

like image 200
Maxim Avatar answered Mar 13 '26 04:03

Maxim


First, you should check your ~/.profile and your shells config files (e.g. ~/.bashrc for bash) for any export $PATH= (or PYTHONPATH, depending on what you're referring to exactly) directives containing the offending path. If there are some, change them and relogin. That should fix your problem.

If it doesn't, talk to your admin. If that doesn't help either, you can do the following. In your shell, run (may substitute PATH with PYTHONPATH, depending on what you really need):

echo $PATH

copy the output and modify it according to your needs. Then open another shell and run (remember the substitution):

export PATH="whatever you copied before"

check that everything is fine (i.e. that you can still call all applications you need and that your path is adapted accordingly). If that's the case, add the command to your ~/.profile.

like image 41
Jonas Schäfer Avatar answered Mar 13 '26 04:03

Jonas Schäfer