Need some help converting the following to 2.7 from 3.6. Made it for someone now they want it in 2.7 :/ - Appreciate any help. Having a tough time. Some reason it is outputting all 0's - maybe some of the operators have changed?
https://hastebin.com/yazisebewa.md
You might want to try future statements. Basically, keep the code the way it is, and backport features to 2.7. I already see the print statements causing problems, so at the top just add from __future__ import print_statement. This will cause Python 2.7 to read print as if it were running in 3.x. Running the code through trial and error, backporting features as needed might be the best way to accomplish your goal. I will be happy to help with any further problems.
Related
I have been looking at similar problems and everyone has a promising solution which usually revolves around changing the interpreter path. I have done my best but have run out of solutions that I can think of. I'm hoping someone else knows how and thank you for any comments.
No version of python ever appears, I have tried to enter the path in the box at the top but have had no luck
I want to switch from 3.10 to 3.9 and this is when not being able to select the version of python became a problem. The picture above is from the terminal within VS Code
This is the default path I have entered in VS Code
The photo above is from the Windows command prompt, locating the active version of python
I would like to be able to use Python 3.10 in some folders and 3.9 in others, however at the moment I really just need VS Code to see 3.9, I imagine once I know what has gone wrong at this stage it will be smooth sailing from here.
I have already uninstalled and reinstalled pretty much anything I can think could be related
I really hope I have just made a stupid mistake somewhere and it is really obvious, thank you again
I'm totally new in Python and I want to use the "shape context"-algorithm in Python. I saw on github that someone already made the effort to program this, but I think his program code was used with OpenCV 2 and it is not compatible with OpenCV 3.
Because of the missing experience I don't know how to fix his code to work on OpenCV 3.
I want to take this algorithm in Python because my previous programming is also in Python.
Please help me and don't be to rude if I made mistakes.
I would try using 2to3 library.
https://docs.python.org/2/library/2to3.html.
If it still doesn't work, You are left with either changing not working parts Yourself(asking someone who will do it for You) or using 2.7 interpreter.
I'm trying to use a github project (TIA), which is dependent on Python 2.7. However, all of the scripts I'm using in the main project are written to run on Anaconda 3 (Python 3.x).
Is there a way for me to run TIA on Python 3.x, even though it says its 2.7 dependent? TIA pulls financial data from Bloomberg's API, and what I'm trying to do is hand that data off to my Python 3.x scripts.
Appreciate any insight on how I should be accomplishing this!
Is there a way for me to run TIA on Python 3.x, even though it says
its 2.7 dependent?
Short answer: no.
Long(er) answer: yes, but you'll have to either adapt the source-code yourself, find someone who has already done it (maybe there is some Python3 compatible fork on Git?). Or you might run python 2.7 to execute the code and write a Python3 script that transforms the output into an acceptable form.
If you are willing to update the source code you could of course use Python2.7's 2to3 module, of which the documentation is found here. Do not expect it to generate a flawless result however, but it might smoothen the ride..
How would I use 2 different python mods in the same file when both mods require different python versions? I am trying to write a program that uses pygame, which only works with 3.2 and pymssql, which only works with 3.3. I get errors if I try to run them both in the same file(on either python version), but not if I run them separately.
There is no simple solution for you. In my opinion, it is the pygame communitie's responsibility to make it work on Python 3.3. Python 3.3 has a higher potential to be widely distributed than Python 3.2. Also, "supporting Python 3" nowadays should mean supporting Python 3.3/3.4, and not only Python 3.2. I guess this is on the todo list of the pygame maintainers. If in doubt, you might want to ask on the corresponding forums/mailing list if supporting Python 3.3 is already planned.
If you are curious and not frightened, you might event want to dig into why pygame fails on Python 3.3 and start fixing issue by issue. I guess this effort will be highly appreciated.
Edit:
I was assuming that you did your research homework a bit :-) Looks like pygame is available for Python 3.3:
https://bitbucket.org/pygame/pygame/downloads
Thanks #batbrat.
A person for which I am working under constantly has reserves about me updating programs that were written in python 2.5 and 2.7 to python 3.3. I work in bioninformatics and a lot of the python code I am trying to work with is pre 3.0 and while I have a linux that runs 2.7 it on a virtual machine, on my main machine I am already at python 3.3 and develop my programs with it. I understand that if the program has heavy reliance on the libraries then there could be some compatibility issues but besides that I don't see why I can't just spend a little time upgrading it. I feel I should clarify that most of this programs are not much more then the a few hundred lines of code.
What I really want to know is;
Are there some real differences between the two version that might cause a program to run different?
Is it possible to just simply update to 3.3 and clean it up by just changing the over things like print to print() or urlib2 to the update urlib?
It is quite easy to write new code that works both python 2.6+ and 3.3+. Use the following at the beginning of each file
from __future__ import division, absolute_import \
unicode_literals, print_function
And then know the differences; you can use the six to ease the porting. However be warned that many needed modules might be written for 2.x only (I suspect more so in the field of bioinformatics than in general programming) and it might not only be your code that needs porting. I'd expect you to still need the 2.x for some time. I'd advice against using the 2to3, to me the right way to proceed is to write code that works on both python 2.x and 3.x out of box - it eases the development and testing.
As for the old code, be warned that the str/unicode confusion will hit you hard many times - some python 2 str should be bytes, and some should be python 3 str.
I don't know if SO is the best place to ask this question, but this link here lists every difference between Python 2.x and 3.x: http://docs.python.org/3.0/whatsnew/3.0.html
After reading it, you can easily tell what needs to be done to your 2.x programs to bring them into 3.x.
As an aside: are you familiar with 2to3?
The list of things that can 'go wrong' is basically too large for this Q+A format. Here is what the docs have to say about porting code. The most vital point is to have well-written tests, but in academia I realize that's not always reality. In lieu of that, see the 'gotchas' section for the most common ones that automation will not/can not pick up.
The two that I see most in academic code are reliance on integer division and opening files in non-binary mode. Without knowing specifics, I'd say to watch out for those.