ImportError: No module named psycopg2 - python

In installation process of OpenERP 6, I want to generate a config file with these commands:
cd /home/openerp/openerp-server/bin/
./openerp-server.py -s --stop-after-init -c /home/openerp/openerp-server.cfg
But it always showed the message: ImportError: No module named psycopg2
When I checked for psycopg2 package, it's already installed. Package python-psycopg2-2.4.5-1.rhel5.x86_64 is already installed to its latest version. Nothing to do. What's wrong with this? My server is CentOS, I've installed Python 2.6.7.

Step 1: Install the dependencies
sudo apt-get install build-dep python-psycopg2
Step 2: Run this command in your virtualenv
pip install psycopg2-binary
Ref: Fernando Munoz

Use psycopg2-binary instead of psycopg2.
pip install psycopg2-binary
Or you will get the warning below:
UserWarning: The psycopg2 wheel package will be renamed from release 2.8; in order to keep installing from binary please use "pip install psycopg2-binary" instead. For details see: http://initd.org/psycopg/docs/install.html#binary-install-from-pypi.
Reference: Psycopg 2.7.4 released | Psycopg

I faced the same issue and resolved it with following commands:
sudo apt-get install libpq-dev
pip install psycopg2

Try installing
psycopg2-binary
with
pip install psycopg2-binary --user

Please try to run the command import psycopg2 on the python console. If you get the error then check the sys.path where the python look for the install module. If the parent directory of the python-psycopg2-2.4.5-1.rhel5.x86_64 is there in the sys.path or not. If its not in the sys.path then run export PYTHONPATH=<parent directory of python-psycopg2-2.4.5-1.rhel5.x86_64> before running the openerp server.

Import Error on Mac OS
If psycopg2 is getting installed but you are unable to import it in your .py file then the problem is libpq, its linkages, and the library openssl, on which libpq depends upon. The overall steps are reproduced below. You can check it step by step to know which is the source of error for you and then you can troubleshoot from there.
Check for the installation of the openssl and make sure it's working.
Check for installation of libpq in your system it may not have been installed or not linked. If not installed then install it using the command brew install libpq. This installs libpq library. As per the documentation
libpq is the C application programmer's interface to PostgreSQL. libpq is a set of library functions that allow client programs to pass queries to the PostgreSQL backend server and to receive the results of these queries.
Link libpq using brew link libpq, if this doesn't work then use the command: brew link libpq --force.
Also put in your .zshrc file the following export PATH="/usr/local/opt/libpq/bin:$PATH". This creates all the necessary linkages for libpq library .
Now restart the terminal or use the following command source ~/.zshrc.
Now use the command pip install psycopg2. It will work.
This works, even when you are working in conda environment.
N.B. pip install psycopg2-binaryshould be avoided because as per the developers of the psycopg2 library
The use of the -binary packages in production is discouraged because in the past they proved unreliable in multithread environments. This might have been fixed in more recent versions but I have never managed to reproduce the failure.

Try with these:
virtualenv -p /usr/bin/python3 test_env
source test_env/bin/activate
pip install psycopg2
run python and try to import if you insist on installing it on your systems python try:
pip3 install psycopg2

Recently faced this issue on my production server. I had installed pyscopg2 using
sudo pip install psycopg2
It worked beautifully on my local, but had me for a run on my ec2 server.
sudo python -m pip install psycopg2
The above command worked for me there. Posting here just in case it would help someone in future.

sudo pip install psycopg2-binary

You need to install the psycopg2 module.
On CentOS:
Make sure Python 2.7+ is installed. If not, follow these instructions: http://toomuchdata.com/2014/02/16/how-to-install-python-on-centos/
# Python 2.7.6:
$ wget http://python.org/ftp/python/2.7.6/Python-2.7.6.tar.xz
$ tar xf Python-2.7.6.tar.xz
$ cd Python-2.7.6
$ ./configure --prefix=/usr/local --enable-unicode=ucs4 --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib"
$ make && make altinstall
$ yum install postgresql-libs
# First get the setup script for Setuptools:
$ wget https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py
# Then install it for Python 2.7 and/or Python 3.3:
$ python2.7 ez_setup.py
$ easy_install-2.7 psycopg2
Even though this is a CentOS question, here are the instructions for Ubuntu:
$ sudo apt-get install python3-pip python-distribute python-dev
$ easy_install psycopg2
Cite: http://initd.org/psycopg/install/

For python3 on ubuntu, this worked for me:
$sudo apt-get update
$sudo apt-get install libpq-dev
$sudo pip3 install psycopg2-binary

i have the same problem, but this piece of snippet alone solved my problem.
pip install psycopg2

Run into the same issue when I switch to Ubuntu from Windows 10.. the following worked for me.. this after googling and trying numerous suggestions for 2 hours...
sudo apt-get install libpq-dev
then
pip3 install psycopg2
I hope this helps someone who has encountered the same problem especially when switching for windows OS to Linux(Ubuntu).

I have done 2 things to solve this issue:
use Python 3.6 instead of 3.8.
change Django version to 2.2 (may be working with some higher but I change to 2.2)

For Python3
Step 1: Install Dependencies
sudo apt-get install python3 python-dev python3-dev
Step 2: Install
pip install psycopg2

check correctly if you had ON your virtual env of your peoject, if it's OFF then make it ON. execute following cammands:
workon <your_env_name>
python manage.py runserver
It's working for me

It's very simple, not sure why nobody mentioned this for mac before.
brew install postgresql
pip3 install psycopg2
In simple terms, psycopg2 wants us to install postgres first.
PS: Don't forget to upvote, so that it can help other people as well.

Solved the issue with below solution :
Basically the issue due to _bz2.cpython-36m-x86_64-linux-gnu.so Linux package file. Try to find the the location.
Check the install python location ( which python3)- Example: /usr/local/bin/python3
copy the file under INSTALL_LOCATION/lib/python3.6
cp -rvp /usr/lib64/python3.6/lib-dynload/_bz2.cpython-36m-x86_64-linux-gnu.so /usr/local/lib/python3.6

try:
pip install psycopg2 --force-reinstall --no-cache-dir

Python2 importerror no module named psycopg2
pip install psycopg2-binary
Requirement already satisfied...
Solved by following steps:
sudo curl https://bootstrap.pypa.io/pip/2.7/get-pip.py -o get-pip.py
sudo python get-pip.py
sudo python -m pip install psycopg2-binary

pip install psycopg-binary
The line above helped me

For Python3 use this:
sudo apt-get install -y python3-psycopg2

Related

SSL backend error when using OpenSSL

I was trying to install pycurl in a virtualenv using pip and I got this error
ImportError: pycurl: libcurl link-time ssl backend (openssl) is different from compile-time ssl backend (none/other)
I read some documentation saying that "To fix this, you need to tell setup.py what SSL backend is used" (source) although I am not sure how to do this since I installed pycurl using pip.
How can I specify the SSL backend when installing pycurl with pip?
Thanks
for most people
After reading their INSTALLATION file, I was able to solve my problem by setting an environment variable and did a reinstall
# remove existing `pycurl` installation
pip uninstall pycurl
# export variable with your link-time ssl backend (which is openssl above)
export PYCURL_SSL_LIBRARY=openssl
# then, re-install `pycurl` with **no cache**
pip install pycurl --no-cache-dir
There could be other solution out there but this works perfectly for me on a virtualenv and pip installation.
Some people have a different error message complaining about nss instead of openssl
ImportError: pycurl: libcurl link-time ssl backend (nss)
(the key part is nss) so you have to do something different for this error message:
pip uninstall pycurl
pip install --no-cache-dir --compile --compile-options="--with-nss" pycurl
helloworld2013's answer is correct, but the key is matching the SSL library that pycurl is expecting. The error will be something like:
pycurl: libcurl link-time ssl backend (<library>) is different from compile-time ssl backend (<library> or "none/other")
To fix it, you have to use the library pycurl is expecting. In my case, my error was "pycurl: libcurl link-time ssl backend (nss) is different from compile-time ssl backend (openssl)", so my fix was:
pip uninstall pycurl
export PYCURL_SSL_LIBRARY=nss
pip install pycurl
With macOS 10.13, a brew-installed openSSL, and virtualenv, I was successful with:
# cd to your virtualenv, then…
pip uninstall pycurl
export PYCURL_SSL_LIBRARY=openssl
export LDFLAGS=-L/usr/local/opt/openssl/lib
export CPPFLAGS=-I/usr/local/opt/openssl/include
pip install pycurl --compile --no-cache-dir
With pip 7.1 you can put the following in your requirements file:
pycurl==7.19.5.1 --global-option="--with-nss"
Simply replace nss with the relevant ssl backend library.
The method to fix the pycurl after Mac OS High Sierra update:
Reinstall the curl libraries to use OpenSSL instead of SecureTransport
brew install curl --with-openssl
Install pycurl with correct build-time environment and paths
export PYCURL_SSL_LIBRARY=openssl
pip uninstall pycurl
pip install --no-cache-dir --global-option=build_ext --global-option="-L/usr/local/opt/openssl/lib" --global-option="-I/usr/local/opt/openssl/include" --user pycurl
This worked for me:
pip uninstall pycurl
export PYCURL_SSL_LIBRARY=nss
easy_install pycurl
None of this worked for me (note the difference is simply easy_install vs pip):
pip uninstall pycurl
export PYCURL_SSL_LIBRARY=[nss|openssl|ssl|gnutls]
pip install pycurl
#xor
curl -O https://pypi.python.org/packages/source/p/pycurl/pycurl-7.19.3.1.tar.gz
#...
python setup.py --with-[nss|openssl|ssl|gnutls] install
I had this problem for days. Finally with the help of other answers here (mainly Alexander Tyapkov's) I got it working for AWS Elastic Beanstalk.
Manual install (connecting with SSH):
sudo pip uninstall pycurl
curl -O https://pypi.python.org/packages/source/p/pycurl/pycurl-7.43.0.tar.gz
sudo pip install pycurl-7.43.0.tar.gz --global-option="--with-nss"
IMPORTANT: Please note that you have to make sure you are using the currect version of Python and PIP, otherwise you might be compiling it for Python 2.x and using v3.x.
Auto-install in Elastic Beanstalk:
files:
"/usr/local/share/pycurl-7.43.0.tar.gz" :
mode: "000644"
owner: root
group: root
source: https://pypi.python.org/packages/source/p/pycurl/pycurl-7.43.0.tar.gz
commands:
01_download_pip3:
# run this before PIP installs requirements as it needs to be compiled with OpenSSL
command: 'curl -O https://bootstrap.pypa.io/get-pip.py'
02_install_pip3:
# run this before PIP installs requirements as it needs to be compiled with OpenSSL
command: 'python3 get-pip.py'
03_pycurl_uninstall:
# run this before PIP installs requirements as it needs to be compiled with OpenSSL
command: '/usr/bin/yes | sudo pip uninstall pycurl'
04_pycurl_download:
# run this before PIP installs requirements as it needs to be compiled with OpenSSL
command: 'curl -O https://pypi.python.org/packages/source/p/pycurl/pycurl-7.43.0.tar.gz'
05_pycurl_reinstall:
# run this before PIP installs requirements as it needs to be compiled with OpenSSL
command: 'sudo pip install pycurl-7.43.0.tar.gz --global-option="--with-nss"'
container_commands:
09_pycurl_reinstall:
# run this before PIP installs requirements as it needs to be compiled with OpenSSL
# the upgrade option is because it will run after PIP installs the requirements.txt file.
# and it needs to be done with the virtual-env activated
command: 'source /opt/python/run/venv/bin/activate && pip3 install /usr/local/share/pycurl-7.43.0.tar.gz --global-option="--with-nss" --upgrade'
I had this problem because I was trying to configure Celery 4 with Django 1.10 in Elastic Beanstalk. If that's your case, I wrote a full blog post about it.
I'm on CentOS 7. I tried all of the above and couldn't get anything to work. It turns out I needed to run these as a root user. So if you're having trouble, try any of the above solutions as a root user. As an example, here is what worked for me:
su -
pip uninstall pycurl
export PYCURL_SSL_LIBRARY=[nss|openssl|ssl|gnutls]
pip install pycurl
Of course, all the usual disclaimers about running as a root user apply.
Note: [nss|openssl|ssl|gnutls] in the code above means to pick one, and don't include the square brackets or pipes. The person who asked the original question would have chosen openssl. In my particular case, I chose nss. Your error message should tell you which choice to make.
2019 Edit: Doing a sudo pip install might cause a problem with the machine's system install of Python. Perhaps try working in a Python virtual environment and install the packages there. If that doesn't work, the sudo trick in my answer is probably one of the last options to consider.
You can download the tar.gz file from here. Then extract it into a folder. You'll find a setup.py file there. Run the command over there that the site mentioned. For example:
python setup.py --with-[ssl|gnutls|nss] install
FYI: I tried to install pycurl at my windows, but I couldn't. But did it on my linux.
I am running this on OS X and some of the above solutions weren't working. Similar to Edward Newell's comment the PYCURL_SSL_LIBRARY variable seemed to have been completely ignored.
Further reading of the PycURL installation doc revealed the following:
pip may reinstall the package it has previously compiled instead of recompiling pycurl with newly specified options
Therefore, I had to force it to compile with:
pip install --compile pycurl
That works on a number of cases. However, I did run into a few systems that continued to ignore the variable so, similar to maharg101's answer, I resorted to the install options which through pip can be set like this:
pip install pycurl --global-option="--with-[ssl|gnutls|nss]"
where you select one of the three options inside the square brackets. Notice that the available option is ssl and not openssl. If you specify --with-openssl you'll get an error. Also note that if you were messing around with the PYCURL_SSL_LIBRARY variable and switching it to funky values to see what would happen this last command will definitely catch it and throw an error if the value is set but not valid.
For anyone having problem inside PyCharm CE on macOS
Mojave this is how i got it working in venv:
specify version: 7.43.0.1
Options: --install-option=--with-openssl --install-option=--openssl-dir=/usr/local/opt/openssl
Reinstallation of curl
I tried every suggestion from this discussion but no one worked for me. As solution I have reinstalled curl and curlib. After that I was able to install pycurl with ssl support inside environment.
At start:
'PycURL/7.43.0 libcurl/7.47.0 GnuTLS/3.4.10 zlib/1.2.8 libidn/1.32
librtmp/2.3'
Part 1.Re/Installation with pip
Firstly I have removed pycurl from virtualenv using pip as was suggested previous answers:
pip uninstall pycurl
export PYCURL_SSL_LIBRARY=openssl
pip install pycurl --global-option="--with-openssl"
The idea here is that package was cached and we just reintstall it with openssl option.
I also tried to recompile pycurl with pip using:
pip install pycurl --compile pycurl --no-cache
..but had the same error after running:
python
import pycurl
pycurl.version
ImportError: pycurl: libcurl link-time ssl backend (gnutls) is
different from compile-time ssl backend (openssl)
Part 2. Installation from tar
After previous method didn't work I have decidede to install pycurl from tar with:
curl -O https://pypi.python.org/packages/source/p/pycurl/pycurl-7.43.0.tar.gz
sudo tar -xzvf pycurl-7.43.0.tar.gz
cd pycurl-7.43.0/
sudo python setup.py --with-ssl install
It has installed pycurl globally but not within virtualenv. I also didn't check if it was installed with SSL support or not but think that still without ssl.
Part 3. Reinstallation of curl and curllib
Finally I understood that pycurl doesn't installs normally into environment because global curl and libcurl are compiled with gnutls.
Before starting check it with:
curl-config --configure
One of the output lines will be
'--without-ssl' '--with-gnutls'
To recompile it:
Firstly remove curl:
sudo apt-get purge curl
Install any build dependencies needed for curl
sudo apt-get build-dep curl
Get latest (as of Dec 20, 2016) libcurl
mkdir ~/curl
wget http://curl.haxx.se/download/curl-7.51.0.tar.bz2
tar -xvjf curl-7.51.0.tar.bz2
cd curl-7.51.0
The usual steps for building an app from source
./configure
./make
sudo make install
If openssl installed correctly then configure will find it automatically. The output will be:
curl version: 7.51.0
Host setup: x86_64-pc-linux-gnu
Install prefix: /usr/local
Compiler: gcc
SSL support: enabled (OpenSSL) ...
Resolve any issues of C-level lib location caches ("shared library cache")
sudo ldconfig
Now try to reinstall pycurl within environment:
curl -O https://pypi.python.org/packages/source/p/pycurl/pycurl-7.43.0.tar.gz
pip install pycurl-7.43.0.tar.gz --global-option="--with-openssl"
The result should be:
python
import pycurl
pycurl.version
'PycURL/7.43.0 libcurl/7.51.0 OpenSSL/1.0.2g zlib/1.2.8 librtmp/2.3'
I tried everything here on macOS 10.13 with no success. Then I found https://gist.github.com/webinista/b4b6a4cf8f158431b2c5134630c2cbfe which worked:
brew install curl --with-openssl
pip uninstall pycurl
export PYCURL_SSL_LIBRARY=openssl
export LDFLAGS=-L/usr/local/opt/openssl/lib;export CPPFLAGS=-I/usr/local/opt/openssl/include; pip install pycurl --compile --no-cache-dir
This worked for me both when not using a virtualenv and within a virtualenv.
This worked for me:
pip install --compile --install-option="--with-openssl" pycurl
Not sure if this is because of running in a virtualenv, but on CentOS 7 these solutions weren't working for me; the compiled objects were still being grabbed from the cache dir when I was reinstalling. If you're running into the same problem after trying other solutions here, try the following:
pip uninstall pycurl
export PYCURL_SSL_LIBRARY=[nss|openssl|ssl|gnutls]
pip install pycurl --no-cache-dir
Error:
ImportError: pycurl: libcurl link-time ssl backend (openssl) is different from compile-time ssl backend (none/other)
This worked for me, Mac 10.13, python 3.5, pycurl import worked after installing like this
pip3 uninstall pycurl;
pip3 install --compile --install-option="--with-openssl" pycurl
After being stuck on this for a long time, I found out that apple stopped including OpenSSL headers since OS X 10.11 El Capitan.
how to fix?
1) brew install openssl
2) echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' >> ~/.bash_profile (or .zshrc for zsh, etc)
3) pip uninstall pycurl
4) pip install --install-option="--with-openssl" --install-option="--openssl-dir=/usr/local/opt/openssl" pycurl
Same problem on amazonlinux - solved
I had this problem while creating a docker image based on amazonlinux, installing python3.7 and adding the pycurl module.
All other python modules were installed correctly except pycurl.
After trying many of the solutions proposed in the threads linked to this problem I finally solved my problem by using following commands for installation of all the pieces.
yum -y install python3 python3-devel gcc libcurl-devel aws-cli openssl-static.x86_64
then installed other modules like psycopg2-binary, requests, certifi using:
pip3 install --user --no-cache-dir -r requirements.txt
and finally installed pycurl module using:
pip3 install --user --global-option="--with-openssl" --no-cache-dir pycurl
and passing here the openssl global option.
The installation of the static library openssl-static.x86_64 solved the problem in my case as using global option used by the second pip3 command.
For python 2.7
sudo apt-get install build-essential libssl-dev libffi-dev python-dev
For python 3.5 also install the next:
sudo apt-get install python3.5-dev
Download the latest pycurl-7.43.0.tar.gz (md5) Source from pypi https://pypi.python.org/pypi/pycurl/7.43.0#downloads
and run the next command:
python setup.py --with-openssl install
Also you can do it into python environment:
(test_env)user#pc:~/Downloads/pycurl-7.43.0$ python setup.py --with-openssl install
pip install -U pip
if [ "$(curl --version | grep NSS 2>/dev/null)" ]; then
pip install --compile --install-option="--with-nss" pycurl
else
pip install --compile --install-option="--with-openssl" pycurl
fi
I encountered this problem and Sanket Jagtap's answer worked for me. I tried the answer with the most votes answer but it did not work.
My openssl old version is 1.0.1t, I think reinstalling openssl may solve this problem.
--- pycurl's openssl backend time....
I rebuilt the latest openssl and tried this answer. Check this out.
pip install --compile --install-option="--with-openssl" pycurl
This worked for me.
i recommend we should reinstall our openssl for try..
Following worked for me with Python3.6
MacOS High-Sierra
sudo pip3 uninstall pycurl
sudo pip3 install --compile --install-option="--with-openssl" pycurl
CentOS 7
sudo pip3 uninstall pycurl
sudo pip3 install --compile --install-option="--with-nss" pycurl
This link sums up the reason why the errors occur and gives a clear instruction to fix the problem.
https://cscheng.info/2018/01/26/installing-pycurl-on-macos-high-sierra.html
For me, the problem occurred when I upgraded to High-Sierra from El
Captain.
FWIW, I ran into a lot of issues getting this working via AWS Elastic Beanstalk and finally was able to get it working with:
packages:
yum:
openssl-devel: []
libcurl-devel: []
container_commands:
# Reinstall PyCurl with correct ssl backend
05_reinstall_pycurl:
command: |
pip install --upgrade pip
pip uninstall -y pycurl
pip install --global-option='--with-openssl' pycurl
Recently while upgrading a Django project I had the similar error. But this time setting the environment variable did not work. So I had to set both environment variable export PYCURL_SSL_LIBRARY=openssl and pass the flag --global-option="with-openssl".
The original answer was posted on this page
export CPPFLAGS=-I/usr/local/opt/openssl/include
export LDFLAGS=-L/usr/local/opt/openssl/lib
pip install pycurl --global-option="--with-openssl"

Error: No module named psycopg2.extensions

I am trying to set up a PostgreSQL database for my django project, which I believe I have done now thanks to the replies to my last question Problems setting up a postgreSQL database for a django project. I am now trying to run the command 'python manage.py runserver' in Terminal to get my localhost up but when I run the command, I see this response...
Error: No module named psycopg2.extensions
I'm not sure what this means - I have tried to download psycopg2 but can't seem to find a way to download psycopg2 using homebrew. I have tried easy_install, pip install and sudo but all return errors like this...
Downloading http://www.psycopg.org/psycopg/tarballs/PSYCOPG-2-4/psycopg2-2.4.5.tar.gz
Processing psycopg2-2.4.5.tar.gz
Writing /tmp/easy_install-l7Qi62/psycopg2-2.4.5/setup.cfg
Running psycopg2-2.4.5/setup.py -q bdist_egg --dist-dir /tmp/easy_install-l7Qi62/psycopg2-2.4.5/egg-dist-tmp-PBP5Ds
no previously-included directories found matching 'doc/src/_build'
unable to execute gcc-4.0: No such file or directory
error: Setup script exited with error: command 'gcc-4.0' failed with exit status 1
How to fix this?
The first thing to do is to install the dependencies.
sudo apt-get build-dep python-psycopg2
sudo apt install python3-psycopg2 # Python 3
After that go inside your virtualenv and use:
pip install psycopg2-binary
These two commands should solve the problem.
pip install psycopg2-binary
The psycopg2 wheel package will be renamed from release 2.8; in order to keep installing from binary please use "pip install psycopg2-binary" instead. For details see: http://initd.org/psycopg/docs/install.html#binary-install-from-pypi.
For Django 2 and python 3 install psycopg2 using pip3 :
pip3 install psycopg2
I installed it successfully using these commands:
sudo apt-get install libpq-dev python-dev
pip install psycopg2
For macOS Mojave just run pip install psycopg2-binary. Works fine for me, python version -> Python 3.7.2
first install apt-get install python-setuptools
then try easy_install psycopg2
This is what helped me on Ubuntu if your python installed from Ubuntu installer. I did this after unsuccessfully trying 'apt-get install' and 'pip install':
In terminal:
sudo synaptic
then in synaptic searchfield write
psycopg2
choose
python-psycopg2
mark it for installation using mouse right-click and push 'apply'. Of course, if you don't have installed synaptic, then first do:
sudo apt-get install synaptic
I ran into this same issues recently and this code worked.
sudo apt-get install libpq-dev python-dev-is-python3
Then
pip3 install psycopg2
In python 3.4, while in a virtual environment, make sure you have the build dependencies first:
sudo apt-get build-dep python3-psycopg2
Then install it:
pip install psycopg2
On Alpine Linux (majority of the docker containers) do:
apk add postgresql-dev
Then:
pip install psycopg2-binary
pip3 install django-psycopg2-extension
I know i am late and there's lot of answers up here which also solves the problem. But today i also faced this problem and none of this helps me. Then i found the above magical command which solves my problem :-P . so i am posting this as it might be case for you too.
Happy coding.
I used the extension after only importing psycopg2:
import psycopg2
...
psycopg2.extensions.AsIs(anap[i])
It seems that you need gcc-4.0, and it would be helpful to specify your OS type and version.
Maybe this question will help you a bit: Installing GCC to Mac OS X Leopard without installing Xcode
Update
I'm a Windows user, so I can't test your setup, but a quick google pointed to some more links:
http://hardlifeofapo.com/psycopg2-and-postgresql-9-1-on-snow-leopard/
Cannot install psycopg2 on OSX 10.6.7 with XCode4
I encountered the No module named psycopg2.extensions error when trying to run pip2 install psycopg2 on a Mac running Mavericks (10.9). I don't think my stack trace included a message about gcc, and it also included a hint:
Error: pg_config executable not found.
Please add the directory containing pg_config to the PATH
or specify the full executable path with the option:
python setup.py build_ext --pg-config /path/to/pg_config build ...
or with the pg_config option in 'setup.cfg'.
I looked for the pg_config file in my Postgres install and added the folder containing it to my path: /Applications/Postgres.app/Contents/Versions/9.4/bin. Your path may be different, especially if you have a different version of Postgres installed - I would just poke around until you find the bin/ folder. After doing this, the installation worked.
try this: sudo pip install -i https://testpypi.python.org/pypi psycopg2==2.7b2
.. this is especially helpful if you're running into egg error
on aws ec2 instances if you run into gcc error; try this
1. sudo yum install gcc python-setuptools python-devel postgresql-devel
2. sudo su -
3. sudo pip install psycopg2
This one worked for me
python manage.py migrate
I had such problem when trying to run python script as a sudo, while psycopg2 was installed via pip3 to my own user's directory.
I managed to resolve the issue for myself removing pip3 version, and just installing it via apt:
pip3 uninstall psycopg2
sudo apt install python3-psycopg2
you can install gcc for macos from https://github.com/kennethreitz/osx-gcc-installer
after instalation of gcc you'll be able to install psycopg with easy_install or with pip
Check if you have installed psycopg2 if not
sudo apt-get install psycopg2
Install the dependencies.
sudo apt-get build-dep python-psycopg2
These two commands should solve the problem.
This error raise because you not install postgres database in you project virtutal environment. you should run one of these command.
from a terminal you can you command for sudo.
sudo apt-get install build-dep python-psycopg2
for pip (pip basically work for python)
pip install psycopg2
or
pip3 install psycopg2-binary
i'm pretty sure it will work for you.

Installing Python Package from Github Using PIP

I've seen it documented that you can install a Github hosting Python package using pip via:
sudo pip install -e git+git://github.com/myuser/myproject.git#egg=myproject
However, this appears to install the package to the current working directory, which is almost never where is should be.
How do you instruct pip to install it into the standard Python package directory (e.g. on Ubuntu this is /usr/local/lib/python2.6/dist-packages)?
The -e flag tells pip to install it as "editable", i.e. keep the source around. Drop the -e flag and it should do about what you expect.
sudo pip install git+git://github.com/myuser/myproject.git#egg=myproject
If that doesn't work try using https instead of git.
sudo pip install git+https://github.com/myuser/myproject.git#egg=myproject
For Python 3 make sure you have python3-pip installed (and of course git installed):
The syntax just changed to:
sudo pip3 install git+git://github.com/someuser/someproject.git

psycopg2 install mutliple versions of python

I have two version of python.
I would like to install psycopg2 for python2.5
How can I run sudo apt-get install python-psycopg2 so it installs it for python2.5 and not python2.6 ?
Thanks
The ubuntu-10.04 package python-psycopg2 is designed to work with the default python2.6 installation.
To install psycopg2 for python2.5, download the psycopg source and use
python2.5 setup.py install
to install it. (Note the call to python2.5).

How do I install boto?

So that I am able to work with it within my python scripts?
If necessary, install pip:
sudo apt-get install python-pip
Then install boto:
pip install -U boto
Installing Boto depends on the Operating system.
For e.g in Ubuntu you can use the aptitude command:
sudo apt-get install python-boto
Or you can download the boto code from their site and move into the unzipped directory to run
python setup.py install
$ easy_install boto
Edit: pip is now by far the preferred way to install packages
switch to the boto-* directory and type python setup.py install.
install pip: https://pip.pypa.io/en/latest/installing.html
insatll boto: https://github.com/boto/boto
$ git clone git://github.com/boto/boto.git
$ cd boto
$ python setup.py install
Best way to install boto in my opinion is to use:
pip install boto-1.6
This ensures you'll have the boto glacier code.
If you already have boto installed in one python version and then install a higher python version, boto is not found by the new version of python.
For example, I had python2.7 and then installed python3.5 (keeping both). My script under python3.5 could not find boto. Doing "pip install boto" told me that boto was already installed in /usr/lib/python2.7/dist-packages.
So I did
pip install --target /usr/lib/python3.5/dist-packages boto
This allowed my script under python3.5 to find boto.
While trying out the
pip install boto
command, I encounter the error
ImportError: No module named pkg_resources
To resolve this, issue another command to handle the setuptools using curl
curl https://bootstrap.pypa.io/ez_setup.py | python
After doing that, the following command will work perfectly.
pip install boto
If you're on a mac, by far the simplest way to install is to use easy_install
sudo easy_install boto3

Categories

Resources