This question already has answers here:
How do I find out all previous versions of python with which my code is compatible
(4 answers)
How to detect minimum version of python that a script required
(2 answers)
Closed 1 year ago.
I am developing a Python package. It occurred to me that as my codebase changes that it would be useful to be able to automatically check what versions of Python are compatible. In general I could see this being a hard problem, but it seems to me like a naive approach that only looks at core syntax (f-formatting of strings, type hints, etc) to give an estimate of the earliest compatible version would still be useful.
Is there an automatic way to do this?
write tests that use your code from the package
Decide what versions of python you to support
set up continuous integration (CI) that runs your tests on the the those versions of python you support.
Related
This question already has an answer here:
How does Python / pip handle conflicting transitive dependencies?
(1 answer)
Closed 1 year ago.
I used discord.py and r6sapi.
But two packages used aiohttp.
discord.py needs aiohttp<3.8.0, >=3.6.0
r6sapi needs aiohttp<3.0.0, >=2.3.3
how to use two packages same time?
if you want to run multiple versions of python on your machine and switch between them, I think the information in the link below might help
https://realpython.com/intro-to-pyenv/
This question already has an answer here:
Why is Python 3 not backwards compatible? [closed]
(1 answer)
Closed 5 years ago.
Ok, so I'm creating a script on python 3 to do some silent installations.
My problem is that I do not know if the server is going to have python 3 available. Its possible that it has by default python 2 or some Unix Engineer installs python 3.
Now, my question is. Is it possible to run a python 3 script on a python 2?
Should I export the modules I need?
Thanks
Kindof. There is the six module. Its goal is
Six is a Python 2 and 3 compatibility library. It provides utility
functions for smoothing over the differences between the Python
versions with the goal of writing Python code that is compatible on
both Python versions.
It won't do you any good if you need python 3 functionality. Its easy to install python 3 next to python 2 on most systems, so there really isn't much reason to try to struggle with it, though.
I recommend the python-future package for writing code that is compatible with Python 2.7 and Python 3.3+. It is somewhat more convenient than six and allows you to simply write idiomatic Python 3 almost everywhere.
I've dabbled a little bit in Python - not much beyond modifying other people's scripts. Now I'm considering getting into it for real, and have hit the "Choose whether to learn 3.x or 2.x" dilemma. I've read that the main issue with 3.x is the existence of a lot of legacy 2.x code which won't run with 3.x ... but that was a while ago. Is it still the case that backwards-incompatibility is an important consideration against working in Python 3.x?
Note: A similar question was asked 5 years ago:
Is it still too early to hop aboard the Python 3 train?
In my experience, there's only a handful of libraries that are needed for using Python in the real world, and all the major ones have been ported for years and years. Most of the Python 2 only libraries are ones that have become stagnant and are no longer updated (there are probably exceptions, but none that I'm aware of).
The real question, though, is are there any libraries that you need that are Python 2.7 only? If the answer is "No" or "I don't know" then I would definitely suggest starting on Python 3.
Another factor is that it's usually quite easy to take Python 3 code and change it to run on Python 2 (if the need arises), since Python 2.7 has a lot of forwards compatible features. The reverse, taking Python 2 code and porting it to Python 3, is not nearly so clean.
As said in python official documentation
Python 2.x is legacy, Python 3.x is the present and future of the language
And you can check this web app here (or this as #Peque suggests) for python3 library support.
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I want to learn Python. I have a course to do in Python 3. However, I will need to use mainly the matplotlib and Numpy, and these libraries are not yet compatible with Python 3. Is it worth doing the course in Python 3 or will be a waste of time to learn Python 3 and then came back to Python 2.x?
What would you do?
FYI, Matplotlib is now ported to Python 3.
You won't have a problem going back to Python 2.x after learning Python 3, or vice versa. There aren't too many differences. (Some standard library changes, print is a function, all strings are unicode -- you'll never notice most of them).
Realistically, if you learn Python 3 now, and get a job working with Python, you will almost definitely be working with Python 2.x for right now. Python 3 hasn't gained wide adoption yet. However, Python 3 will be more adopted in the near future, as a number of libraries are being ported to Python 3.
If you need to use Matplotlib specifically, then you should use Python 2.7 (no sense in using Python 3 right now if the library you need doesn't work for it). But learning Python 3 first will by no means put you at any disadvantage and may put you ahead of the curve when most people finally make the switch.
There's also nothing stopping you from using both (Python 3 for learning/experimenting, Python 2.7 for work).
"What would you do?"
I would port matplotlib to Python 3. :-)
But no, a course in Python 3 is not wasted. The differences are mainly in the standard library, and in subtle internal differences.
The major differences in the language itself is that the unicode type is called str in Python 3, and that print is a function. The differences are not so big that a course is wasted.
Another way to go is using something like cython which allows you to generate native python libraries that are compatible (without using 2to3 or 3to2) with both 2.x and 3.x. However, it is a bit of work. You do get to use set and dict comprehensions with versions of python that don't support those features though.
This question already has answers here:
Closed 12 years ago.
Possible Duplicates:
Is it advisable to go with Python 3.1 for a beginner?
What version of Python should I use if I’m a new to Python?
Haven't really made anything in Python... Which Python should I take ahold of? 2.X or 3.X?
2.X still offers a far wider variety of third-party libraries / frameworks, instructional websites and books, and experts to help you out -- I expect this will continue for a few years until 3.X gradually overtakes it. Right now, therefore, I would still recommend 2.X despite 3.x's even-greater "clean-ness" and simplicity (because some cruft which 2.x has to keen around for backwards compatibility was finally wiped out in 3.x). Very few new features of 3.x are not backported in 2.x, by the way -- e..g, if you want print to be a function, like in 3.x, in your 2.6 or 2.7 module, just put, at the start of the module, the statement
from __future__ import print_function
"Importing from the future" is a typical Python way to make new features available when explicitly requested, without breaking backwards compatibility.
You are in luck! Due to a lot of confusion about this people have put together a wiki page in the last few days: Should I use Python 2 or 3?
I'd say it depends where you are going to run the code. If you have complete control over the environment, use 3.x. If your environment is controlled externally (cheap webhosting for example) then you will probably need to use 2.x. The only other reason to stick with 2.x is if a critical library you can't live without hasn't been ported to 3.x yet. Don't saddle new code with 2.x-isms if you can avoid it.
2.x
Quite some modules have not yet been ported to python 3 and you will find much more books, online resources for learning python 2.x
You also can't rely on python 3 being preinstalled, while for most linux distributions you can rely on some version of python 2 being available. The only one I know of that already has python 3 packages is the latest Fedora 13. If that matters to you depends on your needs.
See also this related (though not identical) thread on Python 3.0.
While I think the case for 3.x is more compelling than it was a year ago, it still doesn't have the breadth of third-party library coverage of 2.x. I would suggest developing for 2.6 and making use of the migration utilities when the time finally comes (e.g. some dependency is forcing you) to move to 3.x.
If you are just learning Python (and you don't have a specific project you need to complete), I'd suggest that you start with the newest version (3.x). Even if you start with 2.x, though, the basics will be the same, so you will be able to learn any differences in 3.x very quickly.
Go with 2.x
I ran into a lot of compatibility issues with libraries and Python 3.x, although I can't recall which ones specifically. The specific issue I was seeing had to do with unicode strings, which I understand is the default in Python 3. The library threw an exception when using unicode strings, and returned an error for normal ASCII strings. This was about 6 months ago, and I'm assuming the support hasn't drastically improved since then.
If you're absolutely sure you won't use any external libraries, 3.x might not bite you. As a compromise, you could use 2.x and try to avoid the changes in 3.x to make it compatible.