[英]How to get MySQLdb running on Mountain Lion with Python 2.7 and MySQL 5.6.11 x86_64
[英]Running Python locally on Mountain Lion
我將本地環境設置為運行MySQL和PHP。 我開始涉足其他語言,並試圖使Java,Python和Ruby在本地Web服務器上運行。 所有語言均已正確安裝,但是apache無法識別它們或給我權限問題。
我開始使用Python,經過許多問題使Apache能夠識別.mod時,我轉到該頁面時遇到403錯誤。
我不確定下一步如何使它正常工作。
403禁止
禁止的
您無權訪問此服務器上的/。
<VirtualHost *:80>
DocumentRoot "/Library/Webserver/Documents/python-mn"
ServerName python.local
ServerAlias www.python.local
WSGIScriptAlias / /Library/WebServer/Documents/python-mn/wsgi.py
<Directory /Library/Webserver/Documents/python-mn>
#Options Indexes FollowSymLinks MultiViews
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
檢查Apache錯誤日志:
tail -f /var/log/apache2/error_log
[Fri Sep 06 15:30:51 2013] [error] [client 127.0.0.1] mod_hfs_apple: Mis-cased URI or unacceptable Unicode in URI: /Library/WebServer/Documents/python-mn/wsgi.py, wants: /Library/Webserver/Documents/python-mn/
Ping當地環境:
ping python.local
PING python.local (127.0.0.1): 56 data bytes
64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.041 ms
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.054 ms
64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.153 ms
64 bytes from 127.0.0.1: icmp_seq=3 ttl=64 time=0.159 ms
64 bytes from 127.0.0.1: icmp_seq=4 ttl=64 time=0.130 ms
64 bytes from 127.0.0.1: icmp_seq=5 ttl=64 time=0.134 ms
64 bytes from 127.0.0.1: icmp_seq=6 ttl=64 time=0.054 ms
64 bytes from 127.0.0.1: icmp_seq=7 ttl=64 time=0.073 ms
64 bytes from 127.0.0.1: icmp_seq=8 ttl=64 time=0.135 ms
64 bytes from 127.0.0.1: icmp_seq=9 ttl=64 time=0.111 ms
64 bytes from 127.0.0.1: icmp_seq=10 ttl=64 time=0.130 ms
64 bytes from 127.0.0.1: icmp_seq=11 ttl=64 time=0.131 ms
64 bytes from 127.0.0.1: icmp_seq=12 ttl=64 time=0.133 ms
64 bytes from 127.0.0.1: icmp_seq=13 ttl=64 time=0.136 ms
64 bytes from 127.0.0.1: icmp_seq=14 ttl=64 time=0.132 ms
64 bytes from 127.0.0.1: icmp_seq=15 ttl=64 time=0.140 ms
64 bytes from 127.0.0.1: icmp_seq=16 ttl=64 time=0.136 ms
64 bytes from 127.0.0.1: icmp_seq=17 ttl=64 time=0.105 ms
64 bytes from 127.0.0.1: icmp_seq=18 ttl=64 time=0.052 ms
64 bytes from 127.0.0.1: icmp_seq=19 ttl=64 time=0.074 ms
MacBook Pro(Retina,15英寸,2013年初),OS X Mountain Lion(10.8.4)
- -編輯 - -
wsgi.py文件:
import bottle
import os
def application(environ, start_response):
data = "Hello World!"
start_response("200 OK", [
("Content-Type", "text/plain"),
("Content-Length", str(len(data)))
])
return iter([data])
---編輯9/9/13 11:46 am-
現在出現新錯誤:
內部服務器錯誤
服務器遇到內部錯誤或配置錯誤,無法完成您的請求。
請與服務器管理員(you@example.com)聯系,並通知他們錯誤發生的時間以及您可能做的任何可能導致錯誤的事情。
服務器錯誤日志中可能會提供有關此錯誤的更多信息。
apache錯誤日志
[Mon Sep 09 11:43:08 2013] [notice] caught SIGTERM, shutting down
[Mon Sep 09 11:43:08 2013] [warn] Init: Session Cache is not configured [hint: SSLSessionCache]
httpd: Could not reliably determine the server's fully qualified domain name, using Micheles-MacBook.local for ServerName
[Mon Sep 09 11:43:08 2013] [warn] mod_wsgi: Compiled for Python/2.6.1.
[Mon Sep 09 11:43:08 2013] [warn] mod_wsgi: Runtime using Python/2.6.7.
[Mon Sep 09 11:43:08 2013] [notice] Digest: generating secret for digest authentication ...
[Mon Sep 09 11:43:08 2013] [notice] Digest: done
[Mon Sep 09 11:43:08 2013] [notice] Apache/2.2.22 (Unix) mod_wsgi/3.3 Python/2.6.7 PHP/5.5.3 mod_ssl/2.2.22 OpenSSL/0.9.8x DAV/2 configured -- resuming normal operations
[Mon Sep 09 11:43:18 2013] [error] [client 127.0.0.1] mod_wsgi (pid=7888): Target WSGI script '/Library/WebServer/Documents/python-mn/wsgi.py' cannot be loaded as Python module.
[Mon Sep 09 11:43:18 2013] [error] [client 127.0.0.1] mod_wsgi (pid=7888): Exception occurred processing WSGI script '/Library/WebServer/Documents/python-mn/wsgi.py'.
[Mon Sep 09 11:43:18 2013] [error] [client 127.0.0.1] Traceback (most recent call last):
[Mon Sep 09 11:43:18 2013] [error] [client 127.0.0.1] File "/Library/WebServer/Documents/python-mn/wsgi.py", line 1, in <module>
[Mon Sep 09 11:43:18 2013] [error] [client 127.0.0.1] import bottle
[Mon Sep 09 11:43:18 2013] [error] [client 127.0.0.1] ImportError: No module named bottle
[Mon Sep 09 11:43:18 2013] [error] [client 127.0.0.1] mod_wsgi (pid=7888): Target WSGI script '/Library/WebServer/Documents/python-mn/wsgi.py' cannot be loaded as Python module.
[Mon Sep 09 11:43:18 2013] [error] [client 127.0.0.1] mod_wsgi (pid=7888): Exception occurred processing WSGI script '/Library/WebServer/Documents/python-mn/wsgi.py'.
[Mon Sep 09 11:43:18 2013] [error] [client 127.0.0.1] Traceback (most recent call last):
[Mon Sep 09 11:43:18 2013] [error] [client 127.0.0.1] File "/Library/WebServer/Documents/python-mn/wsgi.py", line 1, in <module>
[Mon Sep 09 11:43:18 2013] [error] [client 127.0.0.1] import bottle
[Mon Sep 09 11:43:18 2013] [error] [client 127.0.0.1] ImportError: No module named bottle
這是我期望得到的,其文件結構和代碼與我的AppFog安裝相同: http ://python-mn.aws.af.cm/
---編輯9/9/13 1:03 pm ---
我執行了一個終端命令來安裝bottle ...不確定如何確保wsgi.py或vhosts知道將其放置在哪里。 顯然,AppFog服務器具有本機功能,這就是為什么我不需要任何其他東西即可使其運行。
easy_install -U bottle
Searching for bottle
Reading https://pypi.python.org/simple/bottle/
Best match: bottle 0.11.6
Downloading https://pypi.python.org/packages/source/b/bottle/bottle- 0.11.6.tar.gz#md5=0bafdc4e13ea2b1a3bddf36b5af108c4
Processing bottle-0.11.6.tar.gz
Writing /var/folders/hc/dtnjvkvn1dd931bkkxty_05w0000gn/T/easy_install-QS4GZM/bottle-0.11.6/setup.cfg
Running bottle-0.11.6/setup.py -q bdist_egg --dist-dir /var/folders/hc/dtnjvkvn1dd931bkkxty_05w0000gn/T/easy_install-QS4GZM/bottle-0.11.6/egg-dist- tmp-pQrFpa
zip_safe flag not set; analyzing archive contents...
bottle: module references __file__
bottle: module references __path__
Adding bottle 0.11.6 to easy-install.pth file
Installing bottle.py script to /usr/local/bin
Installed /usr/local/lib/python2.7/site-packages/bottle-0.11.6-py2.7.egg
Processing dependencies for bottle
Finished processing dependencies for bottle
嘗試此操作(或可能將WebServer切換到Webserver(我所做的更改是使所有路徑名均為WebServer;您有一些Webserver(小寫S)和一些WebServer
<VirtualHost *:80>
DocumentRoot "/Library/WebServer/Documents/python-mn"
ServerName python.local
ServerAlias www.python.local
WSGIScriptAlias / /Library/WebServer/Documents/python-mn/wsgi.py
<Directory /Library/WebServer/Documents/python-mn>
#Options Indexes FollowSymLinks MultiViews
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
根據Apple的mod_hfs_guide ,您的錯誤消息是由於Apple試圖保護您免受使用HFS區分大小寫的人訪問的,而該訪問應使用該名稱的有趣的大小寫形式來加以保護。
我看到您知道了,但供將來參考...
bottle
似乎不是您的Python系統路徑的一部分。 要將其添加到路徑中,您有兩個選擇:
通過在此處下載bottle
將其手動添加到系統Python路徑中:
https://pypi.python.org/pypi/bottle/0.11.6
下載后,運行:
tar xvf bottle-0.11.6.tar.gz cd bottle-0.11.6/ sudo python setup.py install
使用包管理器為您拉包。 您可以從此處安裝pip(也可以使用easy_install,brew或macports):
https://pypi.python.org/pypi/pip/1.4.1
然后,一旦安裝(類似於以上內容),請運行:
pip install bottle
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.