How to install lxml for python without administative rights on linux?
If you have no admin rights, and cannot convince the administrator to install the relevant packages for you, you have two options:
Option 1 - Download sources for libxml2
and libxslt
and compile and install them under your $HOME
somewhere, then build python-lxml against those copies.
This is a pretty involved example, since if you're missing further dependencies you could be downloading / compiling for a long time.
Option 2 - Download the binary packages for the same distribution of Linux that is used on your server, and extract the contents under your home directory.
For example, if you're running Ubuntu Lucid, you'd first find out the version your OS is using and then download the packages you're missing:
% uname -m
x86_64
% aptitude show libxml2 | grep Version
Version: 2.7.6.dfsg-1ubuntu1.1
Next download the packages you need direct from the Ubuntu server:
% mkdir root ; cd root
% wget http://us.archive.ubuntu.com/ubuntu/pool/main/libx/libxml2/libxml2_2.7.6.dfsg-1ubuntu1.1_amd64.deb
% wget http://us.archive.ubuntu.com/ubuntu/pool/main/libx/libxslt/libxslt1.1_1.1.26-6build1_amd64.deb
% wget http://us.archive.ubuntu.com/ubuntu/pool/main/l/lxml/python-lxml_2.2.4-1_amd64.deb
Extract the contents and merge the lxml native and pure-python code and move the shared libraries to the top, then remove the extracted contents:
% dpkg-deb -x libxml2_2.7.6.dfsg-1ubuntu1.1_amd64.deb .
% dpkg-deb -x libxslt1.1_1.1.26-6build1_amd64.deb .
% dpkg-deb -x python-lxml_2.2.4-1_amd64.deb .
% mv ./usr/lib/python2.6/dist-packages/lxml .
% mv ./usr/share/pyshared/lxml/* lxml
% mv ./usr/lib .
% rm *.deb
% rm -rf usr
Finally, to use those files you need to set your LD_LIBRARY_PATH and PYTHONPATH environment variables to point into $HOME/root
. Place these in your ~/.bashrc
(or equivalent) so they are permanent:
% export LD_LIBRARY_PATH=$HOME/root/lib
% export PYTHONPATH=$HOME/root
You can verify that the shared objects are being found using ldd
(if it's installed):
% ldd $HOME/root/lxml/etree.so | grep $HOME
libxslt.so.1 => /home/user/root/lib/libxslt.so.1 (0x00007ff9b1f0f000)
libexslt.so.0 => /home/user/root/lib/libexslt.so.0 (0x00007ff9b1cfa000)
libxml2.so.2 => /home/user/root/lib/libxml2.so.2 (0x00007ff9b19a9000)
Then you're ready to test Python:
% python
>>> from lxml import etree
How to install python modules without root access?
In most situations the best solution is to rely on the so-called "user site" location (see the PEP for details) by running:
pip install --user package_name
Below is a more "manual" way from my original answer, you do not need to read it if the above solution works for you.
With easy_install you can do:
easy_install --prefix=$HOME/local package_name
which will install into
$HOME/local/lib/pythonX.Y/site-packages
(the 'local' folder is a typical name many people use, but of course you may specify any folder you have permissions to write into).
You will need to manually create
$HOME/local/lib/pythonX.Y/site-packages
and add it to your PYTHONPATH
environment variable (otherwise easy_install will complain -- btw run the command above once to find the correct value for X.Y).
If you are not using easy_install
, look for a prefix option, most install scripts let you specify one.
With pip you can use:
pip install --install-option="--prefix=$HOME/local" package_name
Installing lxml, libxml2, libxslt on Windows 8.1
I was able to fix the installation with the following steps. I hope others find this helpful.
My installation of "pip" was working fine before the problem. I went to the Windows command line and made sure that "wheel" was installed.
C:\Python34>python -m pip install wheel
Requirement already satisfied (use --upgrade to upgrade): wheel in c:\python34\lib\site-packages
After that I downloaded the lxml file from http://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml and placed it in my python directory "C:\Python34"
In that directory I ran the following:
C:\Python34>python -m pip install lxml-3.4.4-cp34-none-win32.whl
The results were:
Processing c:\python34\lxml-3.4.4-cp34-none-win32.whl
Installing collected packages: lxml
Successfully installed lxml-3.4.4
I opened PyCharm and lxml module was available. I was able to execute the code without problem.
What I learned (though this may be corrected by others more knowledgeable)
- Need to install the desired module (as a "*.whl" file) using pip and wheel.
- Using Dropbox to share a code folder with different PyCharm installations causes confusion for the "workspace.xml" file. The two computers kept writing over each other, messing up the installation paths.
Hope this helps.
Python unable to find lxml module
Solved the problem.
It seems that a software that i installed messed out my python path. The python that i was using when calling python in a terminal was the one installed by the software, and the one called by my script was the one installed on my system.
So, i just removed the python path of the software from the path variable of bash.
Python: ImportError: lxml not found, please install it
Based on the fact that the error is:
/Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6
This means that you are working with python-3.6. Now usually the package manager for python-3.x is pip3
. So you probably should install it with:
pip3 install lxml
Getting Permission Denied when running pip as root on my Mac
Use a virtual environment:
$ virtualenv myenv
.. some output ..
$ source myenv/bin/activate
(myenv) $ pip install what-i-want
You only use sudo
or elevated permissions when you want to install stuff for the global, system-wide Python installation.
It is best to use a virtual environment which isolates packages for you. That way you can play around without polluting the global python install.
As a bonus, virtualenv does not need elevated permissions.
Invalid requirements.txt on deploying to AWS. Pip couldn't install lxml
I guess so.
try the following command, and then reinstall lxml:
$ sudo apt-get install libxml2-dev libxslt1-dev python-dev
If failed again, have a check the following questions, they're related to lxml installation problems:
- Installing lxml module in python
- How to install lxml on Ubuntu
- pip install lxml error
Related Topics
Groupby Pandas Dataframe and Select Most Common Value
Pipe Raw Opencv Images to Ffmpeg
Opening a Python Thread in a New Console Window
Plotting the Data with Scrollable X (Time/Horizontal) Axis on Linux
How to Benchmark Part of Tensorflow Graph
Django Form Dropdown List of Numbers
How to Solve Unicodedecodeerror in Python 3.6
What Does -≫ Mean in Python Function Definitions
Python List by Value Not by Reference
Python Gdal 2.1 Installation on Ubuntu 16.04
Oserror: [Error 1] Operation Not Permitted
Auto.Arima() Equivalent for Python
Running Python Script as a Systemd Service