3

What is the easiest way to install python 2 plus lxml plus mechanize on windows? I'm looking for a solution that is easy to follow and also makes it easy to install other libraries (eggs?) in the future.

Edit I want to be able to install libraries which require a compiler. Ruby for windows has a dev kit which allows you to easily install gems that require a compiler. I'm looking for a similar setup for Python.

pguardiario
  • 53,827
  • 19
  • 119
  • 159

6 Answers6

3

For the simplest installation of these components, I recommend going with 32-bit installers for the whole process, so all the links here point to the 32-bit versions. First, download and install Python 2.7.3.

Then you will want to install setuptools Setuptools will make it so you can type "easy_install" in the command prompt and add additional packages. It will come in handy for mechanize.

Now you can download and install lxml for Python 2.7.

Up until now they were all MSI installers, but to get mechanize we have to go to the command prompt. To do that, open the start menu, type cmd, and in the command prompt, enter easy_install mechanize. If typing easy_install doesn't work, make sure to set your PATH (see answer here)

And that's it! For any future libraries, easy_install nameoflibraryhere will do the trick.

So tldr version:

Download and install Python 2.7.3: http://www.python.org/ftp/python/2.7.3/python-2.7.3.msi

Download and install setuptools: http://pypi.python.org/packages/2.7/s/setuptools/setuptools-0.6c11.win32-py2.7.exe#md5=57e1e64f6b7c7f1d2eddfc9746bbaf20

Download and install lxml for Python 2.7: http://pypi.python.org/packages/2.7/l/lxml/lxml-2.2.8.win32-py2.7.exe#md5=deb95d53dbd3734ecfb4f69850758427

In command prompt, type easy_install mechanize

I hope that helps you make the process of installing those on Windows smooth.

Community
  • 1
  • 1
TheJF
  • 831
  • 9
  • 13
2

I would say, at first get PIP then install with pip install lxml lxml. Normally you would now install mechanize like this: pip install mechanize, but the problem is, there is no mechanize port for Python 3, so if you need/want mechanize you have to use Python 2. But maybe the lxml.html capabilities are enough for you.

dav1d
  • 5,917
  • 1
  • 33
  • 52
  • 1
    Installing lxml with pip probably needs a compiler installed. It might be easier to use the installer from here: http://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml – Thomas K Apr 27 '12 at 11:43
  • Sorry, I didn't realize mechanize was python 2 only :( I edited my question – pguardiario Apr 28 '12 at 00:36
1

visit http://www.lfd.uci.edu/~gohlke/pythonlibs/ where you'll find windows binaries (.exe's) for all the python packages available out there :)

pravin
  • 501
  • 2
  • 7
1

You could try installing ActiveState Python(download 32 bit version) and then using the pypm command line tool to install lxml and mechanize with the next commands:

pypm install lxml
pypm install mechanize
ICTylor
  • 470
  • 4
  • 14
  • *sigh* - this answer would carry a lot more weight if you included some download urls at the very least. I'm looking for some exact steps for installing a working python on windows plus lxml + mechanize + a pip that will instann arbitrary eggs. If you don't have that you're just wasting my time. – pguardiario May 01 '12 at 12:15
  • @pguardiario [Link to ActivePython](http://downloads.activestate.com/ActivePython/releases/2.7.2.5/ActivePython-2.7.2.5-win32-x86.msi). It also installs the pypm tool automatically, then you can do the steps I posted before to install lxml and mechanize. Then do pypm install pip. I don't know if it will install arbitrary eggs though – ICTylor May 01 '12 at 12:26
0

Python does not ship any packages that contain a compiler that I am aware of, however, if you install something like Visual Studio it will be recognized by both easy_install or pip. I'd suggest Visual Studio 2008 express c++ edition (Which I believe is free).

Once you have that do a easy_install --always-unzip [package] (which I would suggest over pip). Easy_install will then automatically download the appropriate library and attempt to compile your code.

The problem is that lxml depends on (at the very least) libxml2 & libxslt, which you must build before running easy_install. To build them, you could try something like: https://mail.gnome.org/archives/xml/2010-February/msg00026.html.

As I recall mechanize is a pain to get to compile due to some weird dependencies, however in general if you follow the easy_install [foo], look at error, fix error approach, you will get there.

Good Luck!

Clarus
  • 2,259
  • 16
  • 27
0

I'm not happy with any of the solutions offered. Hopefully someone will come along with a better one but for now it seems safe to say that there is no simple solution for installing python + mechanize + lxml + arbitrary other libraries on windows.

pguardiario
  • 53,827
  • 19
  • 119
  • 159