How can I use Python 2.6 in Ubuntu 11.10? - python

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.

Related

Remove Python from usr/local/bin - 2 versions installed

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

What version of Python is on my Mac?

I have a mac, when I do:
python --version
I got:
Python 2.7.6
but when I got to:
/System/Library/Frameworks/Python.framework/Versions/3.3
where is 2.7.6 located ?
any advice what should I do?
UPDATE:
$ which -a python python3
/usr/bin/python
/usr/local/bin/python3
$ brew list python python3
Error: No such keg: /usr/local/Cellar/python
$ locate python
WARNING: The locate database (/var/db/locate.database) does not exist.
To create the database, run the following command:
sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.locate.plist
Please be aware that the database can take some time to generate; once
the database has been created, this message will no longer appear.
in PyCharm editor, the default settings interpreter shows:
You could have multiple Python versions on your macOS.
You may check that by command, type or which command, like:
which -a python python2 python2.7 python3 python3.6
Or type python in Terminal and hit Tab few times for auto completion, which is equivalent to:
compgen -c python
By default python/pip commands points to the first binary found in PATH environment variable depending what's actually installed. So before installing Python packages with Homebrew, the default Python is installed in /usr/bin which is shipped with your macOS (e.g. Python 2.7.10 on High Sierra). Any versions found in /usr/local (such as /usr/local/bin) are provided by external packages.
It is generally advised, that when working with multiple versions, for Python 2 you may use python2/pip2 command, respectively for Python 3 you can use python3/pip3, but it depends on your configuration which commands are available.
It is also worth to mention, that since release of Homebrew 1.5.0+ (on 19 January 2018), the python formula has been upgraded to Python 3.x and a python#2 formula will be added for installing Python 2.7. Before, python formula was pointing to Python 2.
For instance, if you've installed different version via Homebrew, try the following command:
brew list python python3
or:
brew list | grep ^python
it'll show you all Python files installed with the package.
Alternatively you may use apropos or locate python command to locate more Python related files.
To check any environment variables related to Python, run:
env | grep ^PYTHON
To address your issues:
Error: No such keg: /usr/local/Cellar/python
Means you don't have Python installed via Homebrew. However double check by specifying only one package at a time (like brew list python python2 python3).
The locate database (/var/db/locate.database) does not exist.
Follow the advice and run:
sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.locate.plist
After the database is rebuild, you can use locate command.
To check third version, we can use,
python3 --version
To install python on macOS, we need to install command line developer tools. From Catalina, python is removed from OS bundle. For more information, Apple Official and Python Official.
Use below command to see all python installations :
which -a python
Use the which command. It will show you the path
which python
Take a look at the docs regarding Python on Mac.
The version at /System/Library/Frameworks/Python.framework is installed by Apple and is used by the system. It is version 3.3 in your case. You can access and use this Python interpreter, but you shouldn't try to remove it, and it may not be the one that comes up when you type "Python" in a terminal or click on an icon to launch it.
You must have installed another version of Python (2.7) on your own at some point, and now that is the one that is launched by default.
As other answers have pointed out, you can use the command which python on your terminal to find the path to this other installation.
You can use python official installer. It's very easy and interactive.
Refer https://www.python.org/downloads/release/python-2716/
Just type python and then hit tab-button You will get the list of all the python available in your os

I can't change the default Python version from Apple supplied 2.7.2 to 3.2.2 (OS10.7)

in Lion, have installed python 3.2.2 from python.org. It comes with a terminal command that is supposed to move this version of python earlier by updating my shell profile. When i run it, and then check my default python in Terminal, it still says 2.7.2 which is the Apple supplied one.
Do I need to run the command with sudo to get it to change the default python to 3.2.2?
I've also tried the VERSIONER method but it doesn't work.
For Python 3 interpreters, you must enter python3 not python.
$ python -V
Python 2.7.2
$ python3 -V
Python 3.2.2
For more background on the current recommendation that python refer to a version of Python 2 and python3 refer to a version of Python 3, see the draft PEP 394 - The "python" Command on Unix-Like Systems.
Unfamiliar with osX, but as several system applications might depend on a certain python version, it might be a bad idea to swap the default.
One alternative that might suite your needs is to use pythonbrew, it allows you to have several python versions side by side and lets you set a default version on a user to user basis, without having to meddle with your system python, among other things. It is the equivalent of RVM for those who are familiar with ruby, or a sort of virtualenv for python interpreters. One big advantage is that it allows you to easily install and use the exact python versions you need independently from what is available in your operating system.
Some examples:
Install a python interpreter:
pythonbrew install 2.7.2
Permanently use the specified python (for current user):
pythonbrew switch 2.7.2
pythonbrew switch 3.2
Use the specified python in current shell:
pythonbrew use 2.7.2
Runs a named python file against specified and/or all pythons:
pythonbrew py test.py
pythonbrew py -v test.py # Show verbose output
pythonbrew py -p 2.7.2 -p 3.2 test.py # Use the specified pythons
The only downside of pythonbrew, is the need of a compiler and header files, and that an install can take a bit of time, as it compiles from source.

How to set defualt python library path

I'm using FreeBSD 7.2. I upgraded to Python 2.6. However when I run any python app, it is still using /usr/local/lib/pytho25 as the library path. How do I change it? I cannot modify the python app. Basically I need to change the default lib path to python26.
Are you sure you're using the new binary? I'm not familiar with FreeBSD, but with OpenBSD you have to do a ln -s /usr/local/bin/python2.6 /usr/local/bin/python if you want to start it as python. Perhaps it still points the old way? Also there is PYTHONPATH
You can creat a softlink to your desiered python executable:
$ cd /usr/bin
$ ln -s python2.6 python
This way python command points to python2.6
You have probably not migrated correctly to python 2.6 as you should no longer have python 2.5
You can follow the UPDATING notes here to completely get rid of python2.5 (this is for python2.7 but you can safely follow those instructions):
http://www.freshports.org/lang/python27/

How to make python_select work for '$>python' command?

I installed a couple of pythons in different versions with macports, and the apple python 2.6 is also working. Now I need to run a program which requires MySQLdb package support in python, and this package was installed to the python I installed by macports. The program tells me that there is no MySQLdb installed, so I guess it is the apple python working for that program.
I searched for some help and found python_select for switching between pythons. However after the command
$>sudo python_select python25
told me that it selected the version "python25" for python, when I type
$>python
it is still apple python 2.6 that launches.
The question is that how can I make python25(the one with MySQLdb) work for the program rather than apple python?
Another important thing, the program is NOT a .py file and needs to be compiled before running. So do I need to re-install this program? My Mac OS version is Snow Leopard 10.6.
Any answer is appreciated.
By default, MacPorts installs user programs (or links to them) in /opt/local/bin. The MacPorts select_python command selects which python instance is linked to /opt/local/bin/python. It has no effect (nor should it) on what Apple installs in /usr/bin, which is where the Apple-supplied python and python2.x commands are.
To invoke the MacPorts python2.5, you either need to ensure that /opt/local/bin precedes /usr/bin on your shell $PATH (you can do this by modifying your .bash_profile or other shell initialization script) or you can simply invoke the desired python with an absolute path reference:
$ /usr/bin/python your-program.py
to use the Apple-supplied default python;
$ /opt/local/bin/python your-program.py
to use the version selected with python_select, or:
$ /opt/local/bin/python2.5 your-program.py
to explicitly select the MacPorts 2.5 one.
EDIT:
To modify your search PATH to use MacPorts, add this line to .bash_profile:
export PATH=/opt/local/bin:/opt/local/sbin:$PATH
First, I am not sure with Mac, coz I never use it before.
but in Linux, when I do whereis python
It will show like /usr/bin/python /usr/local/bin/python ....etc
in my .bashrc file, I just export PATH=/usr/local/bin:/usr/bin:$PATH when I want /usr/local/bin more priority
or you still can run like
/usr/bin/python yourpython.py
or
/usr/local/bin/python yourpython.py
depends on your python install locations
just my 2 cents. sorry if my answer dont make you any helps.
'python' in the Mac is just a link. Do a 'which python', 'cd' to the directory in which 'python' resides, and then do an 'ls -a py*'. You shall see where python is pointing too. If you want that python to point to your different version of python, just make it link to the right version.

Categories

Resources