python - 无法在 virtualenv 中导入 beautifulsoup4

标签 python ubuntu terminal beautifulsoup

我一直在尝试在虚拟环境中安装use beautiful soup。我已经使用 pip 和 easy_install 成功安装了模块,但我似乎无法将它导入解释器。这是我尝试启动它时所做的。任何帮助将不胜感激。

谢谢!

(WebScraper)test@ubuntu:~/code/WebScraper$ easy_install beautifulsoup4
Searching for beautifulsoup4
Reading http://pypi.python.org/simple/beautifulsoup4/  
Reading http://www.crummy.com/software/BeautifulSoup/bs4/
Reading http://www.crummy.com/software/BeautifulSoup/bs4/download/
Best match: beautifulsoup4 4.2.0
Downloading http://pypi.python.org/packages/source/b/beautifulsoup4/beautifulsoup4-    4.2.0.tar.gz#md5=48a3a7ee42d9b5bd046b3b5c86bb2d35
Processing beautifulsoup4-4.2.0.tar.gz
Writing /tmp/easy_install-R6wbsM/beautifulsoup4-4.2.0/setup.cfg
Running beautifulsoup4-4.2.0/setup.py -q bdist_egg --dist-dir /tmp/easy_install-    R6wbsM/beautifulsoup4-4.2.0/egg-dist-tmp-xIc3Vf
zip_safe flag not set; analyzing archive contents...
Adding beautifulsoup4 4.2.0 to easy-install.pth file

Installed /home/test/code/WebScraper/lib/python2.7/site-packages/beautifulsoup4-4.2.0-  py2.7.egg
Processing dependencies for beautifulsoup4
Finished processing dependencies for beautifulsoup4
(WebScraper)test@ubuntu:~/code/WebScraper$ python

Python 2.7.4 (default, Apr 19 2013, 18:28:01) 
[GCC 4.7.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import bs4
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "bs4.py", line 1, in <module>
from bs4 import BeautifulSoup
ImportError: cannot import name BeautifulSoup
>>>>

最佳答案

这对我有用:

dirk@discordia:~/Dokumente/devel/python$ virtualenv blabla --no-site-packages
New python executable in blabla/bin/python
Installing setuptools, pip...done.
dirk@discordia:~/Dokumente/devel/python$ source blabla/bin/activate
(blabla)dirk@discordia:~/Dokumente/devel/python$ cd blabla/
(blabla)dirk@discordia:~/Dokumente/devel/python/blabla$ pip install yolk
Downloading/unpacking yolk
  Downloading yolk-0.4.3.tar.gz (86kB): 86kB downloaded
  Running setup.py (path:/home/dirk/Dokumente/devel/python/blabla/build/yolk/setup.py) egg_info for package yolk

...snip...  

Successfully installed yolk
Cleaning up...

(blabla)dirk@discordia:~/Dokumente/devel/python/blabla$ yolk -l
Python          - 2.7.5+       - active development (/usr/lib/python2.7/lib-dynload)
argparse        - 1.2.1        - active development (/usr/lib/python2.7)
pip 1.5.4 has no metadata
setuptools 2.2 has no metadata
wsgiref         - 0.1.2        - active development (/usr/lib/python2.7)
yolk            - 0.4.3        - active 
(blabla)dirk@discordia:~/Dokumente/devel/python/blabla$ pip install beautifulsoup4
Downloading/unpacking beautifulsoup4
  Downloading beautifulsoup4-4.3.2.tar.gz (143kB): 143kB downloaded
  Running setup.py (path:/home/dirk/Dokumente/devel/python/blabla/build/beautifulsoup4/setup.py) egg_info for package beautifulsoup4

Installing collected packages: beautifulsoup4
  Running setup.py install for beautifulsoup4

Successfully installed beautifulsoup4
Cleaning up...
(blabla)dirk@discordia:~/Dokumente/devel/python/blabla$ python
Python 2.7.5+ (default, Feb 27 2014, 19:37:08) 
[GCC 4.8.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import bs4 ; from bs4 import BeautifulSoup
>>>

所以也许您想尝试一个新的 virtenv 并使用 pip install 安装 bs4。

关于python - 无法在 virtualenv 中导入 beautifulsoup4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16760854/

相关文章:

Python将dict中的键与另一个div的值进行比较/替换

python - 如何在python中对数字进行一次热编码?

ubuntu - 64 位汇编语言在 ubuntu 上使用 nasm

c++ - 如何在Ubuntu中使用C++从/dev/xxx路径获取设备的USB VID、PID和序列号

terminal - 杀死 Mavericks 上端口 8080 上运行的所有进程

python - 在python中将部分字符串转换为变量名

python - 将 set_array 与 pyplot.pcolormesh 一起使用会破坏图形

apache - 为什么我不能让 Apache 的 CustomLog 指令工作?

java - 如何在 Spring 项目的终端中更新 pom.xml 属性?

iphone - 使用命令行在 iOS 模拟器上启动应用程序