14w*_*wml 3 beautifulsoup virtualenv python-3.5 jupyter-notebook
I'm using a Jupyter notebook, Python 3.5, and a virtual environment.
Within my virtual env I did:
(venv) > pip install BeautifulSoup4
Run Code Online (Sandbox Code Playgroud)
Which seemed to run fine b/c the terminal output was:
Downloading beautifulsoup4-4.6.0-py2-none-any.whl (86kB)
100% |????????????????????????????????| 92kB 297kB/s
Installing collected packages: BeautifulSoup4
Successfully installed BeautifulSoup4-4.6.0
Run Code Online (Sandbox Code Playgroud)
But when I run my Jupyter notebook I get:
ImportError Traceback (most recent call last)
<ipython-input-1-5fe69888b1a1> in <module>()
5 from itertools import groupby
6 import pickle
----> 7 import bs4
8 import matplotlib.pyplot as plt
9 get_ipython().run_line_magic('matplotlib', 'inline')
ImportError: No module named 'bs4'
Run Code Online (Sandbox Code Playgroud)
And I can't change the line import bs4 to from bs4 import BeautifulSoup which I've seen on other SO posts b/c its read-only and I'm not supposed to
Since you are using Python 3, I think you needed to do
pip3 install BeautifulSoup4
Run Code Online (Sandbox Code Playgroud)
Just pip install would have been for the Python 2 package.
Other things to check:
First make sure you ran both the BeautifulSoup install in your virtualenv, and the python3 prompt or Jupyter notebook in your virtualenv. If you did the install in your root environment and the notebook is run in your virtualenv, or vice versa, you might have a mismatch in your site-packages directory.
通过在命令提示符下键入pip3 list并注意它已出现在列表中,确保确实安装了软件包。
检查Jupyter笔记本是否确实在运行Python 3.5内核(浏览器窗口的右上角)
检查安装软件包的路径在sys.path中
打开Python3提示符或在Jupyter中运行
import sys
print (sys.path)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2509 次 |
| 最近记录: |