I am trying to uninstall Python 3.2 and go back to 2.7, I do not have much experience with Python, and as I am learning now, it is becoming increasingly difficult to manage all of the work arounds needed to work with the newest version, and I require 2.7 for a college course.
I tried using the Windows 7 add/remove programs to uninstall Python 3.2 and 3.1, and then I downloaded and installed the 64 bit Python 2.7, but I was unable to open any of my already existing .py files with the executable in the Python27 folder.
When I click to open any .py file, I don't see any error messages but Windows asks what program to open the file with, and if I choose python.exe or pythonw.exe in C:\Python 27 I get a console Window appearing briefly and then closing. The "edit with IDLE" option in the context menu is gone, and if I try to edit with IdleX, I get another "what application to open with" window.
Instead of removing python 3.2, you can use both of python 2 and 3 in the same time. You just need to specify which version you want to use.
When in CMD, you can see the available versions installed on your windows. If it doesn't appear there, you need to install it.
py -0 # Prints out the versions you can use.
You can specify which python version you want to use.
For example in Windows 10, I use the code below for python 3.
py -3 fileName.py # runs using python 3
For python 2, you can use the code below after installing it.
py -2 fileName.py # Runs using python 2
Here is more information about installing more versions of Python in the same time.
How to install both Python 2.x and Python 3.x in Windows 7
Python 3.x is not backward compatible with Python 2.x, which was the purpose of the release. To clean up Python2.x without worrying about backward compatibility.
You can have as many python installations as you want on your computer, as they do not interact with each other. The python installations have it's own folder, with it's own idle, modules, launcher, ect.
You could install PyCharm or another Python IDE. It allows you to change which version of python you use to interpret your code. This will also identify syntax errors as you are writing and will notify you of them - in case you have code that works in 3.x but not 2.x.
Ecker00 is right, installing 2.7 in a separate directory gives you access to 2.7 while still having 3.x on your computer. You will have to re-install libraries with the Python27 folder's pip in order to use them in 2.7 though.
You can also change your python version using anaconda:
conda install python=3.5.0
or maybe
conda install python=2.7.8
or whatever you want.
Use the following steps to get it fixed.
//Check current Python pointer
ls -l python
//Check available Python versions
ls -l python*
//Unlink current python version
sudo unlink python
//Select required python version and lin to python command
sudo ln -s /usr/bin/python2.7 python
//Confirm change in pointer
ls -l python
Related
I have a specific problem with python. I have on my ubuntu two versions python3.4 and python3.6(from anaconda). I want use just anaconda pythoncurrent version
But when i run script i have some problems with another python version
another version
How i can safe delete useless python 3.4.6?
sudo apt-get remove python3.4
anaconda should have set python3 as default python3.6 version
You should probably not delete Python3 from your system, even if you have Anaconda installed, since there might be system software that:
was not tested with subsequent versions of Python;
might struggle finding Python from Anaconda.
What you should do instead is configure your IDE / environment to run Python script with Anaconda, e.g. by setting your PATH variable to point to your anaconda/bin directory or similar.
If you are using PyCharm, as it seems from the screenshot, you could set up your project to run the Anaconda Python without modifying your other command-line settings.
I installed python3, I can open idle and it says it is running python3.0.1, but when I enter python3 in the terminal (on OSX) I get an error saying 'command not found'. Entering python gets me the 2.x version that came on the computer. Any advice on how I can access python3 from the terminal?
Thanks
First, don't use Python 3.0.1. It has many problems and was officially retired upon the release of Python 3.1 (currently 3.1.2). You can find the python.org Mac OS X installer for 3.1.2 here. Once it is installed, then you need to ensure that the bin directory from the 3.1.2 framework (/Library/Frameworks/Python.framework/Versions/3.1/bin) is on your shell search path. You can manually modify an appropriate shell startup file, like .bash_profile. Or just double-click the Update Shell Profile.command found in /Applications/Python 3.1. In either case, you will need to open a new terminal window or re-login. Another approach is to install Python 3.1 from MacPorts or another distributor. Also, alpha releases of Python 3.2 are now available from python.org and elsewhere.
I bought my mac about a year ago and somehow changed my python symlink so that when I run python some_file.py, python 3.4 is used to run the file instead of python 2.7. I now need to change it back, but I can't figure out what I did to change it in the first place! When I run:
import os
os.path.realpath("/usr/local/bin/python")
in the python terminal, the output is:
'/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7'
Does this not mean that my python symlink is pointing to my python 2.7 version, and not my 3.4 version? If not, how do I find out which file is run when I use the python symlink?
You probably installed that specific Python version using the official Python installer for OS X; see the Using Python on a Macintosh documentation. The installer creates the /usr/local/bin symlink for you.
If you also, at some point, had 3.4 installed then that installation is still there too. Check for a /usr/local/bin/python3 command; it'll link to the existing Python 3 binary. Use that instead to run Python 3 code.
If you do have a /Library/Frameworks/Python.framework/Versions/3.4/bin/python3.4 command, you could re-create the /usr/local/bin/python symlink to point there instead, but I'd personally only use the python3 name for Python 3 scripts.
Last, you could also have used the homebrew tool to install Python; it can manage symlinks for you. However, homebrew installs Python binaries into the /usr/local/Cellar tree structure instead.
I usually develop with python 2.7, but would like to start creating some tools in python 3.x. What is the easiest way to have both running side-by-side, while keeping some semblance of control over what libraries I have installed where...
If I use pyenv to switch between versions, will it propagate to a generic shebang line? Something like
#!/usr/bin/env python
or even better, can I specify which python in the shebang?
#!/usr/bin/env python3
I am anticipating a lot of "Use virtualenv" replies. Is this really the only way to do it? I feel like I would like to have the "base" python on my system with whatever libraries I have installed so that I can change between the two environments by typing something simple like pyenv global 3.2.3
I am using OSX, Mountain Lion at the moment.
Trying to explain it a little better, I have two alternative questions:
If I use something like virtualenv, will I lose the ability to run python2 and python3 scripts alternately, without changing the environment (i.e., just via shebang)?
In contrast, if I use two independent version installations, how can I control/know what will be installed by pip or easy_install for example.
UPDATE: Currently using python3 in the shebang line, and using pip3 to install packages to python3... Seems to work fine.
You have a few possible methods varing slightly with os:
Invoke python 2 as python and 3 as python3
Extensions of .py and .py3
Virtualenv
A script or batch file to switch envionments. I use this to test my code against different versions of python 2. Note that you can have different envionments set in separate command sessions at the same time.
Testing in virtual machines.
Use an IDE that allows you to specify python versions on a project or debug session basis I use WingIDE but it is not the only one to allow this.
It may well pay you to look at six and working in python 3 than back converting to 2.7 for older installations.
See also here for both how to install python 3 libraries under python 3 with virtualevn and without, (modify version numbers as appropriate).
Update - the windows python launcher
Additionally, on Windows, when you install Python 3 you have the option to install the python launchers, (py.exe & pyw.exe), to the Windows directory. The py launcher has the following behaviour:
py Launch the python 3 interactive latest installed prompt (64 bit preferred)
py -2 Launch the python 2 interactive latest installed prompt (64 bit preferred)
py somescript *Check the shebang in the named file and launch it with python 2 (default if no shebang) or 3 as appropriate.
py -2 somescript launch the script under latest python 2 (64 bit preferred)
py -3 somescript launch the script under python 3 (64 bit preferred)
py -3.5 somescript launch the script under python 3.5 (64 bit preferred)
py -3.5-32 somescript launch the script under python 3.5 (32 bit)
the pyw launcher has the same behaviour without the console, like pythonw.
Associating .py files with py.exe and .pyw files with pyw.exe will result in the shebang line being honoured.
Additionally using py -3.5-32 -m pip install some_package will specifically install some_package to the 32 bit python 3.5 installation, etc.
Disclaimer: I am the author of some upcoming enhancements to the python launcher to extend the above options slightly.
I installed python3, I can open idle and it says it is running python3.0.1, but when I enter python3 in the terminal (on OSX) I get an error saying 'command not found'. Entering python gets me the 2.x version that came on the computer. Any advice on how I can access python3 from the terminal?
Thanks
First, don't use Python 3.0.1. It has many problems and was officially retired upon the release of Python 3.1 (currently 3.1.2). You can find the python.org Mac OS X installer for 3.1.2 here. Once it is installed, then you need to ensure that the bin directory from the 3.1.2 framework (/Library/Frameworks/Python.framework/Versions/3.1/bin) is on your shell search path. You can manually modify an appropriate shell startup file, like .bash_profile. Or just double-click the Update Shell Profile.command found in /Applications/Python 3.1. In either case, you will need to open a new terminal window or re-login. Another approach is to install Python 3.1 from MacPorts or another distributor. Also, alpha releases of Python 3.2 are now available from python.org and elsewhere.