无法为 python 3.6 安装 BeautifulSoup
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/43834999/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Cannot install BeautifulSoup for python 3.6
提问by Cooby Booby
I have spent the past 45 minutes hopelessly trying to run:
在过去的 45 分钟里,我绝望地试图跑步:
from bs4 import BeautifulSoup
But to no avail. I have tried the commands:
但无济于事。我已经尝试过以下命令:
python -m pip install beautifulsoup4
where it says:
它说:
Requirement already satisfied: beautifulsoup4 in c:\python27\lib\site-packages
I have tried:
我试过了:
pip3 install beautifulsoup4
where it says the same.
它说同样的地方。
I have tried:
我试过了:
pip install beautifulsoup4
Same thing.
一样。
I have looked all over stackoverflow, youtube, I am driving myself insane trying to figure this out. I have no idea what to do, please help me.
我已经查看了stackoverflow,youtube,我正在疯狂地试图解决这个问题。我不知道该怎么办,请帮助我。
When I try to run my program main.py with the following code:
当我尝试使用以下代码运行我的程序 main.py 时:
from bs4 import BeautifulSoup
With py -3 main.py, I get the error:
使用 py -3 main.py,出现错误:
ModuleNotFoundError: No module named 'bs4'
Please please please please help me.
请请请帮助我。
I have tried the method proposed at BeautifulSoup4 can't be installed in python3.5 on Windows7but to no avail.
我已经尝试过BeautifulSoup4提出的方法无法安装在Windows7上的python3.5但无济于事。
回答by Darshan
Now there is beautifulsoup4 for Python 3.6. It's the same, am using it this way on my webcrawl project.
现在有适用于 Python 3.6 的 beautifulsoup4。是一样的,我在我的 webcrawl 项目中以这种方式使用它。
Just add the beautifulsoup4 module to the project. Then try the line
只需将 beautifulsoup4 模块添加到项目中即可。然后试试线
from bs4 import BeautifulSoup
回答by shahin
As of now the module is not getting loaded to python3.6 Try This
截至目前,该模块尚未加载到 python3.6 试试这个
python3.6 -m pip install beautifulsoup4
回答by xandra
I went through something similar but managed to install BeautifulSoup4. I tried running the commands suggested but none of it worked. So here's what I did.
我经历了类似的事情,但设法安装了 BeautifulSoup4。我尝试运行建议的命令,但没有一个奏效。所以这就是我所做的。
On the command prompt, I decided to try running the commands on the python scripts directory
在命令提示符下,我决定尝试在 python 脚本目录上运行命令
cd C:\Users\User\AppData\Local\Programs\Python\Python36-32\Scripts
then
然后
pip3 install BeautifulSoup4
You should see something that says
你应该看到一些东西说
Collecting BeautifulSoup4
Downloading beautifulsoup4-4.6.0-py3-none-any.whl (86kB)
100% |████████████████████████████████| 92kB 6.7kB/s
Installing collected packages: BeautifulSoup4
Successfully installed BeautifulSoup4-4.6.0
Hope this helps.
希望这可以帮助。
回答by Akshay
Just install:
只需安装:
pip3 install bs4 --user
Import in code:
在代码中导入:
from bs4 import BeautifulSoup
import requests
res = requests.get(url)
soup = BeautifulSoup(res.content,"html.parser")
回答by AlanSTACK
Install this instead: https://anaconda.org/(this is what we use at work)
安装它:https: //anaconda.org/(这是我们在工作中使用的)
It's basically Python with the top 100 modules all installed. The downside is, it's huge (300 MB).
它基本上是安装了前 100 个模块的 Python。缺点是它很大(300 MB)。
回答by Sohaib Arif
The problem is that while it installed beautifulsoup4 and several libraries are not supported on Python 3.6 at the moment.
问题是,虽然它安装了 beautifulsoup4,但目前 Python 3.6 不支持几个库。
You have two options. You can either use a virtual environment like Anaconda or virtualenv as Alan suggested. Here you will make an environment and set the python version to 3.5
你有两个选择。您可以使用 Alan 建议的 Anaconda 或 virtualenv 等虚拟环境。在这里你将创建一个环境并将python版本设置为3.5
The other option is to uninstall python 3.6 and install 3.5 and then beautifulsoup4
另一种选择是卸载python 3.6并安装3.5然后beautifulsoup4
回答by user3325126
I was getting this same error on a mac and the problem stemmed from using Python 2.7.10 when I thought I was using 3.7.
我在 mac 上遇到了同样的错误,这个问题源于当我认为我使用的是 3.7 时使用 Python 2.7.10。
python test.py
File "test.py", line 1, in <module>
from bs4 import BeautifulSoup
ImportError: No module named bs4
However when I was explicit about what python version I wanted to use everything worked. So on the terminal use python and then your version number. Example my version is 3.7:
但是,当我明确说明我想使用什么 python 版本时,一切都有效。所以在终端上使用 python 然后你的版本号。例如我的版本是 3.7:
python3.7 test.py
回答by Kaouther Ghabri St. Clair
Thanks noobninja,
谢谢 noobninja,
As for extending Python 3.8 to BeautifulSoup4, only using ANACONDA worked with me (using MAC OS).
至于将 Python 3.8 扩展到 BeautifulSoup4,我只使用 ANACONDA(使用 MAC OS)。
- Download Anaconda for Mac OS (more than 2 GB)
In terminal: test Anaconda installation:
$ conda list
- $ conda install beautifulsoup4
- Run Python3 shell
- type : from bs4 import BeautifulSoup
- 下载 Mac OS 版 Anaconda(超过 2 GB)
在终端中:测试 Anaconda 安装:
$ conda 列表
- $ conda 安装 beautifulsoup4
- 运行 Python3 外壳
- 类型:从 bs4 导入 BeautifulSoup
No error message !
没有错误信息!