gmpy2 installs but can't find libmpc.so.3 - python

I want to use gmpy2 with python 2.7 but when I try to import it I get:
>>> import gmpy2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: libmpc.so.3: cannot open shared object file: No such file or directory
I installed gmpy2 using pip: pip install -user gmpy2 and the install looks ok apart from saying
Could not find .egg-info directory in install record for gmpy2
but after that it says that the install was a success.
I have installed MPC (1.0.3), GMP (6.1.1) and MPFR (3.1.4) and they all work, by which I mean I can call gcc foo.c -lmpc and gcc bar.c -lmpfr and the code compiles and works as expected. I've also got gmpy working using pip install. I think the problem will be to do with them not being installed in the default directories as I don't have sudo rights.
The directory where libmpc.so.3 is located is in the gcc call that pip spits out, I've also set CPATH and CPPFLAGS to look in my_prefix/include and LDFLAGS to look my_prefix/lib.
I don't really want to use the functionality from MPC so if there's a simple option to not install that part of gmpy2 I'd be happy with that.
I'm really confused, I've had it that pip fails to build a library and I've gone away and installed dependencies but normally once a library is passed pip it works.

I maintain gmpy2 and there are a couple of command line options that can be passed to setup.py that may help. I can't test the pip syntax right now but here are some options:
--shared=/path/to/gmp,mpfr,mpc will configure gmpy2 to load the libraries from the specified directory.
--static or --static=/path/to/gmp,mpfr,mpc will create a statically linked version of gmpy2 if the proper libraries can be found.
You can also try a build using setup.py directly. It may produce better error messages. Again, untested command:
python setup.py build_ext --static=/path/to/gmp,mpfr,mpc should compile a standalone, staticly linked gmpy2.so which will need to moved to the appropriate location.
Update
I've been able to test the options to pip.
If you are trying to use versions of GMP, MPFR, and MPC that are not those provided by the Linux distribution, you will need to specify the location of the new files to the underlying setup.py that is called by pip. For example, I have updated versions installed locally in /home/case/local. The following command will configure gmpy2 to use those versions:
pip install --install-option="--shared=/home/case/local" --user gmpy2
To compile a statically linked version (for example, to simplify distribution to other systems in cluster), you should use the following:
pip install --install-option="--static=/home/case/local" --user gmpy2
setup.py will use the specified base directory to configure the correct INCLUDE path (/home/case/local/include) and runtime library path (/home/case/local/lib).

Try to do the following as it might me fixed in an older version:
pip install --upgrade setuptools pip
pip uninstall gmpy2
pip install gmpy2

Related

Python error message "Incompatible library version" libxml and etree.so

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!
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
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:

Error when importing python igraph in OSX 10.10.5 by anaconda (libxml2.2.dylib)

I installed the python igraph library for anaconda following the directions in this thread installing python igraph, So the C core library and the python package were successfully installed. However, when I tried to import the igraph library in python, I am getting the following error
>>> import igraph
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/user/anaconda/lib/python2.7/site-packages/igraph/__init__.py", line 34, in <module>
from igraph._igraph import *
ImportError: dlopen(/Users/user/anaconda/lib/python2.7/site-packages/igraph/_igraph.so, 2): Library not loaded: libxml2.2.dylib
Referenced from: /Users/user/anaconda/lib/python2.7/site-packages/igraph/_igraph.so
Reason: Incompatible library version: _igraph.so requires version 12.0.0 or later, but libxml2.2.dylib provides version 10.0.0
Looking for similar threads, I found a similar issue here Installation of python igraph with lxml problem. However, there is not a clear way on how to solve this issue. Does anyone know how to fix it? Thanks in advance.
Anaconda Python is weird - it ships with its own version of libxml2 and when you run pip install python-igraph, igraph is probably linked against it. However, when you try to import igraph, the linker finds the system-wide libxml2, which has a lower ABI version, so that's why you see the error message.
The workaround for this is to ensure that during the compilation stage, Anaconda Python's libxml2 is not picked up by the compiler. setup.py in the Python interface of igraph actually contains this workaround - it tries to detect when you are compiling igraph against Anaconda Python on OS X and then it tweaks the environment a bit to ensure that the linker picks up the right version of libxml2. However, this workaround is enabled only if you do not have the C core of igraph installed on your machine - the installer will download the C core, tweak the environment to work around Anaconda Python, then compile the C core and the Python interface together in one single step.
So, the solution is probably one of the following:
Move Anaconda Python's libxml2 out of the way (or maybe rename xml2-config from Anaconda Python's distribution temporarily), then compile and install the C core from Homebrew. (Use brew unlink igraph, brew uninstall igraph, brew install igraph to be on the safe side). Then you can run pip install python-igraph.
Remove Homebrew's igraph entirely and just run pip install python-igraph - it will download the C core, perform the necessary tweaks and then compile everything.
I had exactly the same issue and installing/force linking libxml2 worked for me:
brew install libxml2
brew link --force libxml2
Others also report the same solution and it appears to be working.

ImportError: cannot import name wraps

I'm using python 2.7.6 on Ubuntu 14.04.2 LTS. I'm using mock to mock some unittests and noticing when I import mock it fails importing wraps.
Not sure if there's a different version of mock or six I should be using for it's import to work? Couldn't find any relevant answers and I'm not using virtual environments.
mock module says it's compatible with python 2.7.x: https://pypi.python.org/pypi/mock
mock==1.1.3
six==1.9.0
Python 2.7.6 (default, Mar 22 2014, 22:59:56)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from mock import Mock
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/mock/__init__.py", line 2, in <module>
import mock.mock as _mock
File "/usr/local/lib/python2.7/dist-packages/mock/mock.py", line 68, in <module>
from six import wraps
ImportError: cannot import name wraps
also tried with sudo with no luck.
$ sudo python -c 'from six import wraps'
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: cannot import name wraps
Installed mock==1.0.1 and that worked for some reason. (shrugs)
edit: The real fix for me was to updated setuptools to the latest and it allowed me to upgrade mock and six to the latest. I was on setuptools 3.3. In my case I also had to remove said modules by hand because they were owned by OS in '/usr/local/lib/python2.7/dist-packages/'
check versions of everything
pip freeze | grep -e six -e mock
easy_install --version
Update everything
wget https://bootstrap.pypa.io/ez_setup.py -O - | sudo python
pip install mock --upgrade
pip install six --upgrade
Thanks #lifeless
I encountered the same issue on my mac, which I was able to fix by realizing that my python's sys.path contained both
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/
and
/Library/Python/2.7/site-packages/
with the former earlier than the latter.
You can test if this is happening to you by running the following in the python console.
import six
six.__version__
my python was loading an outdated six.py from the former directory (which didn't have wrapper), even though pip had installed a newer version six in the second directory. (It seems mac's framework comes with a version of six by default.)
I was able to fix it by moving six.py and six.pyc out of the first directory (requires sudo access), so that python would find the newer version of six in the second directory. I'm sure you could also change the ordering of the paths in sys.path.
To find the older version of six that need to be deleted run this from the terminal console
find /System/Library/Frameworks/Python.framework/Versions -name six.py*
so mock 1.1.1 and above defines a versioned requirement on six 1.7 or above:
https://github.com/testing-cabal/mock/blob/master/requirements.txt#L6
This gets reflected into setuptools metadata by pbr, which there is a versioned setup_requires dependency on:
https://github.com/testing-cabal/mock/blob/master/setup.py#L17
So there are a couple of possibilities:
1) six 1.7 is not new enough
2) there's a distro six package claiming to be 1.9.0 that doesn't have wraps for some reason
3) the setuptools in use didn't integrate properly with pbr and deps are missing
4) the wheel metadata isn't being interrogated properly by your pip/setuptools combination.
We do have a hard requirement for setuptools 17.1, and that was only explicitly reported by setup.py more recently. I'd love it if you can figure which of these is the case and update https://github.com/testing-cabal/mock/issues/298 so that we can fix whatever interaction is leading to this silent failure of setup.py / wheels.
On Mac OSX, the previously installed version of six was blocking my upgraded version from being used. I verified this, as previously suggested by running the following in my interpreter:
import six
six.__version__
To fix this I moved the file:
mv/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/six.py
/tmp/old_six.py
This is stated already in another answer on this site, but I wanted to provide a more streamlined response.
I originally had an issue with old "OS-owned" versions of and pip/setuptools. After I installed pip manually, like so:
wget https://bootstrap.pypa.io/get-pip.py
sudo python get-pip.py
sudo ln -s /usr/local/bin/pip /usr/bin/pip
And then installing the latest version of pip, mock and six, I still had the problem you've described above. Turns out that I had six installed twice in:
/usr/lib/python2.7/dist-packages/
and in
/usr/local/lib/python2.7/dist-packages/
After I removed the six from /usr/lib/ it worked fine:
rm /usr/lib/python2.7/dist-packages/*six*
I did a pip install of six==1.9.0 and it took the new version. It seems like mock==1.3.0 doesn't properly define the version of six that it needs to get wraps support.
Another solution is setting your PYTHONPATH environment variable to point to the installed packages.
Setting my environment variable in my bash config so that:
PYTHONPATH=/Library/Python/2.7/site-packages
Allowed me to run tests in terminal (without removing/renaming any libraries, etc).
However, when using PyCharm, it was less-than-helpfully not correctly importing this environment variable. Even though PyCharm was showing as including parent variables (with that listed in the ones it showed importing), it seems this import wasn't working correctly.
Manually setting the environment variable to the above in the PyCharm run configuration resolves this.
I am unsure if PyCharm overwrites the PYTHONPATH variable after importing it from system environment variables or some other trickery, but this did resolve the error for me.
Though you aren't using a virtual environment like virtualenv, it's certainly a great use case for it. By sandboxing your Python installation and all the dependencies for your project, you can avoid hacking away at the global/default python installation entirely, which is where a lot of the complexity/difficulty comes from.
This is what I used when I got the wraps error - requirements.txt contains mock==2.0.0 and six==1.10.0:
cd <my_project>
virtualenv venv
source venv/bin/activate
sudo pip install -r requirements.txt
Not only is this simpler to use in my opinion, it's also simpler to document for people who might want to run your code.
I found a interesting things!
There is a file named "functools.py" in my project root path, and while I run my project , pycharm will raise ImportError.
So I rename my file fix this problem~~

h5py gives error after installation [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Installing h5py on OS X
I am trying to get h5py to work on my OS X Lion 10.7.3 Macbook Pro. It has worked before but somehow it got uninstalled and I can't get it installed again. It seems it has to do with installing XCode 4.3, but I'm not sure.
When importing h5py, I get the following error:
>>> import h5py
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Python/2.7/site-packages/h5py/__init__.py", line 1, in <module>
from h5py import _errors
ImportError: dlopen(/Library/Python/2.7/site-packages/h5py/_errors.so, 2): Symbol not found: _H5E_ALREADYEXISTS_g
Referenced from: /Library/Python/2.7/site-packages/h5py/_errors.so
Expected in: flat namespace
in /Library/Python/2.7/site-packages/h5py/_errors.so
I guess it has something to do with the HDF5-library. It was not yet installed, so I installed it first using
brew install hdf5
This gave no errors. But the following warning at the end. which I guess is important:
ld: warning: ignoring file ../hdf5-1.8.8/hdf5/lib/libhdf5.a,
file was built for archive which is not the architecture being linked (i386)
I'm not 100% sure what this means, but I guess this library is compiled for an i386 architecture, there however more files in this directory it does not complain about:
libhdf5.la
libhdf5.dylib -> libhdf5.7.dylib
libhdf5.7.dylib
libhdf5.settings
libhdf5.a
libhdf5_hl.la
libhdf5_hl.dylib -> libhdf5_hl.7.dylib
libhdf5_hl.a
libhdf5_hl.7.dylib
Later I also compiled the source myself, downloaded from the HDF5 group-website (http://www.hdfgroup.org/HDF5/). Using the following configure-line, to make sure it makes shared libraries I added --enable-shared and disabled fortran:
./configure --with-zlib=/usr/local --disable-fortran
--prefix=/usr/local/ --target=x86_64-apple-darwin
-build=x86_64-apple-darwin --host=x86_64-apple-darwin
--enable-shared --disable-production
I have removed both h5py and the hdf5 library and reinstalled them a few times (both compiling h5py myself, as using pip and easy_install), but that did not seem to help.
I also installed h5py using the build I just made using this command:
python setup.py build --hdf5=../hdf5-1.8.8/hdf5
I also updated my numpy and scipy installations to the latest versions.
From a clean install of Mac OS X Lion, what I had to do is the following:
Install Xcode with the command-line tools
Install Homebrew
Tell Homebrew where Xcode is (xcode-select ...)
Then I could:
$ brew install hdf5
It didn't link properly, because my /usr/local/lib wasn't writable. Check brew doctor to see if there are any unlinked packages:
$ brew doctor
Warning: You have unlinked kegs in your Cellar
Leaving kegs unlinked can lead to build-trouble and cause brews that depend on
those kegs to fail to run properly once built.
hdf5
szip
So I made the dir writable and used
$ brew link hdf5
$ brew link szip
Then I could do
$ sudo pip install h5py
And presto.
>>> import h5py
>>>

setuptools easyinstall mysql-python-1.2.3

I have read a bunch of threads on setuptools here.
A lot of people seem not to like it very much.
But I need to install MySQL-python-1.2.3. and when I do that I get this error:
MySQL-python-1.2.3 X$ python setup.py cleanTraceback (most recent call last):
File "setup.py", line 5, in <module>
from setuptools import setup, Extension
ImportError: No module named setuptools
So it seems I need setuptools and that it is assumed that it is installed.
On the setuptools python homepage it says:
Setuptools will install itself using the matching version of Python (e.g. python2.4), and will place the easy_install executable in the default location for installing Python scripts (as determined by the standard distutils configuration files, or by the Python installation).
Does this mean it will replace any default easy install from python?
If so I dont want to use it.
If so can I install MySQL-python-1.2.3 without setupttools?
Thanks
You should use virtualenv and pip.
Virtualenv automatically creates a setuptools version within the new environment, so the default one is intact.
You may want to read how the packaging and installing works: 1, 2

Categories

Resources