Feeds:
Posts
Comments

Posts Tagged ‘django.core’

If you have installed mac port, it’s normal to install python and django under macport.

如果你安裝了macport,很自然地,你希望用macport去安裝python及django。

The latest python installed by macport should be 2.7.3, thus command for installation of python and django are:

由於在macport之下最新的python的版本是2.7.3。故此在macport下安裝python及django的指令:

sudo port install python
sudo port install py27-django

If you have installed previous version of python through macport, you should make sure which one is active, you can use the following command to check:

如果你之前曾用過macport安裝舊版本的python,你可以用以下的指令查看那一個版本才是預設的。

port select --list python

The result should be similar to the following:
如果會跟以下的差不多:

Available versions for python:
	none (active)
	python25-apple
	python26-apple
	python27
	python27-apple

If you want to ask macport to select the python 2.7.3 provided by macport as default python interpreter, you should use the following command:

如果你想指定用macport所提供的python 2.7,你需要用到以下的指令:

sudo port select python python27

If you want to see if you have set the active python interpreter correctly, type the following command to check the path of python:

如果你想測試之前能否成功地指定python interpreter,可以用以下的指令查看python的路徑:

which python

If you selected macport’s python, the path should be:
如果你選的是macport所提供的python,應看到以下的結果:

/opt/local/bin/python

Try to repeat the previous steps if you find the path is different.
如果你發現python的路徑不相同,請重覆以上的步驟。

Now, please check your path to django-admin.py:
現在請查看django-admin.py的路徑,

which django-admin.py

In my computer, the result is:
在我的電腦,django-admin的位置是:

/usr/local/bin/django-admin.py

If you execute django-admin.py, you will find out that python cannot find django.core. The problem is caused from the first line of django-admin.py

如果你執行django-admin.py你會發現python找不到django.core。問題源於django-admin.py的第一句。

#!/usr/bin/python
from django.core import management

if __name__ == "__main__":
    management.execute_from_command_line()

The first line tell shell to use the python installed by mac os instead of using the python provided by macport. Thus, we should use the following command to change the first line:
第一句告知shell使用由mac os所提供的python而不是macport 所提供的python。所以我們須用以下的指令更改第一句:

sudo nano /usr/local/bin/django-admin.py

The updated source code should look like:
更改後的django-admin.py應該是:

#!/opt/local/bin/python
from django.core import management

if __name__ == "__main__":
    management.execute_from_command_line()

Then, you can ran django-admin.py properly.
之後,你就可以正常地運行django-admin.py

However, next time if you update django, please repeat the process again.
下次你更新django時,請重覆整個步驟。

Advertisements

Read Full Post »