This post has been last edited on april 28, 2014 to reflect changes in the behavior of both Spyder and Conda.
Scroll a bit down if you’re not interested in the story and just want to know how to install Spyder with Anaconda and Python 3.x :)
Today I decided to switch from Python 2.7 to Python 3.x. I had been thinking about this lately, because at some point the scientific community will have to take the patience to migrate to the backwards-incompatible Python 3, right? Or perhaps to Python 4, given the rate this migration seems to be going.
For me, the date is today, after I noticed the very peculiar way Python 2.7 deals with greater than / less than comparisons.
Long story short, I was writing a simple script using max() when I forgot to use len() on a string:
offset = max(len(enzyme), len(spl1), "Start site")
No error was raised right there, but when I tried to use the result as an int, I got a TypeError – the string was the maximum “value” there. That was so weird… having a method deal with strings and numbers together, with some assumption on their ordering? I needed to understand this awkward behavior somehow better.
Well it turned out that in Python 2.x, using max() on two numbers and a string is considered a thing people will do on purpose, and really raises no error. You can even do "string" > 1000000 and it’ll be ok – the string ends up being greater than the number, because -no kidding- Python 2.7 compares two different types by the name of the type – so “str” is bigger than “int” because “s” > “i”. This apparently results from an interest in having a simple way to order a list of different types, so that say, all the ints would be first, then all strings. I thought that this was very very strange and would bring a lot of confusion, and sure enough, one of the changes in Python 3 is that,
“The ordering comparison operators (<, <=, >=, >) raise a TypeError exception when the operands don’t have a meaningful natural ordering.”
Well then, this was somehow the tipping point for me. Python 3 is logic, Python 2 not equally so: I’m going for Python 3.
I’ve been enjoying Continuum’s Anaconda Python for a while now, so I decided to reinstall Anaconda with Python 3.3, and set up Spyder to work with it. This took a little tweaking, so here’s a step-by-step on how I did it on my system (Windows 7, 64-bit).
Installing Anaconda Python 3.3 and Spyder 2.3 on 64-bit Win 7: step-by-step
1) according to this post from Continuum.io, I downloaded miniconda3.
I’m mostly using 64-bit Windows 7 these days, so the right file for my system was Miniconda3-3.0.5-Windows-x86_64.exe. I installed it for all users, choosing not to set it as default Python 3.3 installation, because I have a standard Python3.3 on the system too. But if you don’t have any other Python3, then by all means set it as default, because some automatic installers (i.e. the psutil one) will need to find Python 3 on the registry.
2) I followed the post; opened a cmd and used conda install anaconda. So at this point I had Anaconda Python 3.3.4 ready at C:\Miniconda3. No Spyder though – only the command-line python executable.
4) I extracted the spyder-2.3.0beta4 directory in C:\.
5) Now it’s time to build and install it. Open a cmd session. From the command line use the cd command to go to the Spyder extract folder, i.e. in my case I typed:
Now that you are in the right directory, you need to build and install Spyder, and just to stress it again, to do it correctly you must call python exactly from this folder that contains the Spyder files. Otherwise it won’t work.
What you must do is:
C:\Miniconda3\python.exe setup.py build
(This will create the “build” subfolder and its files); and then:
C:\Miniconda3\python.exe setup.py install
which will install Spyder on Anaconda. Almost done!
Now if you open the Scripts subfolder in your Miniconda folder, you should find there a spyder.bat batch file. You can double-click it to execute Spyder. You can create a link to it and leave the link on your desktop if you like.
You can now work on Spyder’s optional dependencies. To check what you’re missing, open Spyder and go to Help > Optional dependencies. Ideally they should all be “(OK)”, and since in my case several were missing I installed them using conda or pip.
Just a warning: at the time of this writing, if you want to install rope, you should better install it with pip, not conda:
pip install rope_py3k
because (as of today) if you use conda on Python 3, it will download the wrong rope package (apparently) and Spyder will crash on loading.
On the other side, conda was a good way to install matplotlib, pep8, pylint which in my case were not installed together with Anaconda by default. If I remember well I had to use pip to install a few of these the last time (conda was reporting a conflict with Python 3), but now apparently conda managed it ok.
For psutil, since we’re on windows, we get to have an installer, but the downside of it is that it will look for the “official” version of Python 3 in the system registry. If you have set Anaconda Python 3 as your default Python 3 at installation, then you’re good to go. In my case it wasn’t Anaconda, but a regular Python 3.3 installation so I just let the installer complete, then I went to my default Python installation folder, then Lib, site-packages, and I copied the psutil folder plus 3 files: _psutil_mswindows.pyd, _psutil_windows.pyd and psutil-1.2.1-py3.3.egg-info for good measure. (There’s a README.txt there also).
Paste the whole directory, plus the files, in the corrisponding Lib\site-packages subfolder that you will find in the Miniconda3 installation directory. And done!
Enjoy Spyder with Anaconda Python 3.x :)