I have Python2.7 installed on my computer. Is there a way to see if the .py code I have will compile in Python3 short of installing Python3?
You can use this program: https://docs.python.org/2/library/2to3.html
It will convert your code form 2 to 3, or give you information about what needs to be changed.
Without knowing anything about your code or operating system, it's hard to say what would be best. If static analysis is the way you want to go, I would suggest taking a look at this to see if any differences jump out at you:
https://docs.python.org/3/whatsnew/3.0.html#common-stumbling-blocks
By the way, Python 2 and 3 can be installed simultaneously on the same machine without too much effort if you change your mind.
If you're running Linux: Running both python 2.6 and 3.1 on the same machine
If you're running Windows: How to install both Python 2.x and Python 3.x in Windows 7
Related
I just need to update code to python 3 since python 2.7 will soon stop being supported. Want to know if I can install Python 3 without screwing up my current 2.7 code?
Yes, you can have more than one version of python on your machine and you can even use any one of them whenever you need it. (In case you need Python2 for some old projects)
In order to that, first you need to have both python version installed and added to PATH variable, then you can go to the root folder of your python2.7 and there you will see a python.exe file which is used as the interpreter, you can just change that file's name to python2 or something and you now you can compile by using python2 somefile.py
You can install python3, and change the interpreter in VS Code to be whatever version that you want, so 2.7 or 3.x
Yes, you can. Python 2 and Python 3 are very similar, and you can delete python 2 and install python 3. Then reformat your code a little.
I would like to upgrade my Python version from 2.6.6 to the newest version of 3.6.5 on a server. However, there is a program that has been running for multiple days and will be running for a week or more.
Will my program continue to run until it finishes if I upgrade my Python version?
P.S.: I ran my Python program with the screen command so I wouldn't have to stop it to be able to upgrade my Python version.
Yes, your Python 2 script should continue to run while you install/upgrade Python 3, since Python 2 and 3 are different programs.
However, the installation will be be platform specific and there might be common dependencies, so I would test this on a different machine (e.g. local virtual machine) first.
Several aspects are to be considered here:
In general, a Python program that is running does not access the installed binaries of the interpreter anymore. Also all the modules already loaded will not be read again from disk during the execution time of this program. (In this aspect it differs from e. g. a Bash script which reads its script source while executing.) So you probably are safe in even removing the complete Python installation; of course that's not what you plan on and I wouldn't recommend it for other reasons, but even that should not influence your running Python program. If, however, your running Python program tries to import a module for the first time after the removal or upgrade of your Python installation, this might fail due to incompatibilities between the versions. Most programs do their imports only at the beginning of their runtime, though.
Python 2 and 3 are different languages. Scripts for the one need to be at least adjusted to run with the other. Adjustments aren't too hard to do, though. Most distributions have both installed side-by-side. Most of the time, Python2 is still standard (and accessed by typing python). python2 and python3 are then to make it explicit. This means that you probably should not remove Python 2 from your system, even if you plan on installing Python 3. There probably are scripts relying on the installation of Python 2.
There's a lot going on here that you've not explained/described, so it's hard to give you a definitive answer (such as the operating system you're using). This is also not exactly a programming question, so you might find that the question gets voted to close. That said...
It possible to run multiple versions of Python side by side. Because 2.x and 3.x are very different, it might be much better to have both versions installed. See this answer for some details on doing that:
Official multiple Python versions on the same machine?
It's likely that your code will need some modifications to run on Python 3, so you're going to have to redeploy a new version of your code at some point anyway.
Note: Running windows7X64
I want to use some audio functions I have seen allot for python 2.7 like snack and such, however I'm using python 3.3. I have come across pygame.py that has some audio functions however pygame doesn't support 64bit arch yet.
So can it be done? if not do we know of any python audio integration modules that can get the job done on python 3 with a 64bit arch
Yes I can just install python 3 32bit but that seems counterproductive and unnecessarily complicated.
Thanks
Ben
You'll have to install 32-bit Python to run 32-bit extension modules. In my experience, two Python installations can live side-by-side quite nicely on Windows, as long as you make sure your environment (PYTHONPATH esp.) is set properly.
Have you tried this?
$ defaults write com.apple.versioner.python Prefer-32-Bit -bool yes
Edit: For the sake of sharing information, this will work (at least from my experience) on a Mac; however, it will not work on a Windows.
I was trying to install shogun on Windows:
http://www.shogun-toolbox.org/doc/installation.html
but evidently it requires python 2.5 to work. I tried with python 3 and it didn't work. But then python 2.5 no longer exists.
Does anybody know how to get it working with python without using python 2.5?
You won't get very far trying with Python 3 (which is not fully compatible with Python 2.x).
Furthermore, the installation instructions say:
"SHOGUN requires the standard linux
utils like bash, grep, test, sed, cut,
ldd, uname gcc g++ cat python"
sounds like you are out of luck on windows, unless you resort to Cygwin.
There are currently two Python languages out there
the original one, which is still being updated (currently at 2.7.2)
the overhauled Python 3, which is breaking compatibility (currently at 3.1.4)
Many libraries have not switched to Python 3 yet, and might not for some time, so you're better off getting 2.6 or 2.7.
For Windows or Mac, I can recommend the Enthought distribution (free for academic use), which contains loads of goodies, including scipy, which you'll very probably need -- and installs hassle-free!
I'm currently toying with python at home and I'm planning to switch to python 3.1. The fact is that I have some scripts that use python 2.6 and I can't convert them since they use some modules that aren't available for python 3.1 atm. So I'm considering installing python 3.1 along with my python 2.6. I only found people on the internet that achieve that by compiling python from the source and use make altinstall instead of the classic make install. Anyway, I think compiling from the source is a bit complicated. I thought running two different versions of a program is easy on Linux (I run fedora 11 for the record). Any hint?
Thanks for reading.
On my Linux system (Ubuntu Jaunty), I have Python 2.5, 2.6 and 3.0 installed, just by installing the binary (deb) packages 'python2.5', 'python2.6' and 'python3.0' using apt-get. Perhaps Fedora packages them and names them as RPMs in a similar way.
I can run the one I need from the command line just by typing e.g. python2.6. So I can also specify the one I want at the top of my script by putting e.g.:
#!/usr/bin/python2.6
Download the python version you want to have as an alternative, untar it, and when you configure it, use --prefix=/my/alt/dir
Cheers
Nik
You're not supposed to need to run them together.
2.6 already has all of the 3.0 features. You can enable those features with from __future__ import statements.
It's much simpler run 2.6 (with some from __future__ import) until everything you need is in 3.x, then switch.
Why do you need to use make install at all? After having done make to compile python 3.x, just move the python folder somewhere, and create a symlink to the python executable in your ~/bin directory. Add that directory to your path if it isn't already, and you'll have a working python development version ready to be used. As long as the symlink itself is not named python (I've named mine py), you'll never experience any clashes.
An added benefit is that if you want to change to a new release of python 3.x, for example if you're following the beta releases, you simply download, compile and replace the folder with the new one.
It's slightly messy, but the messiness is confined to one directory, and I find it much more convenient than thinking about altinstalls and the like.