2

Is it possible currently? I tried to remove python in Fedora 19 but yum depends on it.

hgajshb
  • 3,865
  • 4
  • 19
  • 18
  • 1
    What do you want to know? Why do you want the system only with python3? In modern distributions you can have multiple versions of python co-exists without any problem. – number5 Jul 19 '13 at 05:12
  • 4
    You can avoid Python 2 in Arch and Gentoo for example. – cnd Jul 19 '13 at 05:34
  • 3
    ArchLinux is even one step further: python is alias for python3, not for python2 as in all other distros. – IBr Jul 19 '13 at 05:49
  • 1
    See my answer below. You should never remove these packages, use a tool such as pyenv to manage multiple versions of python in your environment. – slm Jul 20 '13 at 04:20
  • I just want to isolate out Python 2 altogether from the system. If there are packages that still rely on it, then I'll look for alternative ones that utilize Py3 instead or adjust the code myself. I am juggling virtenvs as it is, but there shouldn't be a need to do so if everyone switches to Py3. I know there is legacy code, and although there are automations for the switch it still needs a human touch, but it's been years since 3 is out. – Iliyan Bobev Jun 26 '14 at 09:05
  • Ubuntu 16.04 will ship with only Python 3. – Janus Troelsen Mar 11 '16 at 12:53

3 Answers3

3

You should never try to uninstall packages such as Python and Perl on a given system. Much of the internal plumbing of the distro depends on these specific packages.

If you have a need for specific versions of Python, Perl, Ruby etc. you should really get in the habit of using systems such as the following to setup your own local versions of these interpreters:

pyenv

This project used to be known as pythonbrew, but is now known as pyenv. To install it you need to clone a copy of it into your $HOME directory like so:

$ git clone git://github.com/yyuu/pyenv.git ~/.pyenv
Cloning into .pyenv...
remote: Counting objects: 2207, done.
remote: Compressing objects: 100% (617/617), done.
remote: Total 2207 (delta 1489), reused 2172 (delta 1462)
Receiving objects: 100% (2207/2207), 358.75 KiB, done.
Resolving deltas: 100% (1489/1489), done.

Now add the setup of pyenv to your ~/.bashrc file:

$ echo 'export PATH="$HOME/.pyenv/bin:$PATH"' >> ~/.bashrc
$ echo 'eval "$(pyenv init -)"' >> ~/.bashrc

Now re-source your .bashrc:

$ source ~/.bashrc

You can see the usage of pyenv:

$ pyenv 
pyenv 0.4.0-20130613-17-ge1ea64b
Usage: pyenv <command> [<args>]

Some useful pyenv commands are:
   commands    List all available pyenv commands
   local       Set or show the local application-specific Python version
   global      Set or show the global Python version
   shell       Set or show the shell-specific Python version
   install     Install a Python version using the python-build plugin
   uninstall   Uninstall a specific Python version
   rehash      Rehash pyenv shims (run this after installing executables)
   version     Show the current Python version and its origin
   versions    List all Python versions available to pyenv
   which       Display the full path to an executable
   whence      List all Python versions that contain the given executable

See `pyenv help <command>' for information on a specific command.
For full documentation, see: https://github.com/yyuu/pyenv#readme

You can see what versions are available:

$ pyenv versions
* system (set by /home/saml/.pyenv/version)

Install build requirements

Now let's install Python 3.2.5:

$ pyenv install 3.2.5
Downloading Python-3.2.5.tgz...
-> http://yyuu.github.io/pythons/ed8d5529d2aebc36b53f4e0a0c9e6728
Installing Python-3.2.5...
Installed Python-3.2.5 to /home/saml/.pyenv/versions/3.2.5

Downloading setuptools-0.9.5.tar.gz...
-> https://pypi.python.org/packages/source/s/setuptools/setuptools-0.9.5.tar.gz
Installing setuptools-0.9.5...
Installed setuptools-0.9.5 to /home/saml/.pyenv/versions/3.2.5

Downloading pip-1.3.1.tar.gz...
-> http://yyuu.github.io/pythons/cbb27a191cebc58997c4da8513863153
Installing pip-1.3.1...
Installed pip-1.3.1 to /home/saml/.pyenv/versions/3.2.5

Rebuild our environment to incorporate new install:

$ pyenv rehash

Now we should see 2 versions available, system is still the default (*):

$ pyenv versions
* system (set by /home/saml/.pyenv/version)
  3.2.5

Let's switch to 3.2.5:

$ pyenv which python
/usr/bin/python

$ pyenv global 3.2.5

$ pyenv which python
/home/saml/.pyenv/versions/3.2.5/bin/python

$ pyenv versions
  system
* 3.2.5 (set by /home/saml/.pyenv/version)

See also:

virtualenv & virtualenvwrapper

These 2 Python modules provide you mechanisms for maintaining separate workspaces where site-packages can be maintained. They a good option if you want to isolate sets of Python modules into sets and associate them to a given Python application. They're a little awkward to use but do the job.

There's a screencast that shows how to use virtualenvwrapper as well. For Python I'd setup virtualenv first, followed by virtualenvwrapper.

Example

$ sudo easy_install virtualenv
$ easy_install virtualenvwrapper

At this point the 2 Python modules have been installed. From here you need to setup your environment, add the following to your $HOME/.bashrc file:

export WORKON_HOME=$HOME/.virtualenvs
source /usr/bin/virtualenvwrapper.sh

Now re-source your .bashrc:

$ source ~/.bashrc

Now you're ready to list your work environments:

$ workon
$

You don't have any yet, so let's create one, we'll call it "temp":

$ mkvirtualenv temp
New python executable in temp/bin/python
Installing setuptools................done.

Now when we re-list our worksets using workon:

(temp)$ workon
temp

Notice the prompt has changed so that the workspace is prefixed in front of your prompt. Now, to remove it:

(temp)$ rmvirtualenv temp
Removing temp...
ERROR: You cannot remove the active environment ('temp').
Either switch to another environment, or run 'deactivate'.

Can't so deactivate it, and your prompt is back to normal:

(temp)$ deactivate
$

Now try to remove it:

$ rmvirtualenv temp
Removing temp...

Now let's recreate it again, and cd to our workspace:

$ mkvirtualenv temp
New python executable in temp/bin/python
Installing setuptools................done.

(temp)$ cdvirtualenv 
(temp)$ ls
bin  include  lib  lib64

Now check out the "temp" workspace site-packages:

$ cdsitepackages 
(temp)$ pwd
/home/saml/.virtualenvs/temp/lib/python2.7/site-packages

Now let's install a Python module, smooshy, first let's search for it using pip:

(temp)$ pip search smooshy
smooshy                   - Automatic lossless image compression

Now install it:

(temp)$ pip install smooshy
Downloading/unpacking smooshy
  Downloading smooshy-1.tar.gz
  Running setup.py egg_info for package smooshy

Requirement already satisfied (use --upgrade to upgrade): simplejson in /usr/lib64/python2.7/site-packages (from smooshy)
Installing collected packages: smooshy
  Running setup.py install for smooshy
    changing mode of build/scripts-2.7/smooshy from 664 to 775

    changing mode of /home/saml/.virtualenvs/temp/bin/smooshy to 775
Successfully installed smooshy
Cleaning up...

To confirm where it was installed:

(temp)$ which smooshy
~/.virtualenvs/temp/bin/smooshy
Evgeny
  • 5,476
slm
  • 369,824
2

Python 2 and 3 are not compatible, so you need Python 2 for programs written in it. And most programs are still in Python 2. Also Python 2 is still being maintained.

So you almost can't have a distribution without Python 2. Except the ones like Arch and Gentoo.. You will also have to avoid programs that use Python 2, since they cant be interpreted with Python 3 interpreter. You can have multiple versions of Python installed though. I have Python 2.5, 2.7 and 3 without any problems.

Alko
  • 922
1

Arch Linux can run with Python 3 only last I checked. I remember because it updated to it when I installed system updates and all my scripts stopped working.