Default python /usr/bin/python instead of /usr/local/bin/python
Asked Answered
S

3

11

I have both python2.6 and python2.7 installed in my CentOS box. python2.6 is installed at /usr/bin/python and i have installed python2.7 from source at location /usr/local/bin/python

after the installation my default python is changed to python2.7 instead of pythn2.6 at /usr/bin, I want to use python 2.6 at /usr/bin/python. I have tried following things already nothing worked.

  1. I have created symlink and made it point to python 2.6 at /usr/bin
  2. I have modified my default python path in .bash_profile and but that still doesn't work

Please let me know how can i have python 2.7 installed along with 2.6 installed and python 2.6 as my default version. I have the same thing working with my arch linux box, but this doesn't work with my centos box.

Attaching my .bash_profile,

# .bash_profile

export _BASH_PROFILE=1

# Get the aliases and functions
if [ -z "$_BASHRC" ]; then
        . ~/.bashrc
fi

unset _BASH_PROFILE

# User specific environment and startup programs

PATH=$PATH:$HOME/bin
BASH_ENV=$HOME/.bashrc
USERNAME=""

export USERNAME BASH_ENV PATH

export user=$(/usr/bin/whoami)
export WK_PORT=8086
export WK_PATH=ADC

# For DEV accounts change PYDOC_PORT value to 7400 + webkit number. For
# example WK23 would be port number 7423
export PYDOC_PORT=7464


alias serve="python -m SimpleHTTPServer"


unset _BASH_PROFILE

# User specific environment and startup programs

PATH=$PATH:$HOME/bin
BASH_ENV=$HOME/.bashrc
USERNAME=""

export USERNAME BASH_ENV PATH

export user=$(/usr/bin/whoami)
export WK_PORT=8086
export WK_PATH=ADC

# For DEV accounts change PYDOC_PORT value to 7400 + webkit number. For
# example WK23 would be port number 7423
export PYDOC_PORT=7464


alias serve="python -m SimpleHTTPServer"


PYTHONPATH="$PYTHONPATH:/usr/bin/python"
Suppletory answered 7/8, 2017 at 18:3 Comment(5)
If you echo your $PATH environment variable, does /usr/local/bin appear before /usr/bin?Kyl
@BrettBeatty yes it does, how can i fix it?Suppletory
I don't know the correct solution here. What that means is your computer looks for python in /usr/local/bin before looking in /usr/bin. It may be as simple as getting rid of /usr/local/bin/python if it's just a symlink to /usr/local/bin/python2.7. It sounds like you installed 2.7 yourself, so I would think it shouldn't break anything, but I don't know enough about your system to say for sure.Kyl
I can remove python2.7 now and i know it will work, but i want to use both versons and for that i have to install it again and the same issue will appearSuppletory
If /usr/local/bin/python is a symlink to /usr/local/bin/python2.7, the latter would be your binary. You can probably call each with the python2.6 and python2.7 commands, respectively. All getting rid of the symlink would do is change which gets referred to by the python command. Disclaimer: I'm going off of my experience with Ubuntu and MacOS--I've never used CentOS.Kyl
S
14

I had the same problem. The following command fixed it:

sudo ln -sf /usr/bin/python /usr/local/bin/python

This will make a symbolic link from /usr/local/bin/python --> /usr/bin/python. Referred from here

Standoff answered 1/5, 2018 at 12:32 Comment(1)
This indeed fixes the issue.Pentastich
T
0

You could use alias to point the command python at the 2.6 folder, and python27 to point at 2.7 like so:

In .bash_profile add:

alias python=/usr/bin/python/<python executable name>
Thundering answered 7/8, 2017 at 18:7 Comment(1)
Can you post your bash profile? Also, edited. Should be python/python26Thundering
S
0

Thanks to @brett-beatty i have referred /usr/local/bin/python symlink to /usr/bin. The compiler looks into /usr/local/bin goes to /usr/bin and uses the correct version also keeps it consistent.

Suppletory answered 8/8, 2017 at 12:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.