pip install lxml – Permission denied

When using Python you mostly rely on pip to install necessary libraries. Recently I ran the following command on my Mac:

pip install lxml

The result was the following output:

error: could not create '/Library/Python/2.7/site-packages/lxml': Permission denied

Obviously, writing to the folder /Library/ is not possible for a normal user account. There are several possible options to overcome this problem.

  1. You can use the command sudo pip install lxml to install the package
  2. You can use the command STATIC_DEPS=true sudo pip install lxml to install the package. This will download libxml2 and libxslt and build the source distribution afterwards.
  3. You use virtualenv to install the package only locally in your current project directory. See here for a good tutorial of virtualenv.

From my perspective option 3 is the cleanest way to install and manage lxml.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s