-1

I am new to python and programming in Terminal. I am trying to install and then access lxml but I already installed Canopy, and I don't know how to get to the normal installation directory or how to make sure that Canopy can see the installation.

Question: How do you install lxml on Mac OSX?

Attempts so far: First, I tried:

$ import lxml
-bash: import: command not found

Showing my complete ignorance, I figured that maybe I need to be in python environment to import it, but that is not the case either:

$ python import lxml
/Users/user/Library/Enthought/Canopy_32bit/User/Resources/Python.app/Contents/MacOS/Python: can't open file 'import': [Errno 2] No such file or directory

On SO, I learned that most folks say that you need to make sure that the underlying libraries are installed. So, I did this:

$ apt-get install python-dev libxml2 libxml2-dev libxslt-dev
-bash: apt-get: command not found

Someone else suggested that you should check the static dependencies. So, I did this:

$ python setup.py build --static-deps
/Users/user/Library/Enthought/Canopy_32bit/User/Resources/Python.app/Contents/MacOS/Python:     can't open file 'setup.py': [Errno 2] No such file or directory

I found this confusing, and I cannot figure out what to do. I am not sure even how I can check the libxml2 installed because I just run into these errors that nothing exists or the command -get does not work.

Background: I need to be able to use python for xml parsing and data analysis. I purchased Wes McKinney's book on Python for Data Analysis, and he suggests using Enthought's EPD (but it is now Canopy). I downloaded Canopy. Then, to do what I need to do (about half way through the book), it has you use lxml.

Google searches and reading SO suggest that Mac OSX already comes with libxml2 and libxlst

Possible helpful details: My bash profile only contains:

# Added by Canopy installer on 2013-05-29
source /Users/user/Library/Enthought/Canopy_32bit/User/bin/activate

I am running: Max OS X Version 10.7.5

I installed XCode and installed "Command Line Tools"

Please forgive my ignorance. I've ready every question that I can find related to this on SO and searched. I may be missing something basic.

Thanks.

jessi
  • 1,438
  • 1
  • 23
  • 36
  • You're already halfway through a book about using Python for data analysis and you haven't learned how to run the python interpreter yet? – Wooble May 30 '13 at 16:49
  • that would be a yes. I probably would have benefited from an "intro to python" or something because the book does not really explain what is going on in the background. I'm used to using plain text syntax, like for programming in R, so I assumed it would be straightforward. I did not anticipate the terminal interface issues. – jessi May 30 '13 at 16:53

1 Answers1

0

You need to install lxml and then run Python before importing it.

$ pip install lxml
$ python
Python <big version string specific to your python installation...>
Type "help", "copyright", "credits" or "license" for more information.
>>> import lxml
>>>

This is a pretty basic question, your best bet is to read through and follow along with the Python tutorial or an introductory book to Python programming. You'll have a very difficult time following along with the book without a basic understanding of Python.

The tutorials in the official documentation are good, and are available for both Python 3 and 2:

Python 3 Tutorial

Python 2 Tutorial

Jeremiah
  • 1,437
  • 8
  • 17
  • The solution does not work because I get: `$ python Enthought Canopy Python 2.7.3 | 32-bit | (default, Mar 25 2013, 15:42:04) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import lxml Traceback (most recent call last): File "", line 1, in ImportError: No module named lxml` I'll go through these tutorials. Thanks, @Jeremiah. I was "optimistically" hoping to avoid installing things. – jessi May 30 '13 at 16:58
  • It looks like you already have Python installed. To see which version, run: python --version – Jeremiah May 30 '13 at 17:01
  • I have python installed. I have used it for some simple programs. I just can't seem to get around canopy to install lxml `$ python --version Python 2.7.3 -- 32-bit ` – jessi May 30 '13 at 17:03
  • You can try quitting the Python shell and running "pip install lxml", then relaunching Python and try "import lxml" again – Jeremiah May 30 '13 at 17:13
  • WOOT. `Successfully installed lxml` I did not even think about using pip. Thanks! – jessi May 30 '13 at 17:24
  • I can not figure out how to accept your answer in the comments, @Jeremiah (the one about quitting and using pip) – jessi May 30 '13 at 17:28
  • I'm not sure if you can accept the comment as an answer. I updated the original answer to say to install lxml with pip before launching Python and importing. – Jeremiah May 30 '13 at 17:59
  • Canopy has a very nice package manager. And lxml comes with Canopy Basic edition, just scroll to lxml in the alphabetical list in the package manager and click 'install'. – Bennett Brown Jun 09 '13 at 04:15