What is the best way to setup Django on os X 10.7

2019-04-12 21:50发布

问题:

I am setting up Python and Django on os X 10.7 from a virgin install and Xcode 4.3.

I tried using the default install of Python:
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/

I normally use a Python based package manager called easy_install. Easy_install seems to not be able to find the compiler.

EDIT: When I tried to install MySQL-python I got this error:

$ sudo easy_install MySQL-python 
Password:
Searching for MySQL-python
Reading http://pypi.python.org/simple/MySQL-python/
Reading http://sourceforge.net/projects/mysql-python/
Reading http://sourceforge.net/projects/mysql-python
Best match: MySQL-python 1.2.3
Downloading http://download.sourceforge.net/sourceforge/mysql-python/MySQL-python-1.2.3.tar.gz
Processing MySQL-python-1.2.3.tar.gz
Running MySQL-python-1.2.3/setup.py -q bdist_egg --dist-dir /tmp/easy_install-P9H9WX/MySQL-python-1.2.3/egg-dist-tmp-rRTfZL
warning: no files found matching 'MANIFEST'
warning: no files found matching 'ChangeLog'
warning: no files found matching 'GPL'
unable to execute llvm-gcc-4.2: No such file or directory
error: Setup script exited with error: command 'llvm-gcc-4.2' failed with exit status 1

error: Setup script exited with error: command 'llvm-gcc-4.2' failed with exit status 1
Apparently, the system attempts to use the same compiler used to compile the installed Python framework. For some reason Apple didn't include llvm-gcc-4.2.

Xcode 4.1 used GCC, but with Xcode 4.3 that seems to have changed.
From what I can gather, Apple wants to use Clang as the compiler vs GCC. So I added to .bash_profile:

cc=clang

I decided I would just recompile Python with clang but first, I needed to install readline.
Fail:

Wed Feb 22 16:04:59 ~/Downloads/readline-6.2 
$ ./configure
checking build system type... i386-apple-darwin11.3.0
checking host system type... i386-apple-darwin11.3.0

Beginning configuration for readline-6.2 for i386-apple-darwin11.3.0

checking whether make sets $(MAKE)... no
checking for gcc... no
checking for cc... no
checking for cl.exe... no
configure: error: in `/Users/Bryan/Downloads/readline-6.2':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details.

What the easiest way to install Django on Lion 10.7?

回答1:

Did you install the command-line tools with Xcode 4.3? They are not installed by default. You can install them by going to the Downloads pane in Xcode 4.3's preferences.



回答2:

Making it way too hard:

First, make sure you install Xcode (available for free in the Mac App Store). It includes all the build tools that might be necessary to compile certain Python packages.

To get easy_install just download setuptools and follow the instructions for installing on Mac OS X at that link.

Once that's done, you can easy_install virtualenv to get a nice segregated environment to work in.



回答3:

For the MySQL issue you have to edit the site.cfgfile:

mysql_config = /usr/local/mysql/bin/mysql_config

And then:

$ python setup.py build
$ sudo python setup.py install


回答4:

Try updating XCode and reinstall all global site-packages. You may also want to try pip instead of easy_install.

You can also try to compile with

export ARCHFLAGS='-arch i386 -arch x86_64'

This solved many of my problems in the past when upgrading OSX versions.