如何为Python 2.7安装mechanize?

发布于 2024-10-15 21:23:37 字数 279 浏览 5 评论 0原文

我将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(11

涫野音 2024-10-22 21:23:38

使用 pip

pip install mechanize

或下载 mechanize distribution 存档,打开它并运行:

python setup.py install

using pip:

pip install mechanize

or download the mechanize distribution archive, open it, and run:

python setup.py install
冬天的雪花 2024-10-22 21:23:38

在 Debian/Ubuntu 上尝试一下:

sudo apt-get install python-mechanize

Try this on Debian/Ubuntu:

sudo apt-get install python-mechanize
守护在此方 2024-10-22 21:23:38

您需要按照安装说明进行操作,而不仅仅是将文件下载到您的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 the site-packages directory properly, which the directions tell you how to do.

不必在意 2024-10-22 21:23:38

我不知道为什么,但“pip install mechanize”对我不起作用。无论如何,安装很简单。试试这个:

sudo easy_install mechanize

I dont know why , but "pip install mechanize" didnt work for me . easy install worked anyway . Try this :

sudo easy_install mechanize
|煩躁 2024-10-22 21:23:38

这是我所做的有效的:

yum install python-pip
pip install -U multi-mechanize

Here's what I did which worked:

yum install python-pip
pip install -U multi-mechanize
陌上芳菲 2024-10-22 21:23:38
sudo pip-2.7 install mechanize
sudo pip-2.7 install mechanize
梦里°也失望 2024-10-22 21:23:38

您需要将实际的包(包含 __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, containing setup.py (which you should use to install the package), documentation, etc. This directory is not a package. Additionally, your Python27 directory is probably not in PYTHONPATH; more likely one or more subdirectories of it are.

空城缀染半城烟沙 2024-10-22 21:23:38

在 Debian/Ubuntu 上安装依赖项:

$ sudo apt-get install python-pip python-matplotlib

使用 PipPyPI 安装 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 using Pip:

$ sudo pip install -U multi-mechanize

_蜘蛛 2024-10-22 21:23:38

您需要

在 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 systems
yum install python-setuptools on Redhat-ish systems

Use sudo if applicable

ㄖ落Θ余辉 2024-10-22 21:23:38

看来您需要按照 Daniel DiPaolo 的答案中的安装说明尝试以下两种方法之一,

  1. 首先通过运行“easy_install mechanize”安装 easy_install,或者
  2. 下载压缩包 mechanize-0.2.5.tar.gz/mechanize-0.2。 5.zip 并(重要)将包解压到 .py 文件所在的目录(即按照说明的“生成的顶级目录”)。然后通过运行“python setup.py install”来安装该包。

希望这能解决您的问题!

It seems you need to follow the installation instructions in Daniel DiPaolo's answer to try one of the two approaches below

  1. install easy_install first by running "easy_install mechanize", or
  2. 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".

Hopefully that will resolve your issue!

第几種人 2024-10-22 21:23:38
pip install mechanize

mechanize 仅支持 python 2。

对于 python3,请参阅 https://stackoverflow.com/a/31774959/4773973 用于替代方案。

pip install mechanize

mechanize supports only python 2.

For python3 refer https://stackoverflow.com/a/31774959/4773973 for alternatives.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文