Beautiful_oup已安装但在dev_appserver运行时无法识别

时间:2011-08-20 20:22:48

标签: python django beautifulsoup

更新

By adding BeautifulSoup.py to my app source, this error was gone :)  

谢谢@Ned Deily,这花了很长时间,但收获颇丰。

忽略此处
我只有一个用BeautifulSoup安装的python 2.5实例,仍然没有运气!,我做错了什么,请帮忙

bash-3.2$ ls -ltr /Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages
total 1096
-rw-r--r--   1 Harit  admin   66866 May 28  2006 BeautifulSoup.py
-rw-r--r--   1 Harit  admin   26413 May 28  2006 BeautifulSoupTests.py
-rw-rwxr--   1 root   admin     119 Sep 18  2006 README
drwxr-xr-x  19 Harit  admin     646 Aug 20 23:58 django
-rw-r--r--   1 Harit  admin    1228 Aug 20 23:58 Django-1.3-py2.5.egg-info
-rw-r--r--   1 Harit  admin  333390 Aug 21 00:17 setuptools-0.6c11-py2.5.egg
-rw-r--r--   1 Harit  admin      30 Aug 21 00:17 setuptools.pth
-rw-r--r--   1 Harit  admin     215 Aug 21 00:22 easy-install.pth
-rw-r--r--   1 Harit  admin   33196 Aug 21 00:23 BeautifulSoupTests.pyc
-rw-r--r--   1 Harit  admin   67193 Aug 21 00:23 BeautifulSoup.pyc
-rw-r--r--   1 Harit  admin     970 Aug 21 00:23 BeautifulSoup-3.0.0-py2.5.egg-info
bash-3.2$ 

从此处忽略

我从macport和system中删除了所有版本的python,并重新安装了python 2.7版本

bash-3.2$ python
Python 2.7.2 (v2.7.2:8527427914a2, Jun 11 2011, 15:22:34) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>> from BeautifulSoup import BeautifulSoup
>>>   

并且所有路径也都很好

bash-3.2$ echo $PATH
/Library/Frameworks/Python.framework/Versions/2.7/bin:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin:/usr/X11/bin:/opt/local/bin  

只有一个安装了DjangoBeautifulSoup的python版本

bash-3.2$ cd /Library/Frameworks/Python.framework/Versions/Current/
Headers/   Mac/       Python     Resources/ bin/       include/   lib/       share/     
bash-3.2$ cd /Library/Frameworks/Python.framework/Versions/Current/lib/python2.7/lib
lib-dynload/ lib-tk/      lib2to3/     
bash-3.2$ cd /Library/Frameworks/Python.framework/Versions/Current/lib/python2.7/
Display all 641 possibilities? (y or n)
bash-3.2$ ls /Library/Frameworks/Python.framework/Versions/Current/lib/python2.7/site-packages/
BeautifulSoup-3.2.0-py2.7.egg-info  BeautifulSoupTests.pyc          easy-install.pth
BeautifulSoup.py            Django-1.3-py2.7.egg-info       setuptools-0.6c11-py2.7.egg
BeautifulSoup.pyc           README                  setuptools.pth
BeautifulSoupTests.py           django
bash-3.2$ 

但是当我运行dev_appserver.py project时,它仍然无法导入模块BeautifulSoup

请帮忙

谢谢

从下方忽略
我在我的Mac上安装了BeautifulSoup,我可以执行以下操作:

bash-3.2$ python
Python 2.6.7 (r267:88850, Jul 27 2011, 11:54:59) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from BeautifulSoup import BeautifulSoup
>>>   

但是当我运行我的djando应用程序并尝试运行代码时,它无法说

Error was: No module named BeautifulSoup  

我似乎正在正确使用一切

bash-3.2$ which python
/opt/local/bin/python

lrwxr-xr-x  1 root  admin        9 Aug 16 13:55 python -> python2.6  

bash-3.2$ cd /Library/Python/2.6/site-packages/
BeautifulSoup-3.0.0-py2.6.egg-info                  ipython-0.11-py2.6.egg/
BeautifulSoup.py                                    mercurial/
BeautifulSoup.pyc                                   mercurial-1.8.3_20110502-py2.6.egg-info/
BeautifulSoupTests.py                               nose-1.1.2-py2.6.egg/
BeautifulSoupTests.pyc                              paramiko-1.7.6-py2.6.egg
Django-1.3-py2.6.egg-info                           pip-1.0.2-py2.6.egg/
MySQL_python-1.2.3-py2.6-macosx-10.6-universal.egg  pycrypto-2.3-py2.6-macosx-10.6-universal.egg
README                                              pysqlite-2.6.3-py2.6.egg-info
django/                                             pysqlite2/
easy-install.pth                                    setuptools-0.6c11-py2.6.egg
easy_install                                        setuptools.pth
easy_install-2.6                                    xlrd/
hgext/                                              xlrd-0.6.1-py2.6.egg-info

如何解决此问题
感谢

1 个答案:

答案 0 :(得分:4)

你显然已经安装了第二个更新的Python 2.6实例。有可能您的Django应用程序已安装并从另一个Python 2.6实例运行,可能是系统Python 2.6(/usr/bin/python/usr/bin/python2.6)。键入which python以查看具有BeautifulSoup的Python的路径(也许是/usr/local/bin/python?)。你需要巩固一些事情;要么使用Django在Python中安装BeautifulSoup,要么在带有BeautifulSoup的Python中安装Django。

更新:由于您显然正在运行Google App Engine dev_server,因此很可能它在Python 2.5下运行,而不是在Python 2.6下运行;目前,据我所知,GAE正式支持2.5。注意Apple随OS X 10.6发布了Python 2.6和2.5。所以你可能需要在Python 2.5中安装Beautiful Soup。尝试:

easy_install-2.5 -U -v beautifulsoup==3.2

目前,您需要指定版本,因为目前有更新的Beautiful Soup 4测试版似乎与Python 2.5不兼容。

更新:您似乎还安装了多个版本的Python 2.5。您展示的路径是第三方Python,而不是Apple提供的Python 2.5。 所以我最后的建议是尝试将easy_install-2.5用于Apple提供的Python 2.5:

/usr/bin/easy_install-2.5 -U -v beautifulsoup==3.2