不能用macos的python安装django

时间:2013-10-01 11:45:31

标签: python django macos

我无法在我的mac上安装django:/

下面: brew卸载python,brew安装python,pip安装django,python,导入django

nma-2:~ nikolaialeksandrenko$ brew uninstall python
Error: No such keg: /usr/local/Cellar/python
nma-2:~ nikolaialeksandrenko$ brew install python
Warning: You have not agreed to the Xcode license.
Builds will fail! Agree to the license by opening Xcode.app or running:
    xcodebuild -license
==> Downloading http://www.python.org/ftp/python/2.7.4/Python-2.7.4.tar.bz2
Already downloaded: /Library/Caches/Homebrew/python-2.7.4.tar.bz2
==> ./configure --prefix=/usr/local/Cellar/python/2.7.4 --enable-ipv6 --datarootdir=/usr/local/Cellar/python/2.7.4/share --datadir=/usr/local/Cellar
==> make
==> make install PYTHONAPPSDIR=/usr/local/Cellar/python/2.7.4
==> make frameworkinstallextras PYTHONAPPSDIR=/usr/local/Cellar/python/2.7.4/share/python
==> Downloading https://pypi.python.org/packages/source/d/distribute/distribute-0.6.38.tar.gz
Already downloaded: /Library/Caches/Homebrew/distribute-0.6.38.tar.gz
==> /usr/local/Cellar/python/2.7.4/bin/python -s setup.py --no-user-cfg install --force --verbose --install-lib=/usr/local/Cellar/python/2.7.4/Frame
==> Downloading https://pypi.python.org/packages/source/p/pip/pip-1.3.1.tar.gz
Already downloaded: /Library/Caches/Homebrew/pip-1.3.1.tar.gz
==> /usr/local/Cellar/python/2.7.4/bin/python -s setup.py --no-user-cfg install --force --verbose --install-lib=/usr/local/Cellar/python/2.7.4/Frame
==> Caveats
Homebrew's Python framework
  /usr/local/Cellar/python/2.7.4/Frameworks/Python.framework

Python demo
  /usr/local/share/python/Extras

Distribute and Pip have been installed. To update them
  pip install --upgrade distribute
  pip install --upgrade pip

To symlink "Idle" and the "Python Launcher" to ~/Applications
  `brew linkapps`

You can install Python packages with (the outdated easy_install or)
  `pip install <your_favorite_package>`

They will install into the site-package directory
  /usr/local/lib/python2.7/site-packages

Executable python scripts will be put in:
  /usr/local/share/python
so you may want to put "/usr/local/share/python" in your PATH, too.

See: https://github.com/mxcl/homebrew/wiki/Homebrew-and-Python
==> Summary
  /usr/local/Cellar/python/2.7.4: 5195 files, 80M, built in 102 seconds
nma-2:~ nikolaialeksandrenko$ brew link python
Warning: Already linked: /usr/local/Cellar/python/2.7.4
To relink: brew unlink python && brew link python
nma-2:~ nikolaialeksandrenko$ pip install Django
Requirement already satisfied (use --upgrade to upgrade): Django in /usr/local/lib/python2.7/site-packages
Cleaning up...
nma-2:~ nikolaialeksandrenko$ python
Python 2.7.2 (default, Oct 11 2012, 20:14:37) 
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named django
>>> import Django
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named Django
>>> 

2 个答案:

答案 0 :(得分:0)

您可以下载Django here。可以在here找到在macos上安装django的默认步骤。

tar xzvf Django-1.5.4.tar.gz
cd Django-1.5.4
sudo python setup.py install

答案 1 :(得分:0)

链接不起作用。你链接到(或试图链接到)的那个是python 2.7.4,但是当你运行python时它清楚地显示了“Python 2.7.2”。

尝试在python中运行:

import site; site.getsitepackages()

它应该显示与您正在运行的python版本关联的site-packages目录的位置。另一件事就是运行which python来查看您实际调用的可执行文件。

如果结果不正确(将其与django安装目录进行比较),则只需手动将其他python目录添加到路径中即可。将其放在主目录中的.profile文件中:

PATH="/usr/local/Cellar/python/2.7.4/bin/:$PATH"

这确保了新安装的Homebrew特定python是在没有任何路径的情况下运行它时执行的python - 这应该有希望与pip正在使用的可执行文件匹配。