[英]How to install mechanize for Python 2.7?
I saved mechanize in my Python 2.7 directory. 我在我的Python 2.7目录中保存了mechanize。 But when I type
import mechanize
into the Python shell, I get an error message that reads: 但是当我在Python shell中输入
import mechanize
时,我收到一条错误消息:
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import mechanize
ImportError: No module named mechanize
pip install mechanize
or download the mechanize distribution archive, open it, and run: 或者下载mechanize distribution archive,打开它,然后运行:
python setup.py install
在Debian / Ubuntu上试试这个:
sudo apt-get install python-mechanize
You need to follow the installation instructions and not just download the files into your Python27
directory. 您需要按照安装说明进行操作 ,而不仅仅是将文件下载到
Python27
目录中。 It has to be installed in the site-packages
directory properly, which the directions tell you how to do. 它必须正确安装在
site-packages
目录中,方向告诉您如何操作。
Here's what I did which worked: 这是我做的工作:
yum install python-pip
pip install -U multi-mechanize
I dont know why , but "pip install mechanize" didnt work for me . 我不知道为什么,但“pip install mechanize”对我没有用。 easy install worked anyway .
无论如何都很容易安装。 Try this :
尝试这个 :
sudo easy_install mechanize
sudo pip-2.7 install mechanize
You need the actual package (the directory containing __init__.py
) stored somewhere that's in your system's PYTHONPATH. 您需要存储在系统的PYTHONPATH中的某个实际包(包含
__init__.py
的目录)。 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. 通常,包与包目录上方的目录一起分发,包含
setup.py
(您应该用它来安装包),文档等。这个目录不是包。 Additionally, your Python27
directory is probably not in PYTHONPATH; 另外,你的
Python27
目录可能不在PYTHONPATH中; more likely one or more subdirectories of it are. 更可能是它的一个或多个子目录。
You need to install the python-setuptools
package: 您需要安装
python-setuptools
包:
apt-get install python-setuptools
on Debian-ish systems yum install python-setuptools
on Redhat-ish systems Debian-ish系统上的
apt-get install python-setuptools
yum install python-setuptools
在Redhat-ish系统上yum install python-setuptools
Use sudo
if applicable 如果适用,请使用
sudo
install dependencies on Debian/Ubuntu: 在Debian / Ubuntu上安装依赖项:
$ sudo apt-get install python-pip python-matplotlib
install multi-mechanize from PyPI
using Pip
: 使用
Pip
从PyPI
安装multi-mechanize:
$ sudo pip install -U multi-mechanize
It seems you need to follow the installation instructions in Daniel DiPaolo's answer to try one of the two approaches below 您似乎需要按照Daniel DiPaolo的回答中的安装说明尝试以下两种方法之一
Hopefully that will resolve your issue! 希望这将解决您的问题!
pip install mechanize
mechanize supports only python 2. mechanize仅支持python 2。
For python3 refer https://stackoverflow.com/a/31774959/4773973 for alternatives. 对于python3,请参阅https://stackoverflow.com/a/31774959/4773973以获取替代方案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.