使用pipenv

时间:2018-01-24 19:23:43

标签: python beautifulsoup pipenv

尝试使用pipenv时有点麻烦。 我运行了以下命令

pipenv安装bs4

它出来了:

���������������������������������Requirement already satisfied: bs4 in /home/sam/.local/share/virtualenvs/ICOtools-kKWO0fqD/lib/python2.7/site-packages
Requirement already satisfied: beautifulsoup4 in /home/sam/.local/share/virtualenvs/ICOtools-kKWO0fqD/lib/python2.7/site-packages (from bs4)

Adding bs4 to Pipfile's [packages]���
Locking [dev-packages] dependencies���
Locking [packages] dependencies���
Updated Pipfile.lock (5de6ca)!

然后当我运行我的脚本时,我仍然得到

'ImportError: No module named bs4'

我脚本的第二行是

'from bs4 import BeautifulSoup' 

我正在使用crouton在chromebook上运行Ubuntu(xenial),不确定是否会影响它。

2 个答案:

答案 0 :(得分:0)

而不是pipenv install bs4

尝试pipenv install beautifulsoup4

答案 1 :(得分:0)

我相信你没有激活你的虚拟环境。默认情况下,当您运行pipenv install bs4时,会创建virtualenv。您可以从同一目录运行pipenv shell以激活它(并exit停用)。 EX:

ubuntu@ubuntu-zesty:~$ pipenv install bs4
Installing bs4…
Collecting bs4
Collecting beautifulsoup4 (from bs4)
  Using cached beautifulsoup4-4.6.0-py2-none-any.whl
Installing collected packages: beautifulsoup4, bs4
Successfully installed beautifulsoup4-4.6.0 bs4-0.0.1

Adding bs4 to Pipfile's [packages]…
Locking [dev-packages] dependencies…
Locking [packages] dependencies…
Updated Pipfile.lock (9e60b9)!
ubuntu@ubuntu-zesty:~$ pipenv shell
Spawning environment shell (/bin/bash). Use 'exit' to leave.
ubuntu@ubuntu-zesty:~$ source /home/ubuntu/.local/share/virtualenvs/ubuntu-7Wf190Ea/bin/activate
(ubuntu-7Wf190Ea) ubuntu@ubuntu-zesty:~$ python
Python 2.7.14 (default, Sep 23 2017, 22:06:14)
[GCC 7.2.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import bs4
>>> print (bs4.__version__)
4.6.0
>>> quit()
(ubuntu-7Wf190Ea) ubuntu@ubuntu-zesty:~$ exit
exit
ubuntu@ubuntu-zesty:~$