Using Different Versions of Python - Compatibility/Dependencies?

  • Thread starter WWGD
  • Start date
  • Tags
    Python
In summary: The divide operator in Python 3 is different from the divide operator in Python 2. You must use the // to integer divides. // is complementary to % for modular math.
  • #36
scottdave said:
My first exposure to it was version 3.5, I think. I have come across code examples which were written for 2.x One thing I found is that the print statements work different in 2. and 3.
In 2.x, it is a statement. You would type
Code:
print "Hello, World"
for example.
In 3.x it is a function. The argument of the function must be enclosed in parenthesis:
Code:
print("Hello, World")

Yes, I think the designers of Python changed from supporting print as a feature of the language to making it a function call instead as is done in many other languages like C/C++. (BASIC had a print statement that was a feature of the language).
 
Technology news on Phys.org
  • #37
Borg said:
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.
But there are some ML packs designed for 2.7 that are not yet available AFAIK, for 3.x . Specifically, Graphlab , with SFrames . I learned these in a class years back and prefer to build on what I know, so I use both Anaconda and Idle. Graphlab has a lot of nice stuff to it, easy to use.
 
  • #38
WWGD said:
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

Many people have given the answer to use python3. My suggestion is also to start with python3 when someone starting fresh. I would not bother much about minor versions like 3.6 vs 3.7 etc.
Broadly I do the following
1) Use pip and virtualenv, create a local setup completely - does not touch the python given by the OS
2) I mainly use Debian GNU/Linux so that almost every package is available to install from Debian itself, just do apt-get install. You could get similar results with other distributions like Ubuntu, Mint, MX Linux, Fedora etc. too.
 
  • Like
Likes scottdave and StoneTemplePython
  • #39
Anand Sivaram said:
Many people have given the answer to use python3. My suggestion is also to start with python3 when someone starting fresh. I would not bother much about minor versions like 3.6 vs 3.7 etc.
Broadly I do the following
1) Use pip and virtualenv, create a local setup completely - does not touch the python given by the OS
2) I mainly use Debian GNU/Linux so that almost every package is available to install from Debian itself, just do apt-get install. You could get similar results with other distributions like Ubuntu, Mint, MX Linux, Fedora etc. too.
I agree,but some of the package s for ML I have learnt, specifically Graphlab with SFrames , which are very effective are , last I checked, available only for 2.7 . If they became available for 3, I would fully drop 2.
 
  • Like
Likes Anand Sivaram
  • #40
WWGD said:
I agree,but some of the package s for ML I have learnt, specifically Graphlab with SFrames , which are very effective are , last I checked, available only for 2.7 . If they became available for 3, I would fully drop 2.

Dato/Grahlab was bought by Apple a few years ago. The fact that they still aren't on python 3.x is a bit ominous. Maybe it's time to get on SKLearn instead, and use Python 3.x.

I understand that there are good legacy packages. But they are basically legacy packages. If you're new-ish to the language you'd be wise to not entangle yourself in any legacy issues. I did a system cleanup recently and no longer have 2.x as part of my conda / ipython setup.

The decision is yours of course but it's also a bad idea for a Newbie (reference thread title) to override advice from more experienced hands.

There's probably something about Fleetwood Mac and how once youre in 2.x you can never break the chain.
 
  • Like
Likes lomidrevo
  • #41
Unfortunately I am in a sort of no-man's-land of having spent enough on Graphlab, which allows me to do ML without much h effort. But don't worry, I do listen to those who have been at it longer than I .
 
  • #42
In a discussion of this very subject yesterday at work, two comments were made that kind of puts this question to rest.

Python 3.x (x < 6) were essentially no better than python 2.7 because they were fixing the errors introduced with the updates. So, 3.6 is the best version of python out there.

Support for python 2.7 and earlier will end at the end of 2019, so why would anyone want to write new python codes in a version that will not be supported any longer, or more succinctly, why would anyone write in python 2.7 in 2019 and beyond?
 
  • #43
Dr Transport said:
so why would anyone want to write new python codes in a version that will not be supported any longer, or more succinctly, why would anyone write in python 2.7 in 2019 and beyond?
If some essential tools are not compatible with the new version, then there is no alternative to programming in the older version. I have run into that in another language.
 
  • #44
As for IDE, supposedly the best one is PyCharm (community is free). But most people nowadays probably use VS Code.
 
  • #45
Python 3's incompatibility with the extensive archives of Python 2 code floating around the web is a slow-motion disaster. Very little effort has been made to go back and tag open source code and docs with version numbers, and you can't trust anything to work out of the box anymore. As mentioned above, Perl, for all its crufty sins, still does the job year after year. Python is in such a sad state that AOSP compiles its Python 2.7 interpreter straight from source code to insure compatibility.
 
  • #46
Dr Transport said:
Python 3.x (x < 6) were essentially no better than python 2.7 because they were fixing the errors introduced with the updates.

I think that's too extreme. I would say that Python 3.3 had reached the point where the errors introduced in the 2 to 3 change had been fixed and the functionality was at least equivalent to 2.7. By 3.6 some genuinely new functionality (such as the async and await keywords) had been added.
 
  • #47
PeterDonis said:
I think that's too extreme. I would say that Python 3.3 had reached the point where the errors introduced in the 2 to 3 change had been fixed and the functionality was at least equivalent to 2.7. By 3.6 some genuinely new functionality (such as the async and await keywords) had been added.

Just quoting my co-worker who is working the issue at work currently. I know that there was a step-back when 3+ was rolled out, that was to be expected, there usually is a little set of issues.
 
  • #48
Choosing a language for a project is important and nontrivial. For web scraping (never heard of it so I watched half a youtube vid making me essentially an expert) one might want to look at the design patterns Python 3 supports which Python 2 doesn't support easily. Decorators come to mind. Some of the f-string stuff is nice. My 1.2 cents.
 
  • #49
If you are learning then just learn Python 3. If you need to write Python 2 just write Python 3 and fix the errors as you find them in your tests. I used that approach years ago, I didn't know basic so I wrote fortran and it didn't take long to get productive.
 
  • Like
Likes Paul Colby
  • #50
flywire said:
If you are learning then just learn Python 3. If you need to write Python 2 just write Python 3 and fix the errors as you find them in your tests. I used that approach years ago, I didn't know basic so I wrote fortran and it didn't take long to get productive.
But the problem is I learned just a bit of Python 2.7 with ML SFrames and this is not available in 3
 
  • #51
Perhaps it's worth asking what ML SFrame'esk lib is in python 3? Sometimes names change to protect the innocent. Other times newer options have sprung up. Data mining the web is a going concern. Seems odd no python 3 options are included.

P.S. are you using pip? Have you looked at virtual environments? Both are essential IMO for python development. (not that I've done much, but I know people who have)
 
  • #53
Any suggestion on web scraping? I am kind of worried about associated legal issues. Should I stick to using APIs?
 
  • #54
I lied, I only watched 1/4 of the youtube video. I really have nothing to suggest.
 
  • #55
WWGD said:
Any suggestion on web scraping? I am kind of worried about associated legal issues.

If you're just scraping sites that are publicly visible anyway, I don't see why there would be any legal issues; everything on the page is there for the public to see. The site might throttle you if it detects that you're requesting too much data in too short a time, but that's a technical issue, not a legal issue; you just need to scrape at a slow enough rate, the same way the web crawlers for Google and other search engines do.
 
<h2>1. What is the difference between Python 2 and Python 3?</h2><p>Python 2 and Python 3 are two different versions of the Python programming language. Python 2 was released in 2000 and Python 3 was released in 2008. Python 3 was created to fix some of the flaws and inconsistencies in Python 2 and to make the language more efficient and modern. Some of the major differences between the two versions include changes to the print function, string handling, and the use of Unicode.</p><h2>2. Can I run code written in Python 2 on a Python 3 interpreter?</h2><p>No, code written in Python 2 is not compatible with a Python 3 interpreter. The syntax and some of the built-in functions are different between the two versions, so code written in Python 2 will not run on a Python 3 interpreter without making some changes.</p><h2>3. Are there any compatibility issues when using different versions of Python?</h2><p>Yes, there can be compatibility issues when using different versions of Python. Code written in one version may not run on a different version without making some changes. Additionally, some libraries and packages may only be compatible with certain versions of Python, so it is important to check compatibility before using them.</p><h2>4. How can I manage dependencies when using different versions of Python?</h2><p>One way to manage dependencies when using different versions of Python is to use virtual environments. Virtual environments allow you to create isolated environments for different projects, each with its own dependencies and versions of Python. This way, you can avoid conflicts and ensure that your code runs smoothly.</p><h2>5. Is it necessary to upgrade to Python 3 if I am currently using Python 2?</h2><p>It is not necessary to upgrade to Python 3 if you are currently using Python 2. However, Python 2 will no longer be supported after 2020, so it is recommended to switch to Python 3 in order to receive updates and support. Additionally, many new libraries and packages are being developed for Python 3, so you may miss out on new features and advancements if you continue to use Python 2.</p>

1. What is the difference between Python 2 and Python 3?

Python 2 and Python 3 are two different versions of the Python programming language. Python 2 was released in 2000 and Python 3 was released in 2008. Python 3 was created to fix some of the flaws and inconsistencies in Python 2 and to make the language more efficient and modern. Some of the major differences between the two versions include changes to the print function, string handling, and the use of Unicode.

2. Can I run code written in Python 2 on a Python 3 interpreter?

No, code written in Python 2 is not compatible with a Python 3 interpreter. The syntax and some of the built-in functions are different between the two versions, so code written in Python 2 will not run on a Python 3 interpreter without making some changes.

3. Are there any compatibility issues when using different versions of Python?

Yes, there can be compatibility issues when using different versions of Python. Code written in one version may not run on a different version without making some changes. Additionally, some libraries and packages may only be compatible with certain versions of Python, so it is important to check compatibility before using them.

4. How can I manage dependencies when using different versions of Python?

One way to manage dependencies when using different versions of Python is to use virtual environments. Virtual environments allow you to create isolated environments for different projects, each with its own dependencies and versions of Python. This way, you can avoid conflicts and ensure that your code runs smoothly.

5. Is it necessary to upgrade to Python 3 if I am currently using Python 2?

It is not necessary to upgrade to Python 3 if you are currently using Python 2. However, Python 2 will no longer be supported after 2020, so it is recommended to switch to Python 3 in order to receive updates and support. Additionally, many new libraries and packages are being developed for Python 3, so you may miss out on new features and advancements if you continue to use Python 2.

Similar threads

  • Programming and Computer Science
Replies
17
Views
1K
Replies
6
Views
545
  • Programming and Computer Science
Replies
10
Views
2K
  • Programming and Computer Science
Replies
6
Views
1K
  • Programming and Computer Science
Replies
8
Views
1K
  • Programming and Computer Science
Replies
1
Views
1K
  • Programming and Computer Science
Replies
3
Views
1K
  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
15
Views
1K
  • Programming and Computer Science
Replies
2
Views
2K
Back
Top