如何为 Python 2.7 安装机械化?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4888463/
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
How to install mechanize for Python 2.7?
提问by user601828
I saved mechanize in my Python 2.7 directory. But when I type import mechanizeinto the Python shell, I get an error message that reads:
我将机械化保存在我的 Python 2.7 目录中。但是当我输入import mechanizePython shell 时,我收到一条错误消息,内容如下:
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import mechanize
ImportError: No module named mechanize
回答by Daniel DiPaolo
You need to follow the installation instructionsand not just download the files into your Python27directory. It has to be installed in the site-packagesdirectory properly, which the directions tell you how to do.
您需要按照安装说明进行操作,而不仅仅是将文件下载到您的Python27目录中。它必须site-packages正确安装在目录中,说明会告诉您如何操作。
回答by Wooble
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, containing setup.py(which you should use to install the package), documentation, etc. This directory is not a package. Additionally, your Python27directory is probably not in PYTHONPATH; more likely one or more subdirectories of it are.
您需要将实际包(包含 的目录__init__.py)存储在系统 PYTHONPATH 中的某处。通常,包与包目录上方的目录一起分发,包含setup.py(您应该用来安装包)、文档等。此目录不是包。此外,您的Python27目录可能不在 PYTHONPATH 中;更有可能是它的一个或多个子目录。
回答by Corey Goldberg
using pip:
使用pip:
pip install mechanize
or download the mechanize distributionarchive, open it, and run:
或者下载 mechanize分发存档,打开它,然后运行:
python setup.py install
回答by hari_sree
I dont know why , but "pip install mechanize" didnt work for me . easy install worked anyway . Try this :
我不知道为什么,但是“pip install mechanize”对我不起作用。无论如何,简单的安装工作。尝试这个 :
sudo easy_install mechanize
回答by opmeitle
sudo pip-2.7 install mechanize
回答by evedovelli
Try this on Debian/Ubuntu:
在 Debian/Ubuntu 上试试这个:
sudo apt-get install python-mechanize
回答by Ununpentium
You need to install the python-setuptoolspackage:
您需要安装python-setuptools软件包:
apt-get install python-setuptoolson Debian-ish systems
yum install python-setuptoolson Redhat-ish systems
apt-get install python-setuptools在 Debian-ish 系统
yum install python-setuptools上 在 Redhat-ish 系统上
Use sudoif applicable
sudo如果适用,请使用
回答by user3349196
install dependencies on Debian/Ubuntu:
在 Debian/Ubuntu 上安装依赖项:
$ sudo apt-get install python-pip python-matplotlib
$ sudo apt-get install python-pip python-matplotlib
install multi-mechanize from PyPIusing Pip:
安装 multi-mechanizePyPI使用Pip:
$ sudo pip install -U multi-mechanize
$ sudo pip install -U multi-mechanize
回答by beetree
Here's what I did which worked:
这是我所做的工作:
yum install python-pip
pip install -U multi-mechanize
回答by yangli.liy
It seems you need to follow the installation instructions in Daniel DiPaolo's answer to try one of the two approaches below
似乎您需要按照 Daniel DiPaolo 的回答中的安装说明尝试以下两种方法之一
- install easy_install first by running "easy_install mechanize", or
- download the zipped package mechanize-0.2.5.tar.gz/mechanize-0.2.5.zip and (IMPORTANT) unzip the package to the directory where your .py file resides (i.e. "the resulting top-level directory" per the instructions). Then install the package by running "python setup.py install".
- 首先通过运行“easy_install mechanize”安装easy_install,或者
- 下载压缩包 mechanize-0.2.5.tar.gz/mechanize-0.2.5.zip 并(重要)将包解压缩到您的 .py 文件所在的目录(即根据说明的“生成的顶级目录”) )。然后通过运行“python setup.py install”安装包。
Hopefully that will resolve your issue!
希望这能解决您的问题!

