0

So, I downloaded Python 2.7.5 on Ubuntu 12.04 and attempted to install the module "lxml" using:

sudo pip install lxml

When I try:

pip freeze

it lists lxml as an installed package, however when I run a python script using

help('modules')

lxml is no longer listed amongst the modules. I've checked using

python -V

and I'm apparently running Python 2.7.5. I've done some poking around and nothing seems to quite suite what's going on with me here. I believe that I'm perhaps installing modules to a different version of Python, and that's the reason pip lists it as installed but not Python's help command. I'm rather new to Linux so I'm not particularly sure what to do next. Any help is appreciated, thanks!

Quick edit: I suppose if you haven't already gathered I should mention that when I try to run a Python script importing something from lxml it tells me there is no module named lxml.

Edit 2: Simply using import lxml does not work either.

Edit 3: pip --version yields that it is hooked to Python2.7. Would it say 2.7.5 or is this correct?

Edit 4: tried reinstalling pip and attempting to install lxml, no changes.

savagesun
  • 109
  • 6
  • Does `import lxml` work? – Martijn Pieters Aug 23 '13 at 08:45
  • Nope, it gives the no module named lxml error. – savagesun Aug 23 '13 at 08:52
  • 2
    Then you have the wrong `pip`; it is tied to a different Python installation. Run `pip -V` and see what Python `lxml` was installed into. – Martijn Pieters Aug 23 '13 at 08:56
  • It seems pip -V is not a command, so I tried pip --version and it showed that it was linked to Python2.7, which I believe is what I'm using currently, unless it would say Python2.7.5. And if that is the case should I reinstall pip? – savagesun Aug 23 '13 at 09:07
  • In my version `-V` is an alias for `--version`. What does `which python` say you are using? Compare that to `which pip` and the output of `pip --version`. – Martijn Pieters Aug 23 '13 at 10:16

1 Answers1

0

You are using two different versions of Python? If you are on a Linux machine and probably using new Linux distributions the default python is 2.7.3. Thus, the pip you installed from sudo apt-get install python-pip is for that default python.

For your issue, there are two possible solutions:

Solution 1:

Manually copy packages into site-packages

The site-packages are on this directory: /usr/lib/local/python2.7/site-packages

Manually copy the module in that directory.

Solution 2:

Two pips for different python versions

Here's a tutorial:

How to organize Python modules for PyPI to support 2.x and 3.x

Community
  • 1
  • 1
Joyfulgrind
  • 2,762
  • 8
  • 34
  • 41
  • Thanks for the input. I decided to go ahead and reinstall Ubuntu before reading this though, and it seemed to work when I skipped the step of installing a newer Python. – savagesun Aug 23 '13 at 11:07
  • You should never mess up with the default Python provided by the Linux distributions as the packages manager are build using python. One great thing about Python is various versions run parallely without conflicting. – Joyfulgrind Aug 23 '13 at 13:17