I am trying to install the python library pyinterval. It requires the crlibm C headers which I have installed without error, but seem to be at the root of the problem.
When I run:
$ sudo easy_install pyinterval
I get the following:
Searching for pyinterval
Reading http://pypi.python.org/simple/pyinterval/
Reading http://pyinterval.googlecode.com/
Best match: pyinterval 1.0b21
Downloading http://pypi.python.org/packages/source/p/pyinterval/pyinterval-1.0b21.tar.gz#md5=a65fe9855d3b6b0a9ddcc5b2f1e1e421
Processing pyinterval-1.0b21.tar.gz
Running pyinterval-1.0b21/setup.py -q bdist_egg --dist-dir /tmp/easy_install-K58WK9/pyinterval-1.0b21/egg-dist-tmp-Tp03Mb
ext/crlibmmodule.c: In function ‘crlibm_cospi_rn’:
ext/crlibmmodule.c:45:1: warning: implicit declaration of function ‘cospi_rn’
ext/crlibmmodule.c: In function ‘crlibm_cospi_ru’:
ext/crlibmmodule.c:45:1: warning: implicit declaration of function ‘cospi_ru’
...
ext/crlibmmodule.c: In function ‘crlibm_log1p_rz’:
ext/crlibmmodule.c:59:1: warning: implicit declaration of function ‘log1p_rz’
/usr/bin/ld: /usr/local/lib/libcrlibm.a(addition_scs.o): relocation R_X86_64_32S against `.rodata' can not be used when making a shared object; recompile with -fPIC
/usr/local/lib/libcrlibm.a: could not read symbols: Bad value
collect2: ld returned 1 exit status
error: Setup script exited with error: command 'gcc' failed with exit status 1
I have called:
$ sudo apt-get install python-all-dev
and that did not fix the problem.
In case anyone still has problems with this, you need to set "CPPFLAGS = -fPIC" in "scs_lib/Makefile", not "./Makefile".
I had been having the same problem, and I found the issue was with crlibm (the flags -fPIC are mentioned in the error).
I ended up installing crlibm from source, and was able to get the the installation working. Once I'd run ./configure for crlibm, I manually edited the Makefile by changing the line "CPPFLAGS = " to "CPPFLAGS = -fPIC". From here I ran "make", "make install", and then "sudo easy_install pyinterval".
I'll add that I'm not 100% confident in this solution, and its not very elegant. I'm not sure about the technical details of the -fPIC flag, and what effect it really has.
But it does work.
It seems to work ok for me:
wget http://lipforge.ens-lyon.fr/frs/download.php/152/crlibm-1.0beta3.tar.gz
tar vfxz crlibm-1.0beta3.tar.gz
cd crlibm-1.0beta3
export CPPFLAGS=-fPIC
./configure
make
sudo make install
sudo pip install pyinterval
python
>>> from interval import *
Thanks for the answer.
I just went through installing pyinterval on ubuntu 12.10 using the above suggestions for crlibm.
I tried adding -fPIC to CPPFLAGS in the scs_lib Makefile but it didn't work. I think later versions of crlibm (I am using 1.0beta-4) require that crlibm_private.o is also compiled with -fPIC so the flag needs to be added to CPPFLAGS in the Makefile of the base directory
Related
I am having trouble installing the python packages PyTransit and ktransit to Anaconda 3 (on Linux). It seems like lots of others have had similar errors, but none of their solutions have worked for me. There's a bunch of stuff going on:
pip install ktransit gives:
/usr/bin/ld: /home/name/anaconda3/lib/libgfortran.a(pause.o): relocation R_X86_64_32 against `.rodata.str1.8' can not be used when making a shared object; recompile with -fPIC
/home/name/anaconda3/lib/libgfortran.a: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
I would try to use ./configure with --enable-shared, but there's no config file. I tried adding extra_compile_args = ["-fPIC"], extra_link_args=["-fPIC"] to setup.py (as in https://github.com/h5py/h5py/issues/851), but that did nothing.
pip install pytransit gives different errors:
#warning "Using deprecated NumPy API, disable it by " \
Warning: src/gimenez.f90:35: Illegal preprocessor directive
Warning: src/gimenez.f90:36: Illegal preprocessor directive
Warning: src/gimenez.f90:37: Illegal preprocessor directive
src/gimenez.f90:271.33:
real(8), dimension(CHUNK_SIZE, npol) :: d
1
Error: Symbol 'chunk_size' at (1) has no IMPLICIT type
Here's where it gets interesting. Using pip3 (or sudo pip) allows ktransit to install successfully, but does nothing for pytransit. Pip and pip3 seem to be tied to different places:
which pip
/home/name/anaconda3/bin/pip
which pip3
/usr/local/bin/pip3
which python
/home/name/anaconda3/bin/python
Lastly, When I try to import ktransit in a jupyter notebook through anaconda, it fails, but when I import ktransit in the Jupyter QtConsole, it succeeds, but seems to contain itself and not provide actual functionality. What I mean is that I can't reference anything within the module, and:
Help on package ktransit:
NAME
ktransit
PACKAGE CONTENTS
ktransit (package)
setup
FILE
(built-in)
I'm thinking that whatever version of python is associated with /usr/bin is somehow messing with me...or maybe there's something wrong with my gcc or libgfortran? I have gcc versions 4.8.5 and 6 (gcc --version gives 4.8.5, but -update-alternatives says there's only one version, 6).
Thanks for taking the time to read this far. I would be very grateful for any suggestions or ideas!
Figured it out -- I uninstalled Anaconda, made sure my python was pointing in the right direction, and then used sudo python -m pip install. Thank you to Nagev for pushing me to get rid of Anaconda!
I'm trying to convert a Python 3 script into C and then compile that C file into an executable.
I have this simple python script:
def greet(name = ""):
print("Hello {0}".format(name if len(name) > 0 else "World"))
greet("Mango")
I've converted this script into C using:
cython greet.py -o greet.c
Then I've compiled the C file using:
cc greet.c -o greet
After I entered the last command I got the error:
fatal error: Python.h: No such file or directory compilation terminated.
After I got the error I went back and realised that I was using Python3 and that I had forgot the "3" after "cython".
So re-compiled the python script using:
cython3 greet.py -o greet.c
Then attempted to re-compile the C file using:
cc greet.c -o greet
Again this failed and threw the same error so I went searching on SO and Google and found these questions:
fatal error: Python.h: No such file or directory
I have Python on my Ubuntu system, but gcc can't find Python.h
https://askubuntu.com/questions/526708/fatal-error-python-h-no-file-or-directory
None of these answers in these questions work.
I've made sure that I have installed cython all of the correct dependencies using apt-get install and pip install sadly thought it still does not seem to work.
Check the documentation. It's not enough to do gcc x.c -o x.
This page explains compilation: http://docs.cython.org/src/reference/compilation.html
There's a lot more to it, but a direct answer is:
Compiling your .c files will vary depending on your operating system. Python documentation for writing extension modules should have some details for your system. Here we give an example on a Linux system:
$ gcc -shared -pthread -fPIC -fwrapv -O2 -Wall -fno-strict-aliasing
-I/usr/include/python2.7 -o yourmod.so yourmod.c
Of course in your situation it's going to be something closer to -I/usr/include/python3.4, or even $(pkg-config --libs --cflags python3). And you're not building with -shared, because you want an executable.
Shortest "this has to work" set of commands is:
cython3 --embed greet.py -o greet.c
gcc $(pkg-config --libs --cflags python3) greet.c -o greet
You need to install pkg-config if it's missing.
As #viraptor's answer shows you and as per my comment, your main problem is that you need to tell your C compiler (e.g. gcc) where to find the python headers required (pyconfig.h and Python.h). To do this, you need to pass a -I option to gcc.
The other answer suggests using pkg-config to add this to your command line. However, like you, with Ubuntu 14.04, cython3 and python3-dev installs, using this method leads the compiled program to exit with a segmentation fault for me.
So, I suggest you go back to basics. After
cython greet.py -o greet.c
Run the following command. It assumes that Python.h and friends are in the standard place (i.e. you've done a standard install of python3-dev)
gcc -I/usr/include/python3.4m -o greet greet.c -lpython3.4m
If that doesn't work - use find / -iname Python.h to find the location of the necessary files and alter the -I path accordingly.
In time, when you want to use cython on more complex programs, such as those that link to other C libraries, you'll need to learn about the other options you need to pass to gcc to get it to compile and link correctly. To get you going, though, the above should work (tested on Ubuntu 14.04 as per your spec)
P.S. I'm not sure why the pkg-config suggestion doesn't work - but for me it seems to add in an extra path to -I which breaks things.
Python 2:
python -m pip install --upgrade cython
Python 3:
python3 -m pip install --upgrade cython
I seem to be one of the many people struggling to install gensim on windows. I have trawled through countless forums but the errors poster there never appear to match my errors. So hopefully someone can point me in the right direction!
I am running Windows Server 2012 R2 Standard 64-bit. I have installed MinGW & Anaconda 2.2.0 (64-bit), which comes with Python 2.7.9.
I have added a file distutils.cfg into C:\Users\Sam\Anaconda\Lib\distutils with the contents:
[build]
compiler=mingw32
I have added C:\MinGW\bin to my Environment variables.
If I install gensim using pip I do not get any errors, until I try to run Word2Vec when I get the error:
C:\Users\sam.passmore\AppData\Local\Continuum\Anaconda\lib\site-packages\gensim\models\word2vec.py:459: UserWarning: C extension com
pilation failed, training will be slow. Install a C compiler and reinstall gensim for fast training.
So I have uninstalled gensim and tried to re-install using the mingw32 compiler, but this gives me this error:
python setup.py build --compiler=mingw32
c:\users\sam.passmore\appdata\local\continuum\anaconda\lib\site-packages\setuptools-14.3-py2.7.egg\setuptools\dist.py:282: UserWarni
ng: Normalizing '0.11.1-1' to '0.11.1.post1'
running build
running build_ext
building 'gensim.models.word2vec_inner' extension
C:\MinGW\bin\gcc.exe -DMS_WIN64 -mdll -O -Wall -Igensim\models -IC:\Users\sam.passmore\AppData\Local\Continuum\Anaconda\include -IC:
\Users\sam.passmore\AppData\Local\Continuum\Anaconda\PC -IC:\Users\sam.passmore\AppData\Local\Continuum\Anaconda\lib\site-packages\n
umpy\core\include -c ./gensim/models/word2vec_inner.c -o build\temp.win-amd64-2.7\Release\.\gensim\models\word2vec_inner.o
gcc: error: ./gensim/models/word2vec_inner.c: No such file or directory
gcc: fatal error: no input files
compilation terminated.
command 'C:\\MinGW\\bin\\gcc.exe' failed with exit status 1
setup.py:82: UserWarning:
********************************************************************
WARNING: %s could not
be compiled. No C extensions are essential for gensim to run,
although they do result in significant speed improvements for some modules.
%s
Here are some hints for popular operating systems:
If you are seeing this message on Linux you probably need to
install GCC and/or the Python development package for your
version of Python.
Debian and Ubuntu users should issue the following command:
$ sudo apt-get install build-essential python-dev
RedHat, CentOS, and Fedora users should issue the following command:
$ sudo yum install gcc python-devel
If you are seeing this message on OSX please read the documentation
here:
http://api.mongodb.org/python/current/installation.html#osx
********************************************************************
The gensim.models.word2vec_inner extension moduleThe output above this warning shows how the compilation failed.
"The output above this warning shows how the compilation failed.")
building 'gensim.models.doc2vec_inner' extension
C:\MinGW\bin\gcc.exe -DMS_WIN64 -mdll -O -Wall -Igensim\models -IC:\Users\sam.passmore\AppData\Local\Continuum\Anaconda\include -IC:
\Users\sam.passmore\AppData\Local\Continuum\Anaconda\PC -IC:\Users\sam.passmore\AppData\Local\Continuum\Anaconda\lib\site-packages\n
umpy\core\include -c ./gensim/models/doc2vec_inner.c -o build\temp.win-amd64-2.7\Release\.\gensim\models\doc2vec_inner.o
gcc: error: ./gensim/models/doc2vec_inner.c: No such file or directory
gcc: fatal error: no input files
compilation terminated.
command 'C:\\MinGW\\bin\\gcc.exe' failed with exit status 1
setup.py:82: UserWarning:
********************************************************************
WARNING: %s could not
be compiled. No C extensions are essential for gensim to run,
although they do result in significant speed improvements for some modules.
%s
Here are some hints for popular operating systems:
If you are seeing this message on Linux you probably need to
install GCC and/or the Python development package for your
version of Python.
Debian and Ubuntu users should issue the following command:
$ sudo apt-get install build-essential python-dev
RedHat, CentOS, and Fedora users should issue the following command:
$ sudo yum install gcc python-devel
If you are seeing this message on OSX please read the documentation
here:
http://api.mongodb.org/python/current/installation.html#osx
********************************************************************
The gensim.models.doc2vec_inner extension moduleThe output above this warning shows how the compilation failed.
"The output above this warning shows how the compilation failed."
I have exhausted all options I can think of or find, so if anyone could give some advice it would be much appreciated.
I managed to solve this after using conda install for gensim, rather than pip.
conda install gensim
I am not sure what other steps I have included above have contributed to the answer, but this was the last thing I did before I no longer was getting the 'Install a C compiler and reinstall gensim for fast training.' message.
During my research in trying to solve this problem I saw that the most common methods were adding the lines
[build]
compiler=mingw32
to the distutils.cfg file as well as ensuring MinGW is in your path. Also ensuring that the MinGW bit version is the same as your python version.
I'd like to start by saying that asking a question here isn't something I do lightly. I've now been attempting to install Pygame 1.9.1 from source for four hours, and I've run into several problems but was able to overcome each one. This is the first one I'm completely stumped on.
After I unpack pygame-1.9.1release.tar.gz and cd to the folder, I run 'python3 setup.py install'
/Library/Frameworks/SDL.framework/Versions/Current/Headers/SDL_syswm.h:58:10: fatal error: 'X11/Xlib.h' file not found
#include <X11/Xlib.h>
1 error generated.
error: command '/usr/bin/clang' failed with exit status 1
After some online research, I read that X11 is no longer included with OSX 10.9, so I installed XQuartz in the hope that it could serve as a replacement.
Xquartz does include 'Xlib.h', but it's filepath is /opt/X11/include/X11/Xlib.h, and the setup script doesn't find it here. I've tried several ways to fix this.
The error process specifically comes up in the build part of the install. I've tried using
python3 setup.py config --include-dirs /opt/X11/include
as well as
python3 setup.py config --include-dirs /opt/X11/include/X11
but get the same error.
I read online that installing the Xcode command line tools could fix this problem. I'm ~95% sure I had the command line tools before, but I tried to get them again anyway with 'xcode-select --install' only to be told that 'Can't install the software because it is currently unavailable from the Software Update server'. "No problem," I tell myself and just download the package from the Mac developers site. It doesn't help anything.
I've also tried symlinking with the command
sudo ln -s /usr/include/X11 /opt/X11/include/X11
Of everything I've tried, I understand this the least, do I could very well be doing the symlink command wrong.
Two other commands I tried are
export C_INCLUDE_PATH=/opt/X11/include
export CPLUS_INCLUDE_PATH=/opt/X11/include
Just looking at the documentation, I came across a debug option for the startup script.
The output of 'python3 setup.py build -g' is
running build
running build_py
running build_ext
building 'pygame.display' extension
/usr/bin/clang -fno-strict-aliasing -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -arch i386 -arch x86_64 -g -g -Ddarwin -I/Library/Frameworks/SDL.framework/Versions/Current/Headers -I/Library/Frameworks/Python.framework/Versions/3.3/include/python3.3m -c src/display.c -o build/temp.macosx-10.6-intel-3.3/src/display.o
In file included from src/display.c:30:
/Library/Frameworks/SDL.framework/Versions/Current/Headers/SDL_syswm.h:58:10: fatal error: 'X11/Xlib.h' file not found
#include <X11/Xlib.h>
^
1 error generated.
error: command '/usr/bin/clang' failed with exit status 1
I'm not sure what else I can do, but I'd really appreciate some help with this. Thanks in advance!
setup.py build|install commands accepts CFLAGS and LDFLAGS compiler options, as far as I know.
Thus here, you can do
CFLAGS=-I/opt/X11/include python3 setup.py install
You probably need the LDFLAGS as well; I'm not sure about the exact location, but something like
CFLAGS=-I/opt/X11/include LDFLAGS=-L/opt/X11/lib python3 setup.py install
seems logical.
After that, you may have to set your DYLD_LIBRARY_PATH to point to your X11 libraries. In case your installation proceeds but your PyGame script won't run and complains about not finding X11 libraries. Thus
export DYLD_LIBRARY_PATH=/opt/X11/lib
As for the symbolic link you tried to create: it's the wrong way 'round: the two paths should have been switched, so I guess you got an error because /opt/X11/include/X11 already exists. But with the above, no symlink is necessary.
I ran into a similar error when trying to install pygame into my PyCharm project's virtualenv. I solved it by cding to the SDL Framework directory where the error originated and copying the X11 header files into it:
$ cd /Library/Frameworks/SDL.framework/Versions/Current/Headers
$ cp -R /opt/X11/include/X11 ./
then $ pip install pygame ran without errors.
I would like to install the ephem package in my Python 3.3.0 version under Windows XP.
I tried first the pip install ephem route from the system command prompt. The process aborted with the error message of Unable to find vcvarsall.bat.
I read prior advice on the net for such a difficulty. Following it I installed mingw32 in my computer, added C:\MinGW\bin to the PATH variable and provided Lib / distutils with a new file called distutils.cfg and the content:
[build]
compiler=mingw32
On running now any of the install commands (pip, *easy_install* and setup.py all work the same) the following error results:
C:\MinGW\bin\gcc.exe -mno-cygwin -mdll -O -Wall -Ilibastro-3.7.5 -IC:\Python33\
include -IC:\Python33\include -c extensions/_libastro.c -o build\temp.win32-3.3\
Release\extensions\_libastro.o
cc1.exe: error: unrecognised command line option '-mno-cygwin'
error: command 'gcc' failed with exit status 1
I have tried to understand and solve the problem, but have been unsuccesful. I have not been able even to find the place in the code where such values are established.
¿Could somebody provide any help? ¿Would ephem be one of the cases alluded by Installing Python modules in the 3.3.0 Documentation with "Not all extensions can be built with MinGW or Cygwin, but many can."?
Thanks in advance
Paco
Here is an extremely useful page of Windows binaries of python packages: http://www.lfd.uci.edu/~gohlke/pythonlibs/.
It includes binaries for pyephem.