7

Update 2:

the main problem turned out to be a different one from what I had thought it was, and asked for help here. I moved the new question to a new post:

Install custom python package in virtualenv


Update: ok, so I screwed up my non-virtualenv by accident. The non-virtualenv (normal bash) I could easily fix by removing the manually installed (via pip) lxml and running

conda install lxml --force 

But for some reason, that doesn't work in the virtualenv. There, running

 conda install lxml --force 

works without error message, but when I run python and simply say

>>> import lxml Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: No module named lxml 

Any suggestions??


old message:

I'm trying to use virtualenv for my python flask application. The python code runs perfectly fine without the virtualenv.

I've installed the packages I need in the virtualenv, but I after installing lxml via

pip install lxml Installing collected packages: lxml Successfully installed lxml-3.6.0 

I get the following error message when running my code:

 File "/Users/XXX/xxx/flask-aws/lib/python2.7/site-packages/docx-0.2.4-py2.7.egg/docx.py", line 17, in <module> from lxml import etree ImportError: dlopen(/Users/XXX/xxx/flask-aws/lib/python2.7/site-packages/lxml/etree.so, 2): Library not loaded: libxml2.2.dylib Referenced from: /Users/XXX/xxx/flask-aws/lib/python2.7/site-packages/lxml/etree.so Reason: Incompatible library version: etree.so requires version 12.0.0 or later, but libxml2.2.dylib provides version 10.0.0 

I have seen other people report similar problems at stackoverflow, and one guy remarked that the problem might related to the virtualenv, but there was no solution.

Once again: The python code runs perfectly fine without virtualenv! But inside virtualenv, I can't get it to work.

I'm using Anaconda Python 2.7 on a Mac.

I'd appreciate any help guys!

2
  • stackoverflow.com/a/25435087/3103677 Did you look at this? Commented May 20, 2016 at 19:31
  • Thanks for the hint, as I wrote above, it didn't work, though in the virtualenv. Commented May 20, 2016 at 20:18

2 Answers 2

18

I had the same error and stumbled upon this link, after searching for the incompatible library error "libxml2.2.dylib provides version 10.0.0"

Installing libxml2 that worked for me:

brew install libxml2 brew link --force libxml2 
Sign up to request clarification or add additional context in comments.

1 Comment

I also had to force the install: brew install --force libxml2
0

Solution that works for me in virtual environment is to force pip to recompile lxml:

pip install lxml --force-reinstall --ignore-installed --no-binary :all: 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.