Somehow i have 2 versions of Python 2 installed. The one installed in usr/local/bin is Python 2.7.13 and the one in usr/bin is Python 2.7.6 - i want to keep the 2.6 version and remove the other one.
How do i remove the other one safely ?
Output of which python
/usr/local/bin/python
Also, the symlink points to python2.7 in the usr/local/bin itself.
EDIT: The other version is not 2.6 but 2.7.6, which should be the default version installed.
The default python version on your server is python2.7. If you remove it, you will break your system. Some apps use python2.7 to work.
If you really need to keep python2.6 (old python script for example), just specify the path to python2.6 when executing a script :
/usr/bin/python2.6 some_old_script.py
You can create virtualenv too :
virtualenv -p /usr/bin/python2.6 my_venv
cd my_venv
source bin/activate
Now your venv is active, if you run :
python some_old_script.py
The script will be run in python2.6
To exit the venv :
deactivate
EDIT
Using multiple python versions on the same system is not a problem. It's oftenly required (python2.6, 2.7, 3 etc.)
If by mistake you installed multiple python versions (in our case python2.7.6 and python2.7.13), you can use aliases to point to the version you want to use by default :
alias python=/your/python/path/python2.7.6
Related
I have created a virtual environment using anaconda in VS. When the environment is active. I check the version using python --version, it gives the following output Python 3.9.9, whereas when I use which python and check the version from the path /usr/bin/python --version I get a different version Python 2.7.18. Why is that happening, and which version does the environment use?
Once your virtual environment is activated the python command will use the python version from your venv (located in path/to/.venv/bin/python).
which python and /usr/bin/python forces the use of the python version installed in /usr/bin/python which in your case seems to be version 2.7.18. If you want to change your default Python version (the one thats used with python without a venv being active) you can use sudo ln -s /usr/bin/python /usr/bin/python3.9.
I'm trying to upgrade my python to 2.7.11 on Ubuntu 15.10, by following the guides here
http://tecadmin.net/install-python-2-7-on-ubuntu-and-linuxmint/
http://mbless.de/blog/2016/01/09/upgrade-to-python-2711-on-ubuntu-1404-lts.html
But after, when I try and reopen terminal, and type in python it still shows the version is 2.7.10
Does anyone know why this is the case?
The post you've linked says explicitly in the first sentence: "you should not touch the Python version of the system." i.e., /usr/bin/python should remain the same and therefore if /usr/bin is earlier in your $PATH envvar than the path to the newly installed python version then python invokes /usr/bin/python and you see the old version.
To install/manage multiple minor python versions, you could use pythonz or similar tools (such as pyenv):
$ pythonz install 2.7.11 # to install 2.7.11 version
$ $(pythonz locate 2.7.11) # to start the corresponding version
You could create a virtualenv using the desired python version (using virtualenvwrapper's command):
$ mkvirtualenv -p $(pythonz locate 2.7.11) py2.7.11
python will refer to 2.7.11 version inside the virtual environment.
How can I use python 2.7 for some apps, while keeping python 2.6 for the OS?
I am using CentOS6.6 (based on RHEL 6 / Fedora 12), and would like to install some recent packages such as meld 3.13, latest rabbitcvs, etc...
It requires python 2.6 to run.
when I try to run meld 3.13, it says "Meld requires Python 2.7 or higher."
I have successively installed python 2.7 following this tutorial
http://toomuchdata.com/2014/02/16/how-to-install-python-on-centos/
how can I tell meld to use python2.7 ?
The best way to install python 2.7 on CentOS 6 for some apps only without touching the default system provided python 2.6 is to use Software Collections.
Check page of software collection python27, it provides description how to install it and link to the package.
It works like this: the collection installs packages into separate directory tree in /opt/rh/python27 and doesn't have any effect until it is enabled.
In your case you can create wrapper script which will run your version of meld with python27 collection. For example save following script into ~/bin/meld:
#!/bin/bash
COMMAND="/path/to/your/meld $#"
scl enable python27 "$COMMAND"
Then every time you run meld command, it would be executed by python2.7 (assuming your meld is not already available in your PATH).
See more details in Packaging Wrappers for Software Collections (while you are not packaging anything, the tip with wrapper seems to be useful in your case).
virtualenv is a tool to create isolated Python environments.
For example:
$ python --version # 2.7.6
$ sudo pip install virtualenv
$ mkdir myproject
$ cd myproject
$ virtualenv -p /usr/bin/python3.4 myenv # assign python version
$ . myenv/bin/activate
(myenv)$ python --version # 3.4.3
Now you can use python 3.4 in the virtual environment.
To quit:
$ deactivate
Is it possible to have pyenv switch between two system versions of Python? I have recently installed Ubuntu 14.04 on my laptop, and it comes shipped with both python2 (v2.7.6) and python3 (v3.4.0) commands. (And the command python links to python2).
After installing pyenv, and typing pyenv versions it shows only one entry with * system, which is apparently the python2 version..
Do I need to install Python3 with pyenv, in order for it to be able to switch between Python2 and Python3? (I hope it is not necessary since I already have it installed)
Note: I know that I could just type python3 prog.py to run Python3, or I could insert an alias python=python3 in my ~/.bashrc but this is not what I am looking for. I am more interested to have programs with the #! /usr/bin/env python shebang to run with the Python3 interpreter..
There is a plugin just for this case: pyenv-register.
The default version of Python on Ubuntu 11.10 is 2.7, but I'm looking for 2.6. How do I make it default and where is the executable located?
I type which python2.6 but it returns nothing, yet I did have a python2.6 folder under /usr/lib/python2.6. But it doesn't look like the python2.7 which is at the same path /usr/lib/. Inside the python2.6, there are two folders: dist-packages and lib-dynload.
Actually I am configuring PyDev, and it requires me to specify where the python2.6 executable is. The python2.7 executable has been easily located by just using auto configuration as it is the default.
You can install the package python2.6 (apt-get install python2.6). At this point, the default version of Python will still be 2.7. You can change this via
ln -s /usr/bin/python2.6 /usr/bin/python
Note that there's a decent chance this could cause problems with your system. Several scripts assume the default version of Python is 2.7 and may break when run under a different version. If you have a script that explicitly requires Python 2.6, you can add a shebang at the beginning of your script to specify the version
#!/usr/bin/python2.6
On many systems, one version of python is the default. The rest get called by their name and version number:
~ $ python --version
Python 2.7.2
~ $ python2.6 --version
Python 2.6.7
Per the release notes, these should be available in Oneiric.
Your other questions:
Where is it? Run $ which python2.6 to find out.
How to make it the default? The safest way is to use alias so that change will be only visible to you. Otherwise, if you repoint /usr/bin/python to an unexpected version of Python, you will may break the OS scripts that rely on Python2.7. Rather than changing the default, it is better to just call the specific version of Python you need.