2

尝试使用 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),不确定这是否会影响这一点。

4

2 回答 2

1

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

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:~$
于 2018-01-24T21:39:32.467 回答
0

而不是 pipenv 安装 bs4

尝试pipenv install beautifulsoup4

于 2018-01-24T19:41:27.443 回答