In this post, we will see How To Fix “Error: libpq-fe.h: No Such File or Directory”.
There can be various formats of the error depending on the context of use. Couple of those are shown below –
error: libpq-fe.h: No such file or directory
Can't find the 'libpq-fe.h header
psycopg2 fatal error libpq-fe.h no such file or directory
cannot open include file 'libpq-fe.h' no such file or directory
This issue occurs while installing postgresql or psycopg2 if the steps are not followed properly.
if( aicp_can_see_ads() ) {
}
- Did you install pyscopg2 correctly ? Note that – it is a C wrapper around the libpq postgreSQL client library. And hence there are few things that you need to take care of. Follow the below steps if not done already.
To solve the error, use the below –
Option 1 : General Steps
if( aicp_can_see_ads() ) {
}
- Python header files – These are needed for pycopg2. So install these by installing the the package – python-dev or python3-dev as per the python version.
sudo apt-get install python-dev <- for python 2.7 sudo apt-get install python3.5-dev <- python 3.5 sudo apt-get install python3.9-dev <- python 3.9
Note : While doing this step, if you see an error – “Python.h: No such file or directory”, the fix is explained here – How To Fix – fatal error: Python.h: No such file or directory ?
- libpq header files – These are also needed for psycopg2. So install these by installing the package libpq-dev.
sudo apt-get install libpq-dev
- pg_config – It is installed by the libpq-dev package. But it might get missed from being added to the PATH. Get the path . Generally it is – /usr/lib/postgresql/X.Y/bin/. And then add it to the PATH.
$ export PATH=/usr/lib/postgresql/X.Y/bin/:$PATH
- Assuming you followed the above steps, run the below –
$ pip install psycopg2
Option 2: For Ubuntu
Use below –
if( aicp_can_see_ads() ) {
}
sudo apt install libpq-dev
Option 3:
Use below snippets
sudo yum install postgresql-devel yum install python-devel postgresql-devel
Option 4 : Using already installed libpq-fe.h correctly
There is possibility that libpq-fe.h is already in the system. But it is not being correctly pointed at. Follow below steps for that.
- Check libpq version and info
brew info libpq
- Locate libpq-fe.h
yum install mlocate sudo updateb locate libpq-fe.h
- Update ~/.bash_profile. pg_config is installed by the libpq-dev package. But it might get missed from being added to the PATH. Get the path . Generally it is – /usr/lib/postgresql/X.Y/bin/. And then add it to the PATH.
export PATH=/usr/lib/postgresql/X.Y/bin/:$PATH OR export PATH=/usr/pgsql-10/bin/:$PATH
if( aicp_can_see_ads() ) {
}
- As a next step just install psycopg2 or whatever you have being doing. That should work.
Option 5 : For Mac
brew install libpq
brew link --force libpq
gem install pg
if( aicp_can_see_ads() ) {
}
Hope this helps to solve the error.
Other Interesting Reads –
-
How to Send Large Messages in Kafka ?
-
Fix Spark Error – “org.apache.spark.SparkException: Failed to get broadcast_0_piece0 of broadcast_0”
-
How to Handle Bad or Corrupt records in Apache Spark ?
-
How to use Broadcast Variable in Spark ?
-
Best Practices for Dependency Problem in Spark
-
Sample Code – Spark Structured Streaming vs Spark Streaming
-
Sample Code for PySpark Cassandra Application
-
How to Enable UTF-8 in Python ?
-
How to log an error in Python ?
-
Sample Python Code To Read & Write Various File Formats (JSON, XML, CSV, Text)
-
How to Handle Errors and Exceptions in Python ?
-
How to Handle Bad or Corrupt records in Apache Spark ?
-
How To Fix – Partitions Being Revoked and Reassigned issue in Kafka ?
-
What Are The Most Important Metrics to Monitor in Kafka ?
-
How To Connect Local Python to Kafka on AWS EC2 ?
libpq-fe.h no such file or directory ,libpq-fe.h no such file or directory psycopg2 ,fatal error libpq-fe.h no such file or directory centos ,cannot open include file 'libpq-fe.h' no such file or directory ,psycopg libpq-fe.h no such file or directory ,ruby fatal error libpq-fe.h no such file or directory ,python psycopg2 libpq-fe.h no such file or directory ,r fatal error libpq-fe.h no such file or directory ,libpq-fe.h no such file or directory centos ,libpq-fe.h no such file or directory centos 7 , ,error libpq-fe.h no such file or directory ,psycopg2 fatal error libpq-fe.h no such file or directory ,fatal error libpq-fe.h no such file or directory centos ,psycopg fatal error libpq-fe.h no such file or directory ,ruby fatal error libpq-fe.h no such file or directory ,r fatal error libpq-fe.h no such file or directory , , ,libpq-fe.h no such file or directory centos 7 ,libpq-fe.h no such file or directory psycopg2 ,libpq-fe h no such file or directory windows ,libpq-dev ,pip libpq-fe.h: no such file or directory ,can't find the 'libpq-fe.h header ,fatal error: libpq-fe.h: no such file or directory ubuntu ,libpq-fe.h psycopg2 , , ,libpq-fe.h no such file or directory centos 7 ,fatal error: libpq-fe.h: no such file or directory ubuntu ,can't find the 'libpq-fe.h header ,fatal error libpq-fe.h no such file or directory psycopg2 ,libpq-dev ,configure: error: cannot find libpq-fe h please specify correct postgresql installation path ,libpq-fe.h psycopg2 ,libpq-fe h file not found mac , , , , ,libpq-fe.h ,libpq-fe.h no such file ,libpq-fe.h psycopg2 ,libpq-fe.h centos ,libpq-fe.h debian ,libpq-fe.h windows ,libpq-fe.h install ubuntu ,libpq-fe.h brew ,libpq-fe.h fedora ,libpq-fe.h alpine ,libpq-fe.h apt ,arch libpq-fe.h ,can't find the 'libpq-fe.h header alpine ,alpine cannot find libpq-fe.h ,brew libpq-fe.h ,bundle libpq-fe.h ,bundle install libpq-fe.h ,libpq-fe.h centos 8 ,libpq-fe.h centos 6 ,#include libpq-fe.h ^ compilation terminated ,cannot find libpq-fe.h ,cannot find libpq-fe.h php ,can't find libpq-fe.h in /usr/include ,can't find the 'libpq-fe.h header windows ,libpq-fe.h download ,postgresql libpq-fe.h download ,debian install libpq-fe.h ,debian stretch libpq-fe.h ,docker cannot find libpq-fe.h ,libpq-fe.h' file not found mac ,libpq-fe.h file not found ,libpq-fe.h functions ,libpq-fe.h github ,libpq-fe.h gem install pg ,gcc libpq-fe.h ,how to get libpq-fe.h ,libpq-fe.h header ,can't find the 'libpq-fe.h header ubuntu 20.04 ,can't find the 'libpq-fe.h header centos 8 ,opensuse can't find the 'libpq-fe.h header ,how to download libpq-fe.h ,libpq-fe.h install ,libpq-fe.h yum install ,#include libpq-fe.h psycopg2 ,pip install psycopg2 libpq-fe.h ,/usr/include/postgresql/libpq-fe.h ,libpq-fe.h missing ,libpq-fe.h missing linux ,libpq-fe.h not found ,libpq-fe.h postgresql ,libpq-fe.h pip ,psycopg libpq-fe.h ,python libpq-fe.h ,rails postgres libpq-fe.h ,r postgres libpq-fe.h ,libpq-fe.h ubuntu ,unable to find libpq-fe.h ,ubuntu cannot find libpq-fe.h , ,/usr/include/libpq-fe.h ,libpq-fe.h windows download ,libpq-fe.h what is ,libpq-fe.h no such file or directory psycopg2 ,libpq-fe.h no such file or directory centos ,libpq-fe.h no such file or directory windows ,libpq-fe.h no such file or directory r ,libpq-fe.h no such file or directory c++ ,libpq-fe.h no such file or directory redhat ,python libpq-fe.h no such file or directory ,python psycopg2 libpq-fe.h no such file or directory ,error libpq-fe.h no such file or directory ,fatal error libpq-fe.h no such file or directory #include libpq-fe.h ,fatal error postgresql/libpq-fe.h no such file or directory ,libpq-fe.h no such file or directory ,cannot open include file 'libpq-fe.h' no such file or directory ,fatal error libpq-fe.h no such file or directory psycopg2 ,fatal error libpq-fe.h no such file or directory centos ,psycopg fatal error libpq-fe.h no such file or directory ,ruby fatal error libpq-fe.h no such file or directory ,r fatal error libpq-fe.h no such file or directory ,fatal error libpq-fe.h no such file or directory ,configure error cannot find libpq-fe.h ,libpq-fe.h no such file or directory #include libpq-fe.h ,postgresql/libpq-fe.h no such file or directory ,can't find the 'libpq-fe.h header ubuntu ,libpq-fe.h no such file or directory ubuntu ,psycopg2 fatal error libpq-fe.h ,libpq.a ,pip install psycopg2 error libpq-fe.h ,libpq postgresql ,centos 7 libpq-fe.h ,can't find the 'libpq-fe.h header centos ,centos cannot find libpq-fe.h ,libpq-fe.h centos 7 ,can't find the 'libpq-fe.h header centos 7 ,libpq-dev for centos , , ,#include libpq-fe.h ^ compilation terminated ,configure error cannot find libpq-fe.h ,configure error could not find libpq-fe.h ,configure error could not find libpq-fe.h header ,configure error header file libpq-fe.h is required ,error 'libpq-fe.h' file not found ,error cannot find libpq-fe.h ,error libpq-fe.h no such file or directory ,fatal error 'libpq-fe.h' file not found ,fatal error libpq-fe.h ,fatal error libpq-fe.h no such file or directory #include libpq-fe.h ,fatal error libpq-fe.h no such file or directory centos ,fatal error postgresql/libpq-fe.h ,fatal error postgresql/libpq-fe.h no such file or directory ,libpq-fe.h error eclipse ,libpq-fe.h error error ,libpq-fe.h error example ,libpq-fe.h error exception ,libpq-fe.h error git ,libpq-fe.h error github ,libpq-fe.h error java ,libpq-fe.h error javascript ,libpq-fe.h error juniper ,libpq-fe.h error jupyter notebook ,libpq-fe.h error keras ,libpq-fe.h error kernel ,libpq-fe.h error key ,libpq-fe.h error kubernetes ,libpq-fe.h error linux ,libpq-fe.h error list ,libpq-fe.h error loading ,libpq-fe.h error log ,libpq-fe.h error query ,libpq-fe.h error queue ,libpq-fe.h error timeout ,libpq-fe.h error windows ,libpq-fe.h error windows 10 ,libpq-fe.h error xcode ,libpq-fe.h error xml ,libpq-fe.h error xpath ,libpq-fe.h error yaml ,libpq-fe.h error youtube ,libpq-fe.h error zero ,libpq-fe.h error zerodha ,libpq-fe.h error zip ,libpq-fe.h error zoom ,libpq-fe.h error zoominfo ,libpq-fe.h not found ,pip install psycopg2 error libpq-fe.h ,psycopg fatal error libpq-fe.h ,psycopg2 fatal error libpq-fe.h ,#include libpq-fe.h ,#include libpq-fe.h ^ compilation terminated ,#include libpq-fe.h psycopg2 ,alpine cannot find libpq-fe.h ,alpine libpq-fe.h ,arch libpq-fe.h ,brew libpq-fe.h ,bundle install libpq-fe.h ,bundle libpq-fe.h ,can't find libpq-fe.h in /usr/include ,can't find the 'libpq-fe.h ,can't find the 'libpq-fe.h header ,can't find the 'libpq-fe.h header alpine ,can't find the 'libpq-fe.h header centos 8 ,can't find the 'libpq-fe.h header mac ,can't find the 'libpq-fe.h header osx ,can't find the 'libpq-fe.h header ubuntu 20.04 ,can't find the 'libpq-fe.h header windows ,cannot find libpq-fe.h ,cannot find libpq-fe.h php ,centos 7 libpq-fe.h ,centos libpq-fe.h ,could not find libpq-fe.h ,debian install libpq-fe.h ,debian libpq-fe.h ,debian stretch libpq-fe.h ,docker cannot find libpq-fe.h ,download libpq-fe.h ,error 'libpq-fe.h' file not found ,example libpq-fe.h ,fatal error libpq-fe.h ,fatal error postgresql/libpq-fe.h ,find header checking for libpq-fe.h ,gcc libpq-fe.h ,gem pg libpq-fe.h ,header file libpq-fe.h is required ,how to download libpq-fe.h ,how to get libpq-fe.h ,how to install libpq-fe.h in ubuntu ,instalar libpq-fe.h ,libpq-fe.h ,libpq-fe.h alpine ,libpq-fe.h apt ,libpq-fe.h brew ,libpq-fe.h c ,libpq-fe.h centos ,libpq-fe.h centos 6 ,libpq-fe.h centos 7 ,libpq-fe.h centos 8 ,libpq-fe.h debian ,libpq-fe.h download ,libpq-fe.h fedora ,libpq-fe.h functions ,libpq-fe.h gem install pg ,libpq-fe.h github ,libpq-fe.h header ,libpq-fe.h install ,libpq-fe.h install ubuntu ,libpq-fe.h missing ,libpq-fe.h missing linux ,libpq-fe.h no such file ,libpq-fe.h not found ,libpq-fe.h pip ,libpq-fe.h postgresql ,libpq-fe.h psycopg2 ,libpq-fe.h r ,libpq-fe.h rpm ,libpq-fe.h ubuntu ,libpq-fe.h visual studio ,libpq-fe.h what is ,libpq-fe.h windows ,libpq-fe.h windows download ,libpq-fe.h yum install , libpq-fe.h' file not found mac ,missing libpq-fe.h ,no file libpq-fe.h in /usr/local/include ,no such file libpq-fe.h ,opensuse can't find the 'libpq-fe.h header ,pip install psycopg2 libpq-fe.h ,postgresql libpq-fe.h download ,psycopg fatal error libpq-fe.h ,psycopg libpq-fe.h ,psycopg2 fatal error libpq-fe.h ,psycopg2 libpq-fe.h ,python libpq-fe.h ,r postgres libpq-fe.h ,rails can't find the 'libpq-fe.h header ,rails postgres libpq-fe.h ,rhel 7 libpq-fe.h ,rpostgresql libpq-fe.h ,ubuntu cannot find libpq-fe.h ,ubuntu libpq-fe.h ,unable to find libpq-fe.h ,what is libpq-fe.h ,where is libpq-fe.h ,windows libpq-fe.h ,yum install libpq-fe.h ,yum libpq-fe.h , ,
libpq-fe.h error ,error 'libpq-fe.h' file not found ,fatal error libpq-fe.h ,psycopg2 fatal error libpq-fe.h ,psycopg fatal error libpq-fe.h ,fatal error postgresql/libpq-fe.h ,error libpq-fe.h no such file or directory ,fatal error libpq-fe.h no such file or directory #include libpq-fe.h ,#include libpq-fe.h ^ compilation terminated ,fatal error postgresql/libpq-fe.h no such file or directory ,error cannot find libpq-fe.h ,configure error cannot find libpq-fe.h ,configure error header file libpq-fe.h is required ,pip install psycopg2 error libpq-fe.h ,fatal error 'libpq-fe.h' file not found mac ,fatal error libpq-fe.h no such file or directory centos ,fatal error 'libpq-fe.h' file not found
if( aicp_can_see_ads() ) {
if( aicp_can_see_ads() ) {
}
}
As per this answer, I performed a series of prerequisite setups to be ready to pip install python3 packages.
However, when I ran
python3 -m pip install psycopg2
I got the following error:
Downloading/unpacking psycopg2
Downloading psycopg2-2.6.2.tar.gz (376kB): 376kB downloaded
Running setup.py (path:/tmp/pip-build-1ocbvumt/psycopg2/setup.py) egg_info for package psycopg2
Installing collected packages: psycopg2
Running setup.py install for psycopg2
Skipping implicit fixer: buffer
Skipping implicit fixer: idioms
Skipping implicit fixer: set_literal
Skipping implicit fixer: ws_comma
building 'psycopg2._psycopg' extension
gcc -pthread -Wno-unused-result -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 -I/opt/rh/rh-python34/root/usr/include -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.6.2 (dt dec pq3 ext)" -DPG_VERSION_HEX=0x090212 -I/opt/rh/rh-python34/root/usr/include/python3.4m -I. -I/usr/include -I/usr/include/pgsql/server -c psycopg/psycopgmodule.c -o build/temp.linux-x86_64-3.4/psycopg/psycopgmodule.o -Wdeclaration-after-statement
In file included from psycopg/psycopgmodule.c:27:0:
./psycopg/psycopg.h:31:22: fatal error: libpq-fe.h: No such file or directory
#include <libpq-fe.h>
^
compilation terminated.
error: command 'gcc' failed with exit status 1
Complete output from command /opt/rh/rh-python34/root/usr/bin/python3 -c "import setuptools, tokenize;__file__='/tmp/pip-build-1ocbvumt/psycopg2/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('rn', 'n'), __file__, 'exec'))" install --record /tmp/pip-rfdowyqt-record/install-record.txt --single-version-externally-managed --compile:
running install
running build
running build_py
creating build
creating build/lib.linux-x86_64-3.4
creating build/lib.linux-x86_64-3.4/psycopg2
copying lib/tz.py -> build/lib.linux-x86_64-3.4/psycopg2
copying lib/pool.py -> build/lib.linux-x86_64-3.4/psycopg2
copying lib/extras.py -> build/lib.linux-x86_64-3.4/psycopg2
copying lib/extensions.py -> build/lib.linux-x86_64-3.4/psycopg2
copying lib/_range.py -> build/lib.linux-x86_64-3.4/psycopg2
copying lib/__init__.py -> build/lib.linux-x86_64-3.4/psycopg2
copying lib/psycopg1.py -> build/lib.linux-x86_64-3.4/psycopg2
copying lib/_json.py -> build/lib.linux-x86_64-3.4/psycopg2
copying lib/errorcodes.py -> build/lib.linux-x86_64-3.4/psycopg2
creating build/lib.linux-x86_64-3.4/psycopg2/tests
copying tests/test_errcodes.py -> build/lib.linux-x86_64-3.4/psycopg2/tests
copying tests/dbapi20.py -> build/lib.linux-x86_64-3.4/psycopg2/tests
copying tests/test_bug_gc.py -> build/lib.linux-x86_64-3.4/psycopg2/tests
copying tests/test_async.py -> build/lib.linux-x86_64-3.4/psycopg2/tests
copying tests/testconfig.py -> build/lib.linux-x86_64-3.4/psycopg2/tests
copying tests/test_quote.py -> build/lib.linux-x86_64-3.4/psycopg2/tests
copying tests/test_extras_dictcursor.py -> build/lib.linux-x86_64-3.4/psycopg2/tests
copying tests/test_types_basic.py -> build/lib.linux-x86_64-3.4/psycopg2/tests
copying tests/test_transaction.py -> build/lib.linux-x86_64-3.4/psycopg2/tests
copying tests/test_cancel.py -> build/lib.linux-x86_64-3.4/psycopg2/tests
copying tests/test_dates.py -> build/lib.linux-x86_64-3.4/psycopg2/tests
copying tests/test_lobject.py -> build/lib.linux-x86_64-3.4/psycopg2/tests
copying tests/dbapi20_tpc.py -> build/lib.linux-x86_64-3.4/psycopg2/tests
copying tests/test_copy.py -> build/lib.linux-x86_64-3.4/psycopg2/tests
copying tests/test_types_extras.py -> build/lib.linux-x86_64-3.4/psycopg2/tests
copying tests/test_psycopg2_dbapi20.py -> build/lib.linux-x86_64-3.4/psycopg2/tests
copying tests/test_module.py -> build/lib.linux-x86_64-3.4/psycopg2/tests
copying tests/__init__.py -> build/lib.linux-x86_64-3.4/psycopg2/tests
copying tests/test_green.py -> build/lib.linux-x86_64-3.4/psycopg2/tests
copying tests/testutils.py -> build/lib.linux-x86_64-3.4/psycopg2/tests
copying tests/test_with.py -> build/lib.linux-x86_64-3.4/psycopg2/tests
copying tests/test_cursor.py -> build/lib.linux-x86_64-3.4/psycopg2/tests
copying tests/test_connection.py -> build/lib.linux-x86_64-3.4/psycopg2/tests
copying tests/test_notify.py -> build/lib.linux-x86_64-3.4/psycopg2/tests
copying tests/test_bugX000.py -> build/lib.linux-x86_64-3.4/psycopg2/tests
Skipping implicit fixer: buffer
Skipping implicit fixer: idioms
Skipping implicit fixer: set_literal
Skipping implicit fixer: ws_comma
running build_ext
building 'psycopg2._psycopg' extension
creating build/temp.linux-x86_64-3.4
creating build/temp.linux-x86_64-3.4/psycopg
gcc -pthread -Wno-unused-result -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 -I/opt/rh/rh-python34/root/usr/include -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.6.2 (dt dec pq3 ext)" -DPG_VERSION_HEX=0x090212 -I/opt/rh/rh-python34/root/usr/include/python3.4m -I. -I/usr/include -I/usr/include/pgsql/server -c psycopg/psycopgmodule.c -o build/temp.linux-x86_64-3.4/psycopg/psycopgmodule.o -Wdeclaration-after-statement
In file included from psycopg/psycopgmodule.c:27:0:
./psycopg/psycopg.h:31:22: fatal error: libpq-fe.h: No such file or directory
#include <libpq-fe.h>
^
compilation terminated.
error: command 'gcc' failed with exit status 1
----------------------------------------
Cleaning up...
Command /opt/rh/rh-python34/root/usr/bin/python3 -c "import setuptools, tokenize;__file__='/tmp/pip-build-1ocbvumt/psycopg2/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('rn', 'n'), __file__, 'exec'))" install --record /tmp/pip-rfdowyqt-record/install-record.txt --single-version-externally-managed --compile failed with error code 1 in /tmp/pip-build-1ocbvumt/psycopg2
Storing debug log for failure in /root/.pip/pip.log
The summary is, I suppose: error: command 'gcc' failed with exit status 1
What else could I be missing on my system to enable an installation of psycopg2?
Содержание
- How To Fix – “Error: Libpq-fe.h: No Such File or Directory” ?
- How To Fix – “Error: Libpq-fe.h: No Such File or Directory” ?
- Option 1 : General Steps
- Option 2: For Ubuntu
- Option 3:
- Option 4 : Using already installed libpq-fe.h correctly
- Одновременная работа php 5.2 и php 5.3 на Ubuntu 12.04
How To Fix – “Error: Libpq-fe.h: No Such File or Directory” ?
How To Fix – “Error: Libpq-fe.h: No Such File or Directory” ?
In this post, we will see How To Fix “Error: libpq-fe.h: No Such File or Directory”.
There can be various formats of the error depending on the context of use. Couple of those are shown below –
This issue occurs while installing postgresql or psycopg2 if the steps are not followed properly.
- Did you install pyscopg2 correctly ? Note that – it is a C wrapper around the libpq postgreSQL client library. And hence there are few things that you need to take care of. Follow the below steps if not done already.
To solve the error, use the below –
Option 1 : General Steps
- Python header files – These are needed for pycopg2. So install these by installing the the package – python-dev or python3-dev as per the python version.
Note : While doing this step, if you see an error – “Python.h: No such file or directory”, the fix is explained here – How To Fix – fatal error: Python.h: No such file or directory ?
- libpq header files – These are also needed for psycopg2. So install these by installing the package libpq-dev.
- pg_config – It is installed by the libpq-dev package. But it might get missed from being added to the PATH. Get the path . Generally it is – /usr/lib/postgresql/X.Y/bin/. And then add it to the PATH.
- Assuming you followed the above steps, run the below –
Option 2: For Ubuntu
Option 3:
Use below snippets
Option 4 : Using already installed libpq-fe.h correctly
There is possibility that libpq-fe.h is already in the system. But it is not being correctly pointed at. Follow below steps for that.
Источник
Одновременная работа php 5.2 и php 5.3 на Ubuntu 12.04
1 час. Установка производилась на работающем dev сервере.
Актуально для разработчиков под Drupal 6 и 7 и всех кто всё еще использует PHP 5.2.
Не смотря на то, что Drupal 7 нормально работает на PHP 5.3, Drupal 6 по-прежнему чувствует себя гораздо лучше с PHP 5.2. Хотя ядро D6 давно совместимо с PHP 5.3, у большинства разработчиков возникает невыносимая икота, когда они получают запрос о обновлении модуля до новой версии. Поэтому разработка для D7 и D6, становится более удобной при одновременной работе обоих версий PHP. (прим. таже это невероятно упрощает администрирование и сопровождение dev серверов путем исключения сервера с 5.2)
Одним из способов решения данной проблемы является использование mod_php5 для обработки скриптов PHP 5.3, и использования FastCGI модуля при необходимости обработки скриптов под PHP 5.2. Соответственно, для Ubuntu 12.04, можно установить PHP 5.3 из репозитория и затем вручную скомпилировать и установить PHP 5.2. Установка PHP 5.3 из репозиториев является довольно простой операцией, которую вы, скорее всего, уже выполняли, так что давайте просто решим, что она выглядит примерно так:
sudo apt-get install php5 php5-common php5-cli php5-dev php5-mysql phpmyadmin php5-pgsql phppgadmin php5-gd php5-mcrypt php5-curl php-pear libapache2-mod-php5 php5-xdebug php5-codesniffer
Примечательно, хотя этот пост сосредоточен на том как установить PHP 5.2, обе версии работают одинаково хорошо.
Загрузка исходного кода PHP
Я первоначально начал с версии 5.2.10 (эта версия была установлена на наших stage серверах) но был внеезапно остановлен ошибкой OpenSSL на этапе конфигурирования.
/usr/include/openssl/conf.h:132:7: note: expected ‘struct lhash_st_CONF_VALUE *’ but argument is of type ‘int *’
make: *** [ext/openssl/openssl.lo] Error 1
для которой я не смог найти работающего фикса (относительно легко применимого), но этап выполнился с самой последней версией 5.2.17, выдав вместо этой, кучу других ошибок.
Что ж, загрузим и распакуем исходники в папку
/Downloads/php-5.2.17
wget museum.php.net/php5/php-5.2.17.tar.gz
tar zxf php-5.2.17.tar.gz
Пришло время приступить к конфигурированию пакета. Ниже приведен пример вызова скрипта ./configure:
Очевидно, что вы можете приспособить его к конкретным потребностям путем добавления и/или удаления соответствующих опций. Вы можете узнать больше о опциях которые вам нужны (или не нужны) в документации для PHP.
Итак, это, вероятно, не работает из коробки, не так ли? В большинстве случаев причина в отсутствующих зависимостях. Вы можете попробовать решить эту проблему одним выстрелом, если вы не слишком беспокоитесь об установке лишних библиотек и пакетов:
sudo apt-get install libxml2-dev libpcre3-dev libbz2-dev libcurl4-openssl-dev libdb4.8-dev libjpeg-dev libpng12-dev libxpm-dev libfreetype6-dev libmysqlclient-dev postgresql-server-dev-9.1 libt1-dev libgd2-xpm-dev libgmp-dev libsasl2-dev libmhash-dev unixodbc-dev freetds-dev libpspell-dev libsnmp-dev libtidy-dev libxslt1-dev libmcrypt-dev
Вы также можете исправлять ошибки отсутствующих зависимостей одну за другой, и устанавливать только те пакеты, которые действительно необходимы.
Давайте рассмотрим некоторые из возможных ошибок, (вы можете перейти к следующему разделу, если скрипт ./configure выполнен без ошибок и получено сообщение
Thank you for using PHP at the end of its execution
configure: error: xml2-config not found. Please check your libxml2 installation.
Эта ошибка предлагает нам проверить наличие пакета libxml2. В действительности же, это значит, что отсутствует его dev версия.
Давайте найдем доступные пакеты, которые могут помочь решить данную проблему:
$ apt-cache search libxml2 | grep dev
libcroco3-dev — Cascading Style Sheet (CSS) parsing and manipulation toolkit
libxml++2.6-dev — C++ interface to the GNOME XML library (libxml2)
libxml2-dev — Development files for the GNOME XML library
libgdome2-cpp-smart-dev — C++ bindings for GDome2 DOM implementation
libgdome2-dev — Development files for libgdome2
libgdome2-ocaml-dev — OCaml bindings for GDome2 DOM implementation
libgtkmathview-dev — rendering engine for MathML documents
libsp-gxmlcpp-dev — S+P C++ wrapper for Gnome libxml2/libxslt
Нас интересует libxml2-dev, устанавливаем его:
sudo apt-get install libxml2-dev
Такая же процедура применяется для всех отсутствующих библиотек, поэтому я приведу только окончательные команды установки:
configure: error: Could not find pcre.h in /usr
sudo apt-get install libpcre3-dev
configure: error: Please reinstall the BZip2 distribution
sudo apt-get install libbz2-dev
configure: error: Please reinstall the libcurl distribution — easy.h should be in /include/curl/
sudo apt-get install libcurl4-openssl-dev
configure: error: DBA: Could not find necessary header file(s).
checking for db4 major version… configure: error: Header contains different version
sudo apt-get install libdb4.8-dev
configure: error: libjpeg.(a|so) not found.
sudo apt-get install libjpeg-dev
configure: error: libpng.(a|so) not found.
sudo apt-get install libpng12-dev
configure: error: libXpm.(a|so) not found.
sudo apt-get install libxpm-dev
configure: error: freetype.h not found.
sudo apt-get install libfreetype6-dev
You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev for building a client-side application.
configure: error: Cannot find libpq-fe.h. Please specify correct PostgreSQL installation path
sudo apt-get install postgresql-server-dev-9.1
checking for FreeType 1 support… no — FreeType 2.x is to be used instead
configure: error: Your t1lib distribution is not installed correctly. Please reinstall it.
sudo apt-get install libt1-dev
configure: error: Unable to find gd.h anywhere under /usr
sudo apt-get install libgd2-xpm-dev
configure: error: Unable to locate gmp.h
sudo apt-get install libgmp-dev
configure: error: Cannot find MySQL header files under /usr.
Note that the MySQL client library is not bundled anymore!
sudo apt-get install libmysqlclient-dev
configure: error: sasl.h not found!
sudo apt-get install libsasl2-dev
configure: error: Please reinstall libmhash — I cannot find mhash.h
sudo apt-get install libmhash-dev
checking for unixODBC support… configure: error: ODBC header file ‘/usr/include/sqlext.h’ not found!
sudo apt-get install unixodbc-dev
configure: error: Directory /usr is not a FreeTDS installation directory
sudo apt-get install freetds-dev
configure: error: Cannot find pspell
sudo apt-get install libpspell-dev
configure: error: SNMP sanity check failed. Please check config.log for more information.
sudo apt-get install libsnmp-dev
configure: error: Cannot find libtidy
sudo apt-get install libtidy-dev
configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution
sudo apt-get install libxslt1-dev
configure: error: mcrypt.h not found. Please reinstall libmcrypt.
sudo apt-get install libmcrypt-dev
configure: error: Cannot find OpenSSL’s libraries
Добавьте следующее в опции ./configure:
—with-libdir=/lib/x86_64-linux-gnu
configure: error: You’ve configured extension pdo_sqlite to build statically, but it depends on extension pdo, which you’ve configured to build shared. You either need to build pdo_sqlite shared or build pdo statically for the build to be successful.
Добавьте следующее в опции ./configure
—with-pdo-sqlite=shared
—with-sqlite=shared
Make
Все настроено правильно и без ошибок? Тогда пришло время для компиляции (и чашечки кофе во время его выполнения):
sudo make
Теперь можно, попивая кофе, ждать приближение ошибок.
Да, весьма вероятно, что здесь все может пойти наперекосяк.
Вот две ошибки и один ворнинг, которые вы всего скорее всего получите:
ext/openssl/.libs/xp_ssl.o: In function `php_openssl_setup_crypto’:
ext/openssl/xp_ssl.c:357: undefined reference to `SSLv2_server_method’
ext/openssl/xp_ssl.c:337: undefined reference to `SSLv2_client_method’
Это связано с багом #54736 которые лекго решаются применением патча прикрепленного к этому багрепорту
Скачайте этот патч в папку
/Downloads/php-5.2.17 и выполните следующее:
patch -p1
Вы должны увидеть сообщение об успешном применении патча, наподобии этого:
patching file ext/openssl/xp_ssl.c
Hunk #1 succeeded at 332 (offset 4 lines).
Hunk #2 succeeded at 354 (offset 4 lines).
Hunk #3 succeeded at 583 (offset -50 lines).
Hunk #4 succeeded at 819 (offset -98 lines).
ext/gmp/gmp.c: In function ‘zif_gmp_random’:
ext/gmp/gmp.c:1399:69: error: ‘__GMP_BITS_PER_MP_LIMB’ undeclared (first use in this function)
ext/gmp/gmp.c:1399:69: note: each undeclared identifier is reported only once for each function it appears in
Пришло время исправить баг #50990
В одном из комментариев susan dot smith dot dev at gmail dot com предлагается следующее работающее решение, которое делает магию:
Я решила проблему заменой устаревшей постоянной определения __GMP_BITS_PER_MP_LIMB на GMP_LIMB_BITS, которая присутствует во всех предыдущих версиях и MPIR определяет тоже.
Вам нужно отредактировать файл ext/gmp/gmp.c и заменить __GMP_BITS_PER_MP_LIMB на GMP_LIMB_BITS. В моем случае это было строке 1399.
ext/zip/lib/.libs/zip_dirent.o: In function `memset’:
/usr/include/x86_64-linux-gnu/bits/string3.h:82: warning: memset used with constant zero length parameter; this could be due to transposed parameters
Последний баг #53568 который довольно легко исправляется: откройте файл ext/zip/lib/zip_dirent.c и замените строкй 478:
memset(&tm, sizeof(tm), 0);
на
memset(&tm, 0, sizeof(tm));
Больше ошибок нет!
Install
Простейший вариант установки вашей блеcтящей новой версии PHP 5.2 является следующая команда:
sudo make install
Кроме того, если вы планируете повторить ту же установку еще раз на других машинах, или просто хотите сохранить файл пакета установки на будущее, вы можете запустить:
sudo checkinstall
которая вместе с установкой PHP? также создаст deb пакет в текущем каталоге.
Теперь, какой бы путь вы не выбрали, у вас установленЗРЗ 5.2 в /usr/bin/php52
Конфигурационные файлы Apache
Конфигурационный каталог /etc/php52/apache2/ уже должен быть создан в процессе установки (создайте его, если он отсутствует). Теперь нужно настроить PHP 5.2 на использование тех же расширений и модулей, которые использует PHP 5.3,
sudo ln -s /etc/php5/conf.d /etc/php52
sudo ln -s /etc/php5/cli /etc/php52
Скопируйте файл php.ini-recommended в новый каталог (который будет определен в следующем шаге)
sudo cp php.ini-recommended /etc/php52/apache2/php.ini
и если нужно, внесите необходимые настройки.
Apache и FastCGI
Следующая вещь, которую мы сделаем, будет настройка apache для запуска PHP 5.2 используя FastCGI. Начнем установку fastcgi модуля:
sudo apt-get install libapache2-mod-fastcgi
Убедитесь, что все требуемые модули включены и перезапустите Apache:
sudo a2enmod cgi fastcgi actions
sudo service apache2 restart
Создайте исполняемый скрипт php52-cgi для запуска FastCGI версии PHP и поместите его в /usr/lib/cgi-bin/:
#!/bin/sh
PHPRC=»/etc/php52/apache2/»
export PHPRC
PHP_FCGI_CHILDREN=4
export PHP_FCGI_CHILDREN
PHP_FCGI_MAX_REQUESTS=5000
export PHP_FCGI_MAX_REQUESTS
exec /usr/bin/php52/php-cgi
PHPRC этот параметр указывает на php.ini
PHP_FCGI_CHILDREN количество потоков
PHP_FCGI_MAX_REQUESTS лимит запросов
Вы можете узнать больше об этом на сайте FastCGI.
Дайте права на запуск:
sudo chmod +x /usr/lib/cgi-bin/php52-cgi
Наконец создайте новый файл /etc/apache2/php52.conf который будет использоваться для виртуальных хостов, которые требую использования PHP 5.2:
# Include file for virtual hosts that need to run PHP 5.2
ScriptAlias /php52-cgi /usr/lib/cgi-bin/php52-cgi
Action application/x-httpd-php5 /php52-cgi
AddHandler application/x-httpd-php5 .php
FilesMatch переопределяет обработчик php файлов.
ScriptAlias задет путь к CGI скрипту
AddHandler регистрирует новый обработчик
Action активизирует CGI-скрипт для работы с файлами переданных от обработчика.
Осталось только одно: для всех хостов, для которых вы хотите использовать PHP 5.2 нужно добавить в конфигурационный файл следующую строку:
Include php52.conf
и перегрузить новую конфигурацию:
sudo service apache2 reload
Поздравляю! Теперь у вас есть есть сервер с одновременно работающими версиями PHP 5.2 и PHP 5.3!
Источник
