Psycopg2 fails to install on python 3 with pip issuing a fatal error - pip

$ yum install python3 postgresql python-devel libpqxx-devel
Loaded plugins: langpacks, refresh-packagekit
Package python3-3.3.2-8.fc20.x86_64 already installed and latest version
Package postgresql-9.3.2-2.fc20.x86_64 already installed and latest version
Package python-devel-2.7.5-9.fc20.x86_64 already installed and latest version
Package 1:libpqxx-devel-3.2-0.5.fc20.x86_64 already installed and latest version
Nothing to do
I am trying to install psycopg2 in my virtualenv to connect django with the postgresql database.
In Fedora 19 and postgresql-9.2 the path to pg_config was:
/usr/pgsql-9.2/bin
In Fedora 20, this directory does not exist.
However pg_config can be found in /usr/bin/pg_config.
Trying to install psycopg2:
$ export PATH=$PATH:/usr/bin; pip install psycopg2
Downloading/unpacking psycopg2
Downloading psycopg2-2.5.2.tar.gz (685kB): 685kB downloaded
Running setup.py egg_info for package psycopg2
... -compiling output here- ...
gcc -pthread -Wno-unused-result -DDYNAMIC_ANNOTATIONS_ENABLED=1 -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -DPSYCOPG_DEFAULT_PYDATETIME=1 -DPSYCOPG_VERSION="2.5.2 (dt dec pq3 ext)" -DPG_VERSION_HEX=0x090302 -DPSYCOPG_EXTENSIONS=1 -DPSYCOPG_NEW_BOOLEAN=1 -DHAVE_PQFREEMEM=1 -I/usr/include/python3.3m -I. -I/usr/include -I/usr/include/pgsql/server -c psycopg/psycopgmodule.c -o build/temp.linux-x86_64-3.3/psycopg/psycopgmodule.o -Wdeclaration-after-statement
In file included from psycopg/psycopgmodule.c:27:0:
./psycopg/psycopg.h:30:20: fatal error: Python.h: No such file or directory
#include <Python.h>
^
compilation terminated.
error: command 'gcc' failed with exit status 1
----------------------------------------
Cleaning up...
Command /home/flyer/.virtualenvs/p3test/bin/python3 -c "import setuptools;__file__='/home/flyer/.virtualenvs/p3test/build/psycopg2/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-mrsky4-record/install-record.txt --single-version-externally-managed --install-headers /home/flyer/.virtualenvs/p3test/include/site/python3.3 failed with error code 1 in /home/flyer/.virtualenvs/p3test/build/psycopg2
Storing complete log in /home/flyer/.pip/pip.log
I would appreciate your help.

You are missing python3 include files
./psycopg/psycopg.h:30:20: fatal error: Python.h: No such file or directory
you can probably find them in the python3-devel package.

Install the python3-devel package to get it work
sudo dnf install python3-devel
If it works then alright or if it requires libpq-fe.h file then install it using the command:
sudo dnf install postgresql-devel

On Ubuntu. I solved this with:
sudo apt-get install libpq-dev

As indicated in the other answers this is caused by not having the right Python "devel" package installed. On CentOS, the Python "devel" rpm package is numbered with the with the qualified version. For example as of this writing the current versions are:
python34-devel for epel repository
python36u-devel for ius repository
Example Yum command (assumes EPEL repository is configured):
sudo yum install python34-devel
Related answer from server fault: https://serverfault.com/questions/710354/repository-for-python3-devel-on-centos-7

Related

How to deal with "clang: error: unsupported option '-fopenmp'" on travis?

I am currently trying to deploy a project using openmp. I have the flag '-fopenmp' on Travis.
How could I fix that ?
In local I just brew install libopenmp which solved the issue. But not on Travis, what are the options ?
Using cython I got the following ".travis.yml"
os: linux
dist: xenial
language: python
python:
- "3.7"
cache: pip
addons:
apt:
packages:
- patchelf
matrix:
include:
- os: osx
# No version of Python is available via virtualenv on OS X workers, see https://github.com/travis-ci/travis-ci/issues/2312
language: generic
env: TOXENV=py37
fast_finish: true
before_install:
brew install libomp
install:
- pip install --upgrade "pip < 19.1" -r CI/requirements.txt
- python setup.py develop
script:
- pytest
Travis fails while executing :
clang -fno-strict-aliasing -fno-common -dynamic -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/usr/local/include -I/usr/local/opt/openssl#1.1/include -I/usr/local/opt/sqlite/include -I/usr/local/Cellar/python#2/2.7.17/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c cpt/alphabet.c -o build/temp.macosx-10.13-x86_64-2.7/cpt/alphabet.o -fopenmp
While in local it compiles with python 3.7, how could I fix that aswell ?
On apple's llvm, -fopenmp is not supported. One should use brew's llvm.
The following ables to link openmp:
- brew install llvm libomp
- export CPP=/usr/local/opt/llvm/bin/clang;
For reference, the issue where there are all the commands: https://github.com/bluesheeptoken/CPT/issues/68#issuecomment-563342866

Failed to install gem rest-client

I am trying to install gem res-client in my redhat linux server.Installed whatever dependencies i found but still not working for me.
Ruby Version:
ruby 2.3.6p384 (2017-12-14 revision 61254) [x86_64-linux]
[root#feeds ]# gem install rest-client
Building native extensions. This could take a while...
ERROR: Error installing rest-client:
ERROR: Failed to build gem native extension.
current directory: /opt/rh/rh-ruby23/root/usr/local/share/gems/gems/unf_ext-0.0.7.6/ext/unf_ext
/opt/rh/rh-ruby23/root/usr/bin/ruby -I /opt/rh/rh-ruby23/root/usr/local/share/ruby/site_ruby -r ./siteconf20190429-62674-e4of20.rb extconf.rb
checking for main() in -lstdc++... no
creating Makefile
current directory: /opt/rh/rh-ruby23/root/usr/local/share/gems/gems/unf_ext-
0.0.7.6/ext/unf_ext
make "DESTDIR=" clean
rm -f
rm -f unf_ext.so *.o .bak mkmf.log ..time
current directory: /opt/rh/rh-ruby23/root/usr/local/share/gems/gems/unf_ext-0.0.7.6/ext/unf_ext
make "DESTDIR="
g++ -I. -I/opt/rh/rh-ruby23/root/usr/include -I/opt/rh/rh-ruby23/root/usr/include/ruby/backward -I/opt/rh/rh-ruby23/root/usr/include -I. -fPIC -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -mtune=generic -m64 -o unf.o -c unf.cc
make: g++: Command not found
make: *** [unf.o] Error 127
make failed, exit code 2
Gem files will remain installed in /opt/rh/rh-ruby23/root/usr/local/share/gems/gems/unf_ext-0.0.7.6 for inspection.
Results logged to /opt/rh/rh-ruby23/root/usr/local/lib64/gems/ruby/unf_ext-0.0.7.6/gem_make.out
Can anyone please suggest.
Thanks
Sina
It looks like you are missing the gcc-c++ compiler. Install it with:
yum install gcc-c++
build-essential g++ are the missing ones. So try installing:
yum install build-essential g++
then install the required gem:
gem install rest-client
hope it helps....
Thanks .
I reinstall ruby and dependencies then it worked.
Regards,
Sina

Unable to install sasl on cloudera centos linux vm for connecting to hive from python

I want to connect to Hive data warehouse from python. I am trying to install sasl (version 0.2.1) on my Cloudera VM (centos 6.7) using below command:
$sudo pip install sasl
I got below error message:
Collecting sasl
Using cached sasl-0.2.1.tar.gz
Requirement already satisfied: six in ./anaconda3/lib/python3.5/site-packages (f
rom sasl)
Building wheels for collected packages: sasl
Running setup.py bdist_wheel for sasl: started
Running setup.py bdist_wheel for sasl: finished with status 'error'
Complete output from command /home/cloudera/anaconda3/bin/python -u -c "import
setuptools, tokenize;__file__='/tmp/pip-build-cu3nu05u/sasl/setup.py';f=getattr
(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close()
;exec(compile(code, __file__, 'exec'))" bdist_wheel -d /tmp/tmpz1j86agrpip-wheel
....
building 'sasl.saslwrapper' extension
creating build/temp.linux-x86_64-3.5
creating build/temp.linux-x86_64-3.5/sasl
gcc -pthread -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -
Wstrict-prototypes -fPIC -Isasl -I/home/cloudera/anaconda3/include/python3.5m -c
sasl/saslwrapper.cpp -o build/temp.linux-x86_64-3.5/sasl/saslwrapper.o
cc1plus: warning: command line option "-Wstrict-prototypes" is valid for Ada/C
/ObjC but not for C++
In file included from sasl/saslwrapper.cpp:254:
sasl/saslwrapper.h:22:23: error: sasl/sasl.h: No such file or directory
In file included from sasl/saslwrapper.cpp:254:
sasl/saslwrapper.h:145: error: ‘sasl_interact_t’ has not been declared
sasl/saslwrapper.h:148: error: ‘sasl_conn_t’ has not been declared
...
----------------------------------------
Running setup.py clean for sasl
Failed to build sasl
Installing collected packages: sasl
Running setup.py install for sasl: started
Running setup.py install for sasl: finished with status 'error'
Anyone know why sasl can not be installed on Cloudera centos 6.7?
Thanks,
ds2000
You need to install cyrus-sasl-devel too.
This is what I had to add:
# yum install python-pip gcc gcc-c++ python-virtualenv cyrus-sasl-devel
After that, pip install sasl worked.

Debian 7.4 - LXML compilation failed with Python 3.4.0

I've just installed Debian 7.4 on my PC. I need python 3.3.2 or higher AND python3-lxml for my inner developments. As python 3.2 is the base line for the python3.x series in debian wheezy Ive' compiled a 3.4.0 python version and uninstalled the old 3.2. (note that the process also un-installed some gnome dependencies).
After that work Python3 packages (cherrypy for example) install fine and modules can be successfully imported inside the interpreter.
When trying to install python3-lxml , the system needs to install the lxml repository dependencies python3.2 ... that I just don't want to.
So I decided to compile lxml over python 3.4.0.
Dependencies installed :
* libxml2 >= 2.7.8
* libxml2-dev
* libxslt1= >= 1.1.26
* libxslt1-dev
sudo apt-get install libxml2 libxml2-dev libxslt1 libxslt1-dev
I think that only the *-dev packages are required, aren't they ?
The problem is that I faced this issue while compiling in the source directory :
jeby6372#mercure:~/Pack/lxml-3.3.4$ sudo python3 setup.py build
Building lxml version 3.3.4.
Building without Cython.
Using build configuration of libxslt 1.1.26
Building against libxml2/libxslt in the following directory: /usr/lib
/opt/python-3.4.0/lib/python3.4/distutils/dist.py:260: UserWarning: Unknown distribution option: 'bugtrack_url'
warnings.warn(msg)
running build
running build_py
copying src/lxml/includes/lxml-version.h -> build/lib.linux-x86_64-3.4/lxml/includes
running build_ext
building 'lxml.etree' extension
gcc -pthread -Wno-unused-result -Werror=declaration-after-statement -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/usr/include/libxml2 -I/home/jeby6372/Pack/lxml-3.3.4/src/lxml/includes -I/opt/python-3.4.0/include/python3.4m -c src/lxml/lxml.etree.c -o build/temp.linux-x86_64-3.4/src/lxml/lxml.etree.o -w
gcc -pthread -shared build/temp.linux-x86_64-3.4/src/lxml/lxml.etree.o -L/usr/lib -lxslt -lexslt -lxml2 -lz -lm -o build/lib.linux-x86_64-3.4/lxml/etree.cpython-34m.so
/usr/bin/ld: cannot find -lz
collect2: error: ld returned 1 exit status
error: command 'gcc' failed with exit status 1
the -lz option is not recognized by the gcc. For information i've install the tool chain with :
sudo apt-get install build-essential
Any idea ?
In advance thanks for your help.
The linker can't find libz when trying to compile the python c-extension. I believe you need the zlib dev package on Debian. Try apt-get install zlib1g-dev and then try and rebuild.
You're right Photoionized,
while installing another package (setuptools) it claims for the zlib python module that must be set at compile time. Don't now why but I thought it was a similar problem as the unknown -lz option that sounds like Library Zlib ?
So I installed the zlib1g librairy and its sources , compile again the python-3.4.0 with the --with-zlib option.
./compile --prefix=opt/python-3.4.0 --with-zlib
make
sudo make install
then create a new link to the command
sudo rm /usr/bin/python3 && ln -s /usr/bin/python3 /opt/python-3.4.0/bin/python3.4m
After that the installation ended succesfully in the lxml source directory
sudo python3 setup.py install
Thanks again for your answer

How to install Nokogiri as a Macruby gem?

The latest MacRuby release notes (v0.6) state that the authors have managed to get this release working with the SQLite and Nokogiri gems. However when I run sudo macgem install nokogiri I get the following errors:
ERROR: Error installing nokogiri:
extconf failed:
and then a bunch of paths followed by:
libxml2 is missing. try 'port install libxml2' or 'yum install libxml2'
/Library/Frameworks/MacRuby.framework/Versions/0.6/usr/lib/ruby/Gems/1.9.0/gems/nokogiri-1.4.1/ext/nokogiri/extconf.rb:1:in `<main>': libxml2 is missing. try 'port install libxml2' or 'yum install libxml2' (SystemExit)
Anyone knows how to get this working? My platform is Mac OS X 10.6.3. Nokogiri normally (meaining on plain old ruby 1.8.7) installs without a problem.
Progress
OK, so I have:
git clone http://github.com/tenderlove/nokogiri.git
cd nokogiri/ext/nokogiri
Then I've rebuilt the macports libraries with sudo port upgrade --enforce-variants libxml2 +universal and sudo port upgrade --enforce-variants libxslt +universal
Then I've executed macruby extconf.rb successfully
Then I proceed to make
At this point it errors out like so:
/usr/bin/gcc -I. -I/opt/local/include/libxml2 -I/opt/local/include/ -I/Library/Frameworks/MacRuby.framework/Versions/0.6/usr/include/ruby-1.9.0/universal-darwin10.0 -I/Library/Frameworks/MacRuby.framework/Versions/0.6/usr/include/ruby-1.9.0/ruby/backward -I/Library/Frameworks/MacRuby.framework/Versions/0.6/usr/include/ruby-1.9.0 -I. -DHAVE_XMLRELAXNGSETPARSERSTRUCTUREDERRORS -DHAVE_XMLRELAXNGSETPARSERSTRUCTUREDERRORS -DHAVE_XMLRELAXNGSETVALIDSTRUCTUREDERRORS -DHAVE_XMLSCHEMASETVALIDSTRUCTUREDERRORS -DHAVE_XMLSCHEMASETPARSERSTRUCTUREDERRORS -I/opt/local/include/ -I/opt/local/include/libxml2 -I/opt/local/include -fno-common -fexceptions -fno-common -pipe -O3 -g -Wall -Wno-parentheses -g -DXP_UNIX -O3 -Wall -Wcast-qual -Wwrite-strings -Wconversion -Wmissing-noreturn -Winline -arch i386 -arch x86_64 -o html_document.o -c html_document.c
In file included from ./html_document.h:4,
from html_document.c:1:
./nokogiri.h:35:16: error: st.h: No such file or directory
In file included from ./html_document.h:4,
from html_document.c:1:
./nokogiri.h:35:16: error: st.h: No such file or directory
lipo: can't open input file: /var/folders/wU/wUGgoG1JGeKBgwalWLPMAU+++TI/-Tmp-//ccSgAUv5.out (No such file or directory)
make: *** [html_document.o] Error 1
I think you have to build from source since only Nokogiri's head is MacRuby compliant
If you use the source code of GitHub,
$ git clone git://github.com/tenderlove/nokogiri.git
$ cd nokogiri/ext/nokogiri/
$ sed -i.bak 's/<st.h>/<ruby\/st.h>/' nokogiri.h
If you make a gem package of Nokogiri,
$ cd ../..
$ sudo gem install hoe
$ sudo gem install rake-compiler
$ sudo gem install racc
$ sudo gem install rexical
$ mkdir ~/.rubyforge; touch ~/.rubyforge/user-config.yml
$ rake gem
An Above command, I used ruby of the system default. ("/usr/bin/ruby")
$ cd pkg
$ sudo macgem install nokogiri-1.4.1.gem
I think you have to build a libxml2 as Universal binary.
If you use MacPorts, execute the command below.
$ sudo port upgrade --enforce-variants libxml2 +universal
$ sudo port upgrade --enforce-variants libxslt +universal
$ sudo port upgrade --enforce-variants sqlite3 +universal
It still fails in the installation (x _ x;
$ sudo macgem install nokogiri
Building native extensions. This could take a while...
ERROR: Error installing nokogiri:
make failed:
["/Library/Frameworks/MacRuby.framework/Versions/0.6/usr/bin/macruby extconf.rb", "checking for iconv.h in /opt/local/include/,/opt/local/include/libxml2,/opt/local/include,/opt/local/include,/opt/local/include/libxml2,/usr/local/include,/usr/local/include/libxml2,/Library/Frameworks/MacRuby.framework/Versions/0.6/usr/include,/Library/Frameworks/MacRuby.framework/Versions/0.6/usr/include/libxml2,/usr/include,/usr/include/libxml2... yes\nchecking for libxml/parser.h in /opt/local/include/,/opt/local/include/libxml2,/opt/local/include,/opt/local/include,/opt/local/include/libxml2,/usr/local/include,/usr/local/include/libxml2,/Library/Frameworks/MacRuby.framework/Versions/0.6/usr/include,/Library/Frameworks/MacRuby.framework/Versions/0.6/usr/include/libxml2,/usr/include,/usr/include/libxml2... yes\nchecking for libxslt/xslt.h in /opt/local/include/,/opt/local/include/libxml2,/opt/local/include,/opt/local/include,/opt/local/include/libxml2,/usr/local/include,/usr/local/include/libxml2,/Library/Frameworks/MacRuby.framework/Versions/0.6/usr/include,/Library/Frameworks/MacRuby.framework/Versions/0.6/usr/include/libxml2,/usr/include,/usr/include/libxml2... yes\nchecking for libexslt/exslt.h in /opt/local/include/,/opt/local/include/libxml2,/opt/local/include,/opt/local/include,/opt/local/include/libxml2,/usr/local/include,/usr/local/include/libxml2,/Library/Frameworks/MacRuby.framework/Versions/0.6/usr/include,/Library/Frameworks/MacRuby.framework/Versions/0.6/usr/include/libxml2,/usr/include,/usr/include/libxml2... yes\nchecking for xmlParseDoc() in -lxml2... yes\nchecking for xsltParseStylesheetDoc() in -lxslt... yes\nchecking for exsltFuncRegister() in -lexslt... yes\nchecking for xmlRelaxNGSetParserStructuredErrors()... yes\nchecking for xmlRelaxNGSetParserStructuredErrors()... yes\nchecking for xmlRelaxNGSetValidStructuredErrors()... yes\nchecking for xmlSchemaSetValidStructuredErrors()... yes\nchecking for xmlSchemaSetParserStructuredErrors()... yes\ncreating Makefile\n", "make", "/usr/bin/gcc -I. -I/opt/local/include/libxml2 -I/opt/local/include/ -I/Library/Frameworks/MacRuby.framework/Versions/0.6/usr/include/ruby-1.9.0/universal-darwin10.0 -I/Library/Frameworks/MacRuby.framework/Versions/0.6/usr/include/ruby-1.9.0/ruby/backward -I/Library/Frameworks/MacRuby.framework/Versions/0.6/usr/include/ruby-1.9.0 -I. -DHAVE_XMLRELAXNGSETPARSERSTRUCTUREDERRORS -DHAVE_XMLRELAXNGSETPARSERSTRUCTUREDERRORS -DHAVE_XMLRELAXNGSETVALIDSTRUCTUREDERRORS -DHAVE_XMLSCHEMASETVALIDSTRUCTUREDERRORS -DHAVE_XMLSCHEMASETPARSERSTRUCTUREDERRORS -I/opt/local/include/ -I/opt/local/include/libxml2 -I/opt/local/include -fno-common -fexceptions -fno-common -pipe -O3 -g -Wall -Wno-parentheses -g -DXP_UNIX -O3 -Wall -Wcast-qual -Wwrite-strings -Wconversion -Wmissing-noreturn -Winline -arch i386 -arch x86_64 -o html_document.o -c html_document.c\nIn file included from ./nokogiri.h:75,\n from ./html_document.h:4,\n from html_document.c:1:\n./xml_document.h:5:16: error: st.h: No such file or directory\nIn file included from ./nokogiri.h:75,\n from ./html_document.h:4,\n from html_document.c:1:\n./xml_document.h:5:16: error: st.h: No such file or directory\nlipo: can't open input file: /var/tmp//cco5nNYw.out (No such file or directory)\nmake: *** [html_document.o] Error 1\n"]
I uploaded to GitHub which I made a package.
http://wiki.github.com/Watson1978/nokogiri-macruby/

Resources