Question

I have a new MacBook Pro running OS X 10.6.6 / Snow Leopard -- which ships with Python 2.6, although I have installed 2.7.1

Unfortunately, this doesn't seem to see the Twisted install in the 2.6/Extras/lib/python/twisted directory, as I find I'm unable to import modules that I can see are present in that directory.

"which python" returns "/Library/Frameworks/Python.framework/Versions/2.7/bin/python"

and running python returns the same: "Python 2.7.1 (r271:86882M, Nov 30 2010, 10:35:34)"

I have added the twisted directory (absolute) to sys.path, and I have added it to .bash_profile, which now consists of the following:

PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}" PATH=$PATH:/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/twisted export PATH

Any ideas how I can get 2.7.1 to see the Twisted install? Or am I trying to do something that just can't be done?

thanks.

Was it helpful?

Solution

You'll need to install Twisted into your Python 2.7 installation somehow. The "2.6" in that path should be a hint that you shouldn't be trying to tell Python 2.7 about it. Among other things:

  • Extension modules are not compatible between python versions. You may get a segfault if you try to use them.
  • Bytecode formats are not compatible between python versions. Python will fall back to parsing '.py' files, which is slower.
  • If you're using an operating system that ships with Python 2.6, there is a good chance that the version of Twisted included is not compatible with Python 2.7, since Python 2.7 may not have been out yet when it was released.

OTHER TIPS

You'll have to install twisted using python 2.7.

Also, python doesn't look up what's in the PATH variable for imports, it looks in PYTHONPATH. But just putting your python 2.6 folder in your pythonpath isn't a very good solution.

Create an environment using virtualenv.

Install Twisted in your newly created environment using pip.

You need to set up an environment for your new Python 2.7 or use the OS installed 2.6.

OS X ships with NumPy for example, but your new Python 2.7 will not 'see' it.

The best solution (IMHO) is this:

o Don't change the OS default Python AT ALL!

o Install Python 2.7, 3.0 as you wish with the system Python first in the path

o Use virtualenv to set up a personal Python environment -- a sandbox. Install twisted into that.

o Install libraries into the environment you are going to use for the job. Might mean duplicates.

o Use your shebang to execute the proper Python

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top