Discussion:
[ale] Slightly OT: System default python version
Todor Fassl via Ale
2018-01-24 23:03:33 UTC
Permalink
I got a question from a student who is using python. "I'd rather not
hard code in any python version. Is there any reason to have the system
default be 2 instead of 3?"

He had asked me to install the python-matplotlib package. I was like,
"Are you sure you want python-matplotlib and not python3-matplotlib?" He
is still coding in python2.7 instead of python3 but not by choice. Is
there such a thing as a system default python version? To program in
python3, doesn't he have to modify his code?
--
Todd
_______________________________________________
Ale mailing list
***@ale.org
http://mail.ale.org/mailman/listinfo/ale
See JOBS, ANNOUNCE and SCHOOLS lists at
http://mail.ale.org/mailman/listinfo
Pete Hardie via Ale
2018-01-24 23:08:18 UTC
Permalink
#!/usr/bin/python3 at the start of the file, and set the execution bits?
I got a question from a student who is using python. "I'd rather not hard
code in any python version. Is there any reason to have the system default
be 2 instead of 3?"
He had asked me to install the python-matplotlib package. I was like, "Are
you sure you want python-matplotlib and not python3-matplotlib?" He is
still coding in python2.7 instead of python3 but not by choice. Is there
such a thing as a system default python version? To program in python3,
doesn't he have to modify his code?
--
Todd
_______________________________________________
Ale mailing list
http://mail.ale.org/mailman/listinfo/ale
See JOBS, ANNOUNCE and SCHOOLS lists at
http://mail.ale.org/mailman/listinfo
--
Pete Hardie
--------
Better Living Through Bitmaps
Putnam, James M. via Ale
2018-01-24 23:28:42 UTC
Permalink
Lots of, maybe most, of 2.7, and 3 are common. Some potentially useful
things, like map and filter, are named the same but function very differently.
Ideally 3 should have been a proper superset of 2.x, but Guido evidently
decided differently, and it isn't.

If he doesn't use any of the named-the-same-but-different features he
can use either 2.7 or 3.

--
James M. Putnam
Visiting Professor of Computer Science

The air was soft, the stars so fine,
the promise of every cobbled alley so great,
that I thought I was in a dream.
________________________________________
From: Ale [ale-***@ale.org] on behalf of Todor Fassl via Ale [***@ale.org]
Sent: Wednesday, January 24, 2018 6:03 PM
To: Atlanta Linux Enthusiasts
Subject: [ale] Slightly OT: System default python version

I got a question from a student who is using python. "I'd rather not
hard code in any python version. Is there any reason to have the system
default be 2 instead of 3?"

He had asked me to install the python-matplotlib package. I was like,
"Are you sure you want python-matplotlib and not python3-matplotlib?" He
is still coding in python2.7 instead of python3 but not by choice. Is
there such a thing as a system default python version? To program in
python3, doesn't he have to modify his code?

--
Todd
_______________________________________________
Ale mailing list
***@ale.org
http://mail.ale.org/mailman/listinfo/ale
See JOBS, ANNOUNCE and SCHOOLS lists at
http://mail.ale.org/mailman/listinfo
_______________________________________________
Ale mailing list
***@ale.org
http://mail.ale.org/mailman/listinfo/ale
See JOBS, ANNOUNCE and SCHOOLS lists at
http://mail.ale.org/mailman/listinfo
Jim Kinney via Ale
2018-01-25 01:19:28 UTC
Permalink
Rhel, and centos, still use python 2.7 as system default. Python 3.4 is optional. Most of the system management is python 2.7. Fedora ships with both 2.7 and 3.6

Lot's of python 2 code can work in 3. But there's enough changes that it can't be relied upon to work without modifications.

New python projects should be with version 3, not 2.
Post by Todor Fassl via Ale
I got a question from a student who is using python. "I'd rather not
hard code in any python version. Is there any reason to have the system
default be 2 instead of 3?"
He had asked me to install the python-matplotlib package. I was like,
"Are you sure you want python-matplotlib and not python3-matplotlib?" He
is still coding in python2.7 instead of python3 but not by choice. Is
there such a thing as a system default python version? To program in
python3, doesn't he have to modify his code?
--
Todd
_______________________________________________
Ale mailing list
http://mail.ale.org/mailman/listinfo/ale
See JOBS, ANNOUNCE and SCHOOLS lists at
http://mail.ale.org/mailman/listinfo
--
Sent from my Android device with K-9 Mail. All tyopes are thumb related and reflect authenticity.
Jay Lozier via Ale
2018-01-25 01:59:32 UTC
Permalink
Arch defaults to Python 3 with 2.7 available for packages that require it.
Post by Jim Kinney via Ale
Rhel, and centos, still use python 2.7 as system default. Python 3.4
is optional. Most of the system management is python 2.7. Fedora ships
with both 2.7 and 3.6
Lot's of python 2 code can work in 3. But there's enough changes that
it can't be relied upon to work without modifications.
New python projects should be with version 3, not 2.
I got a question from a student who is using python. "I'd rather not
hard code in any python version. Is there any reason to have the system
default be 2 instead of 3?"
He had asked me to install the python-matplotlib package. I was like,
"Are you sure you want python-matplotlib and not python3-matplotlib?" He
is still coding in python2.7 instead of python3 but not by choice. Is
there such a thing as a system default python version? To program in
python3, doesn't he have to modify his code?
--
Sent from my Android device with K-9 Mail. All tyopes are thumb
related and reflect authenticity.
_______________________________________________
Ale mailing list
http://mail.ale.org/mailman/listinfo/ale
See JOBS, ANNOUNCE and SCHOOLS lists at
http://mail.ale.org/mailman/listinfo
DJ-Pfulio via Ale
2018-01-25 03:08:09 UTC
Permalink
Post by Todor Fassl via Ale
I got a question from a student who is using python. "I'd rather not
hard code in any python version. Is there any reason to have the system
default be 2 instead of 3?"
He had asked me to install the python-matplotlib package. I was like,
"Are you sure you want python-matplotlib and not python3-matplotlib?" He
is still coding in python2.7 instead of python3 but not by choice. Is
there such a thing as a system default python version? To program in
python3, doesn't he have to modify his code?
There are 2 major ways for python versions to be decided.

a) If you are making an application that needs to run on every OS, then
the developer should specify the exact version necessary and provide any
libs needed for it. It should be self-contained and not dependent on
whatever the OS python or OS python libraries happen to be. Ruby and
perl both provide tools for self-contained deployments in this way.
Python definitely does as well.

b) If you are making an application to be added to an existing OS, then
the platform/distro decides the version and everything you code should
work with that version and the libraries provided for it through the
package manager.

I read somewhere that Ubuntu will be switching to Python3 as the primary
platform version in 18.04. https://wiki.ubuntu.com/Python

[quote]All Ubuntu/Canonical driven development should be targeting
Python 3 right now, and all new code should be Python 3-only.
[/quote]
_______________________________________________
Ale mailing list
***@ale.org
http://mail.ale.org/mailman/listinfo/ale
See JOBS, ANNOUNCE and SCHOOLS lists at
http://mail.ale.org/mailman/listinfo
Charles Shapiro via Ale
2018-01-25 12:32:43 UTC
Permalink
Another Correct way to specify the interpreter is:

<code>
#!/usr/bin/env python
</code>

Guarantees that you'll get the first "python" in ${PATH}. On most
Debian-based systems, that is a softlink to the current default version. On
my Slink (yeah, I know, I'm updating soon) it goes to "/usr/bin/python",
which is a symlink to "/usr/bin/python2.7". It may also be a symlink to a
symlink in /etc/alternatives.

This is really a bash thing rather than a python thing. The trick is to get
the bash interpreter to invoke the correct program to run your script, be
it python, perl, or another language.


-- CHS
Post by DJ-Pfulio via Ale
Post by Todor Fassl via Ale
I got a question from a student who is using python. "I'd rather not
hard code in any python version. Is there any reason to have the system
default be 2 instead of 3?"
He had asked me to install the python-matplotlib package. I was like,
"Are you sure you want python-matplotlib and not python3-matplotlib?" He
is still coding in python2.7 instead of python3 but not by choice. Is
there such a thing as a system default python version? To program in
python3, doesn't he have to modify his code?
There are 2 major ways for python versions to be decided.
a) If you are making an application that needs to run on every OS, then
the developer should specify the exact version necessary and provide any
libs needed for it. It should be self-contained and not dependent on
whatever the OS python or OS python libraries happen to be. Ruby and
perl both provide tools for self-contained deployments in this way.
Python definitely does as well.
b) If you are making an application to be added to an existing OS, then
the platform/distro decides the version and everything you code should
work with that version and the libraries provided for it through the
package manager.
I read somewhere that Ubuntu will be switching to Python3 as the primary
platform version in 18.04. https://wiki.ubuntu.com/Python
[quote]All Ubuntu/Canonical driven development should be targeting
Python 3 right now, and all new code should be Python 3-only.
[/quote]
_______________________________________________
Ale mailing list
http://mail.ale.org/mailman/listinfo/ale
See JOBS, ANNOUNCE and SCHOOLS lists at
http://mail.ale.org/mailman/listinfo
Ed Cashin via Ale
2018-01-25 13:55:45 UTC
Permalink
But this might be a good opportunity for education. The "I don't want to
hard code the specifics" inclination probably comes from a principle that
the student has just learned. It is true that when there is no advantage
to hard-coding externalities, one should avoid it. That way you don't get
"tight coupling" without need, and you have more modularity, more reusable
components.

However, sometimes the externalities matter a lot. In this case, Python 2
and 3 are different enough that I don't think it's safe to write toward an
abstraction "#! /usr/bin/env python".

You could try, by writing lowest-common-denominator code, but it would be
dangerous, because anyone coming to your code later (or your future self)
would not necessarily know about tricky situations. For example, below you
get two answers from the same simple arithmetic expression. It is probably
better to hard-code *at least* the fact that it's either Python 2 or 3
code, because tightly coupling the code to the interpreter is safer and
more simple in this case. Python 2 and 3 are not really the same
interpreter.

(normal) bash$ ipython
Python 2.7.10 (default, Oct 23 2015, 19:19:21)
Type "copyright", "credits" or "license" for more information.

IPython 2.2.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.

In [1]: from __future__ import print_function

In [2]: print(11 / 10)
1

In [3]:
Do you really want to exit ([y]/n)? y

(That thing about importing from future is the kind of stuff the student
would have to get used to if trying to support 2 and 3.)

Now switch to Python 3.

(normal) bash$ . ~/environments/py36/bin/activate

(py36) bash$ ipython
Python 3.6.2 (default, Sep 25 2017, 14:00:54)
Type 'copyright', 'credits' or 'license' for more information
IPython 6.2.1 -- An enhanced Interactive Python. Type '?' for help.

In [1]: from __future__ import print_function

In [2]: print(11 / 10)
1.1

In [3]:
Do you really want to exit ([y]/n)?
(py36) bash$
Post by Charles Shapiro via Ale
<code>
#!/usr/bin/env python
</code>
Guarantees that you'll get the first "python" in ${PATH}. On most
Debian-based systems, that is a softlink to the current default version. On
my Slink (yeah, I know, I'm updating soon) it goes to "/usr/bin/python",
which is a symlink to "/usr/bin/python2.7". It may also be a symlink to a
symlink in /etc/alternatives.
This is really a bash thing rather than a python thing. The trick is to
get the bash interpreter to invoke the correct program to run your script,
be it python, perl, or another language.
-- CHS
Post by DJ-Pfulio via Ale
Post by Todor Fassl via Ale
I got a question from a student who is using python. "I'd rather not
hard code in any python version. Is there any reason to have the system
default be 2 instead of 3?"
He had asked me to install the python-matplotlib package. I was like,
"Are you sure you want python-matplotlib and not python3-matplotlib?" He
is still coding in python2.7 instead of python3 but not by choice. Is
there such a thing as a system default python version? To program in
python3, doesn't he have to modify his code?
There are 2 major ways for python versions to be decided.
a) If you are making an application that needs to run on every OS, then
the developer should specify the exact version necessary and provide any
libs needed for it. It should be self-contained and not dependent on
whatever the OS python or OS python libraries happen to be. Ruby and
perl both provide tools for self-contained deployments in this way.
Python definitely does as well.
b) If you are making an application to be added to an existing OS, then
the platform/distro decides the version and everything you code should
work with that version and the libraries provided for it through the
package manager.
I read somewhere that Ubuntu will be switching to Python3 as the primary
platform version in 18.04. https://wiki.ubuntu.com/Python
[quote]All Ubuntu/Canonical driven development should be targeting
Python 3 right now, and all new code should be Python 3-only.
[/quote]
_______________________________________________
Ale mailing list
http://mail.ale.org/mailman/listinfo/ale
See JOBS, ANNOUNCE and SCHOOLS lists at
http://mail.ale.org/mailman/listinfo
_______________________________________________
Ale mailing list
http://mail.ale.org/mailman/listinfo/ale
See JOBS, ANNOUNCE and SCHOOLS lists at
http://mail.ale.org/mailman/listinfo
--
Ed Cashin <***@noserose.net>
Phil Turmel via Ale
2018-01-25 15:13:01 UTC
Permalink
There are some big differences in handling strings and byte arrays that
will eat one's lunch. There are quite a few built-in functions that
were removed in v3 and/or changed to be quite different.

I highly recommend "Practical Python porting for systems programmers"
by Peter A. Donis and Eric S. Raymond.

http://www.catb.org/esr/faqs/practical-python-porting/

That document offers some strategies for making your python code
compatible with both v2 and v3. It is not simple.
Post by Todor Fassl via Ale
I got a question from a student who is using python. "I'd rather not
hard code in any python version. Is there any reason to have the system
default be 2 instead of 3?"
He had asked me to install the python-matplotlib package. I was like,
"Are you sure you want python-matplotlib and not python3-matplotlib?" He
is still coding in python2.7 instead of python3 but not by choice. Is
there such a thing as a system default python version? To program in
python3, doesn't he have to modify his code?
_______________________________________________
Ale mailing list
***@ale.org
http://mail.ale.org/mailman/listinfo/ale
See JOBS, ANNOUNCE and SCHOOLS lists at
http://mail.ale.org/mailman/listinfo
Jeff Hubbs via Ale
2018-01-25 17:42:34 UTC
Permalink
Post by Todor Fassl via Ale
I got a question from a student who is using python. "I'd rather not
hard code in any python version. Is there any reason to have the
system default be 2 instead of 3?"
He had asked me to install the python-matplotlib package. I was like,
"Are you sure you want python-matplotlib and not python3-matplotlib?"
He is still coding in python2.7 instead of python3 but not by choice.
Is there such a thing as a system default python version? To program
in python3, doesn't he have to modify his code?
In Gentoo Linux you can install a number of Python versions and have an
overall and a default for each of Python2 and Python3. In fact, there's
a mechanism to make the package manager go around the system and change
which Python implementation gets invoked by apps that are already
installed, and you can also single out or otherwise limit which Python
version is used on a package-by-package basis.

He will not necessarily have to recode for 3.x, but if he does it's
probably not going to be a nightmare. I've actually had slightly more
trouble going from 3.4 to 3.6 than I have 2.7 to 3.6, just as a function
of the specifics I've encountered (i.e., generalize my experience at
your peril).

_______________________________________________
Ale mailing list
***@ale.org
http://mail.ale.org/mailman/listinfo/ale
See JOBS, ANNOUNCE and SCHOOLS lists at
http://mail.ale.org/mailman/listinfo
Ted W. via Ale
2018-01-27 05:17:09 UTC
Permalink
Maybe I'm missing something here but I have to ask why the student isn't
using something like pyenv to configure the version of python and the
modules they need for the particular project. In my admittedly limited
python development experience developing for older systems (CentOS 5 and
6) it was common for the system to have an extremely out of date python
version available in the upstream repositories. Instead of relying on
what I could get from the vendor I would use virtual envs to configure
whatever version I wrote in and install all of the modules necessary on
the target system. Is this not possible or am I missing some piece of
the question?
I got a question from a student who is using python. "I'd rather not hard
code in any python version. Is there any reason to have the system default
be 2 instead of 3?"
He had asked me to install the python-matplotlib package. I was like, "Are
you sure you want python-matplotlib and not python3-matplotlib?" He is still
coding in python2.7 instead of python3 but not by choice. Is there such a
thing as a system default python version? To program in python3, doesn't he
have to modify his code?
--
Todd
_______________________________________________
Ale mailing list
http://mail.ale.org/mailman/listinfo/ale
See JOBS, ANNOUNCE and SCHOOLS lists at
http://mail.ale.org/mailman/listinfo
Kyle Brieden via Ale
2018-02-05 21:40:18 UTC
Permalink
I know I'm behind, but I just wanted to bump this response and say that
this is the correct response. If he's learning, he needs to learn
right.

---
Very respectfully,
Kyle Brieden
Post by Ted W. via Ale
Maybe I'm missing something here but I have to ask why the student isn't
using something like pyenv to configure the version of python and the
modules they need for the particular project. In my admittedly limited
python development experience developing for older systems (CentOS 5 and
6) it was common for the system to have an extremely out of date python
version available in the upstream repositories. Instead of relying on
what I could get from the vendor I would use virtual envs to configure
whatever version I wrote in and install all of the modules necessary on
the target system. Is this not possible or am I missing some piece of
the question?
I got a question from a student who is using python. "I'd rather not hard
code in any python version. Is there any reason to have the system default
be 2 instead of 3?"
He had asked me to install the python-matplotlib package. I was like, "Are
you sure you want python-matplotlib and not python3-matplotlib?" He is still
coding in python2.7 instead of python3 but not by choice. Is there such a
thing as a system default python version? To program in python3, doesn't he
have to modify his code?
--
Todd
_______________________________________________
Ale mailing list
http://mail.ale.org/mailman/listinfo/ale
See JOBS, ANNOUNCE and SCHOOLS lists at
http://mail.ale.org/mailman/listinfo
_______________________________________________
Ale mailing list
http://mail.ale.org/mailman/listinfo/ale
See JOBS, ANNOUNCE and SCHOOLS lists at
http://mail.ale.org/mailman/listinfo
leam hall via Ale
2018-02-05 21:59:16 UTC
Permalink
Not really. Using something like pyenv or rvm adds complication that
may or may not work. If they are a student then reduction in
complexity directly impacts learning potential.

Few students are going to start coding at a level that the system's
base can't take them. Once the initial skills are gained, along with
confidence and a liberal dose of desire, add the packages and
virtualization of pyenv or rvm. Until then it is more likely to cause
the student to use a different language or to drop programming
completely.

Except when you watch people on IRC swear pyenv/rvm is easy but the
HOWTO pages they point you to don't work and they have no clue. Then
it's sort of funny in a sad way.

I've been doing this for a while and still don't care to use pyenv/rvm/whatever.
I know I'm behind, but I just wanted to bump this response and say that this
is the correct response. If he's learning, he needs to learn right.
---
Very respectfully,
Kyle Brieden
Post by Ted W. via Ale
Maybe I'm missing something here but I have to ask why the student isn't
using something like pyenv to configure the version of python and the
modules they need for the particular project. In my admittedly limited
python development experience developing for older systems (CentOS 5 and
6) it was common for the system to have an extremely out of date python
version available in the upstream repositories. Instead of relying on
what I could get from the vendor I would use virtual envs to configure
whatever version I wrote in and install all of the modules necessary on
the target system. Is this not possible or am I missing some piece of
the question?
I got a question from a student who is using python. "I'd rather not hard
code in any python version. Is there any reason to have the system default
be 2 instead of 3?"
He had asked me to install the python-matplotlib package. I was like, "Are
you sure you want python-matplotlib and not python3-matplotlib?" He is still
coding in python2.7 instead of python3 but not by choice. Is there such a
thing as a system default python version? To program in python3, doesn't he
have to modify his code?
--
Todd
_______________________________________________
Ale mailing list
http://mail.ale.org/mailman/listinfo/ale
See JOBS, ANNOUNCE and SCHOOLS lists at
http://mail.ale.org/mailman/listinfo
_______________________________________________
Ale mailing list
http://mail.ale.org/mailman/listinfo/ale
See JOBS, ANNOUNCE and SCHOOLS lists at
http://mail.ale.org/mailman/listinfo
_______________________________________________
Ale mailing list
http://mail.ale.org/mailman/listinfo/ale
See JOBS, ANNOUNCE and SCHOOLS lists at
http://mail.ale.org/mailman/listinfo
_______________________________________________
Ale mailing list
***@ale.org
http://mail.ale.org/mailman/listinfo/ale
See JOBS, ANNOUNCE and SCHOOLS lists at
http://mail.ale.org/mailman/listinfo

Loading...