Using Different Versions of Python - Compatibility/Dependencies?

  • Python
  • Thread starter WWGD
  • Start date
  • #1
WWGD
Science Advisor
Gold Member
2019 Award
5,316
3,091

Main Question or Discussion Point

Hi All,
I am trying to learn versions 2,3 of Python ( long story). Just curious as to the "Dependency/Compatibility" issues between and within versions 2 and 3. Are packages/libraries in 3.x available for 3.x' where x'>x ? How about for version 2? Specifically, at this point, I am trying to do some Web Scraping. If I learn to use it with one version, how likely am I of being able to do the same or similar within an other
 

Answers and Replies

  • #2
Borg
Science Advisor
Gold Member
1,874
2,310
I am fairly new to Python also. I chose to go with 3 right away and a lot of examples use 2. However, I haven't had too many issues using version 2 examples with my version 3 code.
 
  • Like
Likes WWGD
  • #3
WWGD
Science Advisor
Gold Member
2019 Award
5,316
3,091
I am fairly new to Python also. I chose to go with 3 right away and a lot of examples use 2. However, I haven't had too many issues using version 2 examples with my version 3 code.
Have you been able to do Web Scraping with more than one version?
 
  • #4
Borg
Science Advisor
Gold Member
1,874
2,310
Haven't done that. I've been focused on machine learning code.
 
  • Like
Likes WWGD
  • #5
WWGD
Science Advisor
Gold Member
2019 Award
5,316
3,091
Haven't done that. I've been focused on machine learning code.
And you have been able to go back-and-forth between versions?
EDIT: Do you use Graphlab or something else for ML?
 
  • #6
Borg
Science Advisor
Gold Member
1,874
2,310
I haven't been doing that. I just said that I've had few problems using the version 2 examples in my version 3 environment. BTW, why do you want to use both versions anyway? I could understand if you had a large collection of version 2 code that you built but, if you're as new to Python as I am, you're better off just going with the newer version.
 
  • #7
WWGD
Science Advisor
Gold Member
2019 Award
5,316
3,091
I haven't been doing that. I just said that I've had few problems using the version 2 examples in my version 3 environment. BTW, why do you want to use both versions anyway? I could understand if you had a large collection of version 2 code that you built but, if you're as new to Python as I am, you're better off just going with the newer version.
I agree, it is just that I have seen jobs that look interesting that require 2 , some require 3. Just covering my bases. I will start with 2 with Anaconda, I guess, in the meantime become familiar with 3 and IDLE. What IDE do you use?
 
  • #8
Borg
Science Advisor
Gold Member
1,874
2,310
If I saw a job that required version 2, that would tell me that they have a lot of legacy code that they need to maintain. Call me silly but I wouldn't want to be a janitor. :oldtongue:

As for my IDE, I've been coding everything in Jupyter.
 
  • Like
Likes phinds
  • #9
WWGD
Science Advisor
Gold Member
2019 Award
5,316
3,091
If I saw a job that required version 2, that would tell me that they have a lot of legacy code that they need to maintain. Call me silly but I wouldn't want to be a janitor. :oldtongue:

As for my IDE, I've been coding everything in Jupyter.
Do you have access to Graphlab? SFrames? How do you code, e.g., a regression without them?
 
  • #10
Borg
Science Advisor
Gold Member
1,874
2,310
Haven't heard of that.
 
  • #11
WWGD
Science Advisor
Gold Member
2019 Award
5,316
3,091
Haven't heard of that.
So you just code, say a a regression without any additional packages? Sorry if I am being ignorant here, but I have to import other packages before doing any ML
 
  • #12
Borg
Science Advisor
Gold Member
1,874
2,310
I'm using pip and conda installs to download everything locally. Keep in mind that I'm still learning Python and I'm not dealing with gigantic data sets at this point. My focus is on learning the details of ML algorithms and there's plenty I can do on a laptop for now.
 
  • Like
Likes scottdave and WWGD
  • #13
WWGD
Science Advisor
Gold Member
2019 Award
5,316
3,091
I'm using pip and conda installs to download everything locally. Keep in mind that I'm still learning Python. I'm not dealing with gigantic data sets at this point. My focus is on learning the details of ML algorithms and there's plenty I can do on a laptop for now.
Ok, I do things in a kind of disorganized way, bottom-up learning from a source, top-down by reading someone else's code and eventually comes together in my brain.
 
  • Like
Likes Borg
  • #14
WWGD
Science Advisor
Gold Member
2019 Award
5,316
3,091
Sorry, don't mean to drag this too long, but, would you consider any version of Python 3 before the latest, e.g., 3.4 instead of 3.7?
 
  • #15
Borg
Science Advisor
Gold Member
1,874
2,310
If I needed to. I was using 3.6 for a while.
 
  • #16
PeterDonis
Mentor
Insights Author
2019 Award
29,638
8,906
Specifically, at this point, I am trying to do some Web Scraping.
I have done web scraping with BeautifulSoup in both Python 2 and Python 3. There isn't much difference between the two. The kind of code you will need to write for web scraping will be pretty much the same in both versions.

https://pypi.org/project/beautifulsoup4/
 
  • Like
Likes Paul Colby, WWGD and Borg
  • #17
11,805
5,426
One key difference is the divide operator. In 2 its returns ints if given ints but in 3 it returns floats. You must use the // to integer divides. // is complementary to % for modular math.
 
  • Like
Likes WWGD
  • #18
WWGD
Science Advisor
Gold Member
2019 Award
5,316
3,091
One key difference is the divide operator. In 2 its returns ints if given ints but in 3 it returns floats. You must use the // to integer divides. // is complementary to % for modular math.
Thanks. That also reminds me of the difference between raw input in 2 and input() in 3.
 
  • #19
11,805
5,426
I would suggest using 3 and not 2 unless the project calls for using 2 for legacy support.
 
  • Like
Likes WWGD
  • #20
WWGD
Science Advisor
Gold Member
2019 Award
5,316
3,091
I would suggest using 3 and not 2 unless the project calls for using 2 for legacy support.
Thanks, but, what then, must one then move on to the next version/generation -- I guess Python 4 -- and so on indefinitely?
 
  • #21
11,805
5,426
Another was ord() returned the ascii code in 2 whereas in 3 you must use int() i think.
 
  • #22
11,805
5,426
This is the common issue developers always face ie use the latest or stick with what works. For major changes you have to weight program life with support for version it uses vs upgrading.
 
  • Like
Likes WWGD
  • #23
PeterDonis
Mentor
Insights Author
2019 Award
29,638
8,906
must one then move on to the next version/generation -- I guess Python 4 -- and so on indefinitely?
Eventually, but not on any short time scale. Python 2.7, the last version of Python 2, was first released in 2010; Python 2 itself was first released in 2000; and the Python 2 series is being end of lifed by the core developers in 2020. So you're looking at 10 to 20 years between having to switch versions.
 
  • Like
Likes WWGD
  • #24
FactChecker
Science Advisor
Gold Member
5,583
2,060
This is a philosophical objection I have to Python as a scripting language, versus Perl. The Perl philosophy is "there are many ways to do it" and they try to accept any syntax where they can understand the intent. The Python philosophy seems to be "this is the perfect way to do it and you must comply". That is until the next version comes out and the new philosophy is "this is the new super-duper, perfect way to do it and the old way was TERRIBLE and unacceptable." The Python changes sometimes require rewrites. The changes I needed to make to decades-old Perl scripts were minimal.
 
  • #25
PeterDonis
Mentor
Insights Author
2019 Award
29,638
8,906
The Python philosophy seems to be "this is the perfect way to do it and you must comply".
This has never been the Python philosophy. The Zen of Python has this:

"There should be one—and preferably only one—obvious way to do it."

Although Tim Peters couldn't resist following that with this:

"Although that way may not be obvious at first unless you're Dutch."

But in any case, nothing requires you to do it the obvious way.

[1] https://en.wikipedia.org/wiki/Zen_of_Python

That is until the next version comes out and the new philosophy is "this is the new super-duper, perfect way to do it and the old way was TERRIBLE and unacceptable."
Within a given Python version (2 or 3), I'm not aware of any change that made a previous way to do it no longer doable. Plenty of changes opened up new ways to do things, but those never invalidated the old ways.

The Python 2 to Python 3 change certainly did break a lot of old ways of doing things, but that was on purpose and the Python devs were quite open about that for years in advance. Also, Python 2 has stayed around and fully supported for 10 years while Python 3 was refined.

The Python changes sometimes require rewrites.
Do you have an example within a single Python version (2 or 3)?
 
  • Like
Likes jedishrfu

Related Threads on Using Different Versions of Python - Compatibility/Dependencies?

  • Last Post
Replies
2
Views
2K
Replies
1
Views
368
Replies
1
Views
1K
  • Last Post
Replies
8
Views
3K
Replies
2
Views
4K
Replies
9
Views
12K
Replies
21
Views
1K
Replies
2
Views
2K
Replies
2
Views
2K
  • Last Post
Replies
0
Views
2K
Top