如何为Python 2.7安装mechanize?
我将 mechanize 保存在 Python 2.7 目录中。但是当我在 Python shell 中输入 import mechanize
时,我收到一条错误消息:
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import mechanize
ImportError: No module named mechanize
I saved mechanize in my Python 2.7 directory. But when I type import mechanize
into the Python shell, I get an error message that reads:
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import mechanize
ImportError: No module named mechanize
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(11)
使用 pip:
或下载 mechanize distribution 存档,打开它并运行:
using pip:
or download the mechanize distribution archive, open it, and run:
在 Debian/Ubuntu 上尝试一下:
Try this on Debian/Ubuntu:
您需要按照安装说明进行操作,而不仅仅是将文件下载到您的
Python27中目录。它必须正确安装在
site-packages
目录中,说明会告诉您如何操作。You need to follow the installation instructions and not just download the files into your
Python27
directory. It has to be installed in thesite-packages
directory properly, which the directions tell you how to do.我不知道为什么,但“pip install mechanize”对我不起作用。无论如何,安装很简单。试试这个:
I dont know why , but "pip install mechanize" didnt work for me . easy install worked anyway . Try this :
这是我所做的有效的:
Here's what I did which worked:
您需要将实际的包(包含
__init__.py
的目录)存储在系统 PYTHONPATH 中的某个位置。通常,包是在包目录上方的一个目录中分发的,其中包含setup.py(您应该使用它来安装包)、文档等。该目录不是包。此外,您的 Python27 目录可能不在 PYTHONPATH 中;更有可能的是它的一个或多个子目录。You need the actual package (the directory containing
__init__.py
) stored somewhere that's in your system's PYTHONPATH. Normally, packages are distributed with a directory above the package directory, containingsetup.py
(which you should use to install the package), documentation, etc. This directory is not a package. Additionally, yourPython27
directory is probably not in PYTHONPATH; more likely one or more subdirectories of it are.在 Debian/Ubuntu 上安装依赖项:
$ sudo apt-get install python-pip python-matplotlib
使用
Pip
从PyPI
安装 multi-mechanize:<代码>$ sudo pip install -U multi-mechanize
install dependencies on Debian/Ubuntu:
$ sudo apt-get install python-pip python-matplotlib
install multi-mechanize from
PyPI
usingPip
:$ sudo pip install -U multi-mechanize
您需要
在 Debian-ish 系统上安装
python-setuptools
软件包:apt-get install python-setuptools
在 Redhat-ish 系统上
yum install python-setuptools
使用
sudo
(如果适用)You need to install the
python-setuptools
package:apt-get install python-setuptools
on Debian-ish systemsyum install python-setuptools
on Redhat-ish systemsUse
sudo
if applicable看来您需要按照 Daniel DiPaolo 的答案中的安装说明尝试以下两种方法之一,
希望这能解决您的问题!
It seems you need to follow the installation instructions in Daniel DiPaolo's answer to try one of the two approaches below
Hopefully that will resolve your issue!
mechanize 仅支持 python 2。
对于 python3,请参阅 https://stackoverflow.com/a/31774959/4773973 用于替代方案。
mechanize supports only python 2.
For python3 refer https://stackoverflow.com/a/31774959/4773973 for alternatives.