Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Updating and replacing system Python takes tremendous blood and treasure. Compiling python from scratch, updating symlinks, resolving dependency issues and finally debugging the whole thing is no small endeavour. Been there, done that; never again.

(This was on a Ubuntu LTS system)




I've done this dozens of times, didn't seem like that big of a deal? I think the place this might have fallen over is the "updating symlinks" part. Don't replace the system Python, install yours alongside it. They don't need to know anything about each other; aliases in developers profiles and full paths in services/scripts.


Yup, stick it in /usr/local and place that in your PATH and Python search path before other dependencies. If you want to be fancy, put it somewhere in your home directory so other users on your same machine cannot be affected.

It's really not hard. I do this with other compilers and don't really have issues, though I tend to package it up into a container if I'm going to ship it (e.g. build environment for a team, interpretor for a production service, etc).


Or you could, just like on other platforms and with other languages, use virtual environments with a version manager such as pyenv for your development environment. Combine that with pipenv and you get pretty painless python development. To be fair, some of this stuff is more recent though.


Here is an excellent short blog describing all this and how pyenv and pipenv click together to create a virtual Python environment, that is completely independent of your OS vendor's runtime: https://gioele.io/pyenv-pipenv

This stuff is definitely quite new, and I guess the need for it has risen as a consequence of all the great new features that have shipped in Python during the last few years.

I recently had to write an utility script in Python. I chose to use Python 3 and type hints syntax, requiring at least Python 3.6. This was a problem when I realized some of my team use Ubuntu and Debian versions that ship with Python 3.5 (not to speak of Macs with Python 2.x, but these guys use homebrew anyway). Plenty of time was spent researching virtual environments and writing deployment instructions, and I ended up using pip in pyenv (but stopped short of using pipenv, since creating private distributable packages with it seemed convoluted.)


You could just use Anaconda or a similar system.


Go there once, script it, and never do it manually again.


Oh, you mean all that work that package maintainers do for not cost to you?

Not to mention there are other distribution tools to acquire a pre-built python release other than installing a .deb.


It's hard if you're trying to update the system Python and need to upgrade every dependency for that but if you just want to have, say, “python3.7” in your path it's just a couple of commands:

https://docs.python-guide.org/starting/install3/linux/

    ~ $ docker run -it --rm ubuntu:xenial
    root@b8cda311d766:/# apt-get update -qqy
    root@b8cda311d766:/# apt-get install -qqy software-properties-common
    …
    root@b8cda311d766:/# add-apt-repository --yes ppa:deadsnakes/ppa
    gpg: keyring `/tmp/tmpe354n0av/secring.gpg' created
    gpg: keyring `/tmp/tmpe354n0av/pubring.gpg' created
    gpg: requesting key 6A755776 from hkp server keyserver.ubuntu.com
    gpg: /tmp/tmpe354n0av/trustdb.gpg: trustdb created
    gpg: key 6A755776: public key "Launchpad PPA for deadsnakes" imported
    gpg: Total number processed: 1
    gpg:               imported: 1  (RSA: 1)
    OK
    root@b8cda311d766:/# apt-get update -qqy
    root@b8cda311d766:/# apt-get install -qqy python3.7
    debconf: delaying package configuration, since apt-utils is not installed
    Selecting previously unselected package libpython3.7-minimal:amd64.
    (Reading database ... 7603 files and directories currently installed.)
    Preparing to unpack .../libpython3.7-minimal_3.7.3-1+xenial1_amd64.deb ...
    Unpacking libpython3.7-minimal:amd64 (3.7.3-1+xenial1) ...
    Selecting previously unselected package python3.7-minimal.
    Preparing to unpack .../python3.7-minimal_3.7.3-1+xenial1_amd64.deb ...
    Unpacking python3.7-minimal (3.7.3-1+xenial1) ...
    Selecting previously unselected package libpython3.7-stdlib:amd64.
    Preparing to unpack .../libpython3.7-stdlib_3.7.3-1+xenial1_amd64.deb ...
    Unpacking libpython3.7-stdlib:amd64 (3.7.3-1+xenial1) ...
    Selecting previously unselected package python3.7-lib2to3.
    Preparing to unpack .../python3.7-lib2to3_3.7.3-1+xenial1_all.deb ...
    Unpacking python3.7-lib2to3 (3.7.3-1+xenial1) ...
    Selecting previously unselected package python3.7-distutils.
    Preparing to unpack .../python3.7-distutils_3.7.3-1+xenial1_all.deb ...
    Unpacking python3.7-distutils (3.7.3-1+xenial1) ...
    Selecting previously unselected package python3.7.
    Preparing to unpack .../python3.7_3.7.3-1+xenial1_amd64.deb ...
    Unpacking python3.7 (3.7.3-1+xenial1) ...
    Processing triggers for mime-support (3.59ubuntu1) ...
    Setting up libpython3.7-minimal:amd64 (3.7.3-1+xenial1) ...
    Setting up python3.7-minimal (3.7.3-1+xenial1) ...
    Setting up libpython3.7-stdlib:amd64 (3.7.3-1+xenial1) ...
    Setting up python3.7-lib2to3 (3.7.3-1+xenial1) ...
    Setting up python3.7-distutils (3.7.3-1+xenial1) ...
    Setting up python3.7 (3.7.3-1+xenial1) ...
    root@b8cda311d766:/# python3.7
    Python 3.7.3 (default, Mar 26 2019, 01:59:45) 
    [GCC 5.4.0 20160609] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> 
    root@b8cda311d766:/# exit
    ~ $




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: