2

I am using MacOSX 10.6.8 I switched from python version 2.6 to python 2.7 But the modules I have downloaded for python 2.6 like sympy numpy doesn't work for 2.7 Do I need to install these things separately again?

blackmamba
  • 1,952
  • 11
  • 34
  • 59
  • 3
    yes, you do. Different Python versions have different bytecode, so any compiled libraries wouldn't work. Just use `pip` and you'll be all set. – MattDMo Jan 24 '14 at 16:59
  • 1
    @MattDMo The problem is more likely to be the ABI han the bytecode. – Alex Chamberlain Jan 24 '14 at 17:01
  • @MattDMo except that almost *no* package is distributed as `.pyc` exactly for this reason. I'm pretty sure `numpy` etc ship with some C extension (which is causing the problems) and pure python source code. @wannaC: Could you define what "doesn't work" mean? Python raises an `ImportError`? Or what? – Bakuriu Jan 24 '14 at 17:07
  • numpy IS some C extension and a link between python and this. Reinstall or recomile - should be easy. You may find some prebuilt, but should be sure that are for exactly same architecture and py version. – cox Jan 24 '14 at 17:13
  • I was thinking more along the lines of the OP just trying to move the contents of `site-packages` from 2.6 to 2.7. Any `.pyc` files present would mess things up. Additionally, NumPy has a bunch of C extensions that definitely wouldn't work if moved from one version to the other. Pure Python packages should be able to be moved with no problems, but with the changes in 2.7 over 2.6 it's possible that PyPI has different versions of some packages. I was just trying to be simple in my original comment, and convince the OP that reinstalling all packages would be less painful than trying to move them – MattDMo Jan 24 '14 at 17:13
  • @Bakuriu: Yes it raises an import error. – blackmamba Jan 25 '14 at 09:04

1 Answers1

1

As discussed in the comments, there are many issues associated with just moving the contents of your site-packages directory from Python 2.6 to 2.7. If there is any bytecode present (.pyc files) there's a chance they won't work with the new version. The ABI may also have changed. Additionally, modules like NumPy have compiled C extensions that rely on the source/headers of the version of Python being used to generate them, and that can change between minor versions (2.6 and 2.7). In general, you can use packages compiled with 2.7.3 with 2.7.6 (only the micro version has changed), but seeing as there were a large number of changes between 2.6 and 2.7 (2.7 has quite a few features backported from the 3.X line), using 2.6 modules with 2.7 just probably isn't a good idea.

If you have pure Python modules (no C extensions, any .pyc or .pyo files removed) you may be able to use them with 2.7, but it would be just as easy to reinstall them with pip-2.7. Modules with compiled libraries like NumPy will definitely need to be reinstalled. Finally, some modules may have different versions for use with 2.6 vs. 2.7 that take advantage of 2.7's new features, so in that case it'd definitely be worthwhile to reinstall.

Community
  • 1
  • 1
MattDMo
  • 100,794
  • 21
  • 241
  • 231
  • So I just noticed that when I restarted the terminal and checked for python's version it still showed me Python 2.6 So in case I need to switch to python 2.7 I wrote python2.7 in the terminal. In this case how should I make sure those modules like sympy are installed for python2.7 as well? – blackmamba Jan 25 '14 at 09:25