I'm relatively new to Python, extremely new to Django and Heroku, and also rather new to working in the terminal.
I'm attempting to follow the instructions on setting up a Django Heroku project found here. I'm getting stuck at the following command:
pip install django-toolbelt
I keep getting the following error:
Error: pg_config executable not found.
I don't know if any of this is even remotely related to the problem, but these are the things I've tried so far:
Tried reinstalling the django-toolbelt (just running the command again)
Tried switching from Postgres.app to the full Mac OSX install
No luck. What am I missing?
EDIT: Per Midimo's suggestion, I tried installing python-dev. This is what happened:
(venv)Macbook:[SITE] [USER]$ pip install python-dev
Downloading/unpacking python-dev
Could not find any downloads that satisfy the requirement python-dev
Cleaning up...
No distributions at all found for python-dev
Storing complete log in /Users/[USER]/.pip/pip.log
EDIT 2: And this is what happened when I tried to install libpq-dev...
(venv)Macbook:[SITE] [USER]$ pip install libpq-dev
Downloading/unpacking libpq-dev
Could not find any downloads that satisfy the requirement libpq-dev
Cleaning up...
No distributions at all found for libpq-dev
Storing complete log in /Users/[USER]/.pip/pip.log
do you have python-dev installed?
If you did, try installing libpq-dev
Before installing django-toolbelt you have to install those following dependencies:
$ sudo apt-get install python-dev python-psycopg2 libpq-dev
And then in the virtualenv:
(myven)trinh#trinh-pc:/path/to/django/project$ pip install django-toolbelt
Source :
I had same problem: one of the messages was couldn't run pg_config. Despite fact I had pg_config on my PATH and had restarted terminal to be sure.
My solution was to just run pg_config right before pip install django-toolbelt.
install than ran without any errors.
Just in case this will help anyone.
I'm working through this on Windows and was having this problem while trying to install django-toolbelt via pip in a virtualenv.
I had to add the entire directory to my PATH and make sure that Program Files was in quotes --
PATH=$PATH:/c/"program files"/postgresql/9.4/bin/
I was trying to get this work for hours so hopefully this helps someone else!
You need Postgres on you Mac because the django-toolbelt will try to install psycopg2 that won't find the path for the database and will raise the error.
The easiest solution is to install the Postgres.app and then add to the .profile file located on your home folder the following and restart or just run the command manually in the terminal:
export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/9.4/bin
Now you are ready to install the toolbelt
Related
I am having trouble installing psycopg2. I get the following error when I try to pip install psycopg2:
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'.
----------------------------------------
Command python setup.py egg_info failed with error code 1 in /tmp/pip-build/psycopg2
But the problem is pg_config is actually in my PATH; it runs without any problem:
$ which pg_config
/usr/pgsql-9.1/bin/pg_config
I tried adding the pg_config path to the setup.cfg file and building it using the source files I downloaded from their website (http://initd.org/psycopg/) and I get the following error message!
Error: Unable to find 'pg_config' file in '/usr/pgsql-9.1/bin/'
But it is actually THERE!!!
I am baffled by these errors. Can anyone help please?
By the way, I sudo all the commands. Also I am on RHEL 5.5.
pg_config is in postgresql-devel (libpq-dev in Debian/Ubuntu, libpq-devel on Centos/Fedora/Cygwin/Babun.)
On Mac OS X, I solved it using the homebrew package manager
brew install postgresql
Have you installed python-dev?
If you already have, try also installing libpq-dev
sudo apt-get install libpq-dev python-dev
From the article: How to install psycopg2 under virtualenv
Also on OSX. Installed Postgress.app from http://postgresapp.com/ but had the same issue.
I found pg_config in that app's contents and added the dir to $PATH.
It was at /Applications/Postgres.app/Contents/Versions/latest/bin. So this worked: export PATH="/Applications/Postgres.app/Contents/Versions/latest/bin:$PATH".
You can install pre-compiled binaries on any platform with pip or conda:
python -m pip install psycopg2-binary
or
conda install psycopg2
Please be advised that the psycopg2-binary pypi page recommends building from source in production:
The binary package is a practical choice for development and testing but in production it is advised to use the package built from sources
To use the package built from sources, use python -m pip install psycopg2. That process will require several dependencies (documentation) (emphasis mine):
A C compiler.
The Python header files. They are usually installed in a package such as python-dev. A message such as error: Python.h: No such file or directory is an indication that the Python headers are missing.
The libpq header files. They are usually installed in a package such as libpq-dev. If you get an error: libpq-fe.h: No such file or directory you are missing them.
The pg_config program: it is usually installed by the libpq-dev package but sometimes it is not in a PATH directory. Having it in the PATH greatly streamlines the installation, so try running pg_config --version: if it returns an error or an unexpected version number then locate the directory containing the pg_config shipped with the right libpq version (usually /usr/lib/postgresql/X.Y/bin/) and add it to the PATH:
$ export PATH=/usr/lib/postgresql/X.Y/bin/:$PATH
You only need pg_config to compile psycopg2, not for its regular usage.
Once everything is in place it’s just a matter of running the standard:
$ pip install psycopg2
or, from the directory containing the source code:
$ python setup.py build
$ python setup.py install
For ubuntu users, this is the solution:
sudo apt install libpq-dev
It worked for me.
On alpine, the library containing pg_config is postgresql-dev. To install, run:
apk add postgresql-dev
This is what worked for me on CentOS, first install:
sudo yum install postgresql postgresql-devel python-devel
On Ubuntu just use the equivilent apt-get packages.
sudo apt-get install postgresql postgresql-dev python-dev
And now include the path to your postgresql binary dir with you pip install, this should work for either Debain or RHEL based Linux:
sudo PATH=$PATH:/usr/pgsql-9.3/bin/ pip install psycopg2
Make sure to include the correct path. Thats all :)
You have to install libpq-dev/postgresql-libs, which is the header files and static library for compiling C programs to link with the libpq library in order to communicate with a PostgreSQL database backend.
On Arch this will run:
$ sudo pacman -S postgresql-libs
On Debian and Ubuntu:
$ sudo apt-get install libpq-dev
On Mac OS X:
$ brew install postgresql
On Red Hat/CentOS/Fedora:
$ sudo yum install postgresql-devel
apt-get build-dep python-psycopg2
Just to sum up, I also faced exactly same problem. After reading a lot of stackoverflow posts and online blogs, the final solution which worked for me is this:
1) PostgreSQL(development or any stable version) should be installed before installing psycopg2.
2) The pg_config file (this file normally resides in the bin folder of the PostgreSQL installation folder) PATH had to be explicitly setup before installing psycopg2. In my case, the installation PATH for PostgreSQL is:
/opt/local/lib/postgresql91/
so in order to explicitly set the PATH of pg_config file, I entered following command in my terminal:
PATH=$PATH:/opt/local/lib/postgresql91/bin/
This command ensures that when you try to pip install psycopg2, it would find the PATH to pg_config automatically this time.
I have also posted a full error with trace and its solution on my blog which you may want to refer. Its for Mac OS X but the pg_config PATH problem is generic and applicable to Linux also.
You should add python requirements used in Postgres on Ubuntu. Run:
sudo apt-get install libpq-dev python-dev
sudo apt-get install libpq-dev works for me on Ubuntu 15.4
I had this issue because I didn't had a postgres install. If you have brew install run
brew install postgresql
This should fix the issue.
For those running OS X, this solution worked for me:
1) Install Postgres.app:
http://www.postgresql.org/download/macosx/
2) Then open the Terminal and run this command, replacing where it says {{version}} with the Postgres version number:
export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/{{version}}/bin
e.g.
export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/9.4/bin
On Linux Mint sudo apt-get install libpq-dev worked for me.
UPDATE /etc/yum.repos.d/CentOS-Base.repo, [base] and [updates] sections
ADD exclude=postgresql*
curl -O http://yum.postgresql.org/9.1/redhat/rhel-6-i386/pgdg-centos91-9.1-4.noarch.rpmr
rpm -ivh pgdg-centos91-9.1-4.noarch.rpm
yum install postgresql
yum install postgresql-devel
PATH=$PATH:/usr/pgsql-9.1/bin/
pip install psycopg2
Simply run the following:
sudo apt install libpq-dev
Fixed the issue for me
Try to add it to PATH:
PATH=$PATH:/usr/pgsql-9.1/bin/ ./pip install psycopg2
Ali's solution worked for me but I was having trouble finding the bin folder location. A quick way to find the path on Mac OS X is to open psql (there's a quick link in the top menu bar). This will open a separate terminal window and on the second line the path of your Postgres installation will appear like so:
My-MacBook-Pro:~ Me$ /Applications/Postgres93.app/Contents/MacOS/bin/psql ; exit;
Your pg_config file is in that bin folder. Therefore, before installing psycopg2 set the path of the pg_config file:
PATH=$PATH:/Applications/Postgres93.app/Contents/MacOS/bin/
or for newer version:
PATH=$PATH:/Applications/Postgres.app/Contents/Versions/9.3/bin
Then install psycopg2.
I'm going to leave this here for the next unfortunate soul who can't get around this problem despite all the provided solutions. Simply use sudo pip3 install psycopg2-binary
You need to upgrade your pip before installing psycopg2. Use this command
pip install --upgrade pip
On MacOS, the simplest solution will be to symlink the correct binary, that is under the Postgres package.
sudo ln -s /Applications/Postgres.app/Contents/Versions/latest/bin/pg_config /usr/local/bin/pg_config
This is fairly harmless, and all the applications will be able to use it system wide, if required.
On Mac OS X and If you are using Postgres App (http://postgresapp.com/):
export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/latest/bin
No need to specify version of Postgres in this command. It will be always pointed to latest.
and do
pip install psycopg2
P.S: If Changes doesn't reflect you may need to restart the Terminal/Command prompt
Source
Installing python-psycopg2 solved it for me on Arch Linux:
pacman -S python-psycopg2
On Windows,
You may want to install the Windows port of Psycopg, which is recommended in psycopg's documentation.
Just solved the problem in Cent OS 7 by:
export PATH=$PATH:/usr/pgsql-9.5/bin
make sure your PostgreSql version matches the right version above.
This was partly suggested before, adding it here for clarity.
From the documentation at https://www.psycopg.org/docs/install.html.
they suggest running: $ pip install psycopg2-binary
That solved the issue for me.
Here, for OS X completeness: if you install PostgreSQL from MacPorts, pg_config will be in /opt/local/lib/postgresql94/bin/pg_config.
When you installed MacPorts, it already added /opt/local/bin to your PATH.
So, this will fix the problem:
$ sudo ln -s /opt/local/lib/postgresql94/bin/pg_config /opt/local/bin/pg_config
Now pip install psycopg2 will be able to run pg_config without issues.
To those on macOS Catalina using the zsh shell who have also installed the postgres app:
Open your ~/.zshrc file, and add the following line:
export PATH="/Applications/Postgres.app/Contents/Versions/latest/bin:$PATH"
Then close all your terminals, reopen them, and you'll have resolved your problem.
If you don't want to close your terminals, simply enter source ~/.zshrc in whatever terminal you'd like to keep working on.
My goal is to install a package to a specific directory on my machine so I can package it up to be used with AWS Lambda.
Here is what I have tried:
pip install snowflake-connector-python -t .
pip install --system --target=C:\Users\path2folder --install-option=--install-scripts=C:\Users\path2folder --upgrade snowflake-connector-python
Both of these options have returned the following error message:
ERROR: Can not combine '--user' and '--target'
In order for the AWS Lambda function to work, I need to have my dependencies installed in a specific directory to create a .zip file for deployment. I have searched through Google and StackOverflow, but have not seen a thread that has answered this issue.
Update: This does not seem to be a problem on Mac. The issue described is on Windows 10.
We encountered the same issue when running pip install --target ./py_pkg -r requirements.txt --upgrade with Microsoft store version of Python 3.9.
Adding --no-user to the end of it seems solves the issue. Maybe you can try that in your command and let us know if this solution works?
pip install --target ./py_pkg -r requirements.txt --upgrade --no-user
We had the same issue just in a Python course: The error comes up if Python is installed as an app from the Microsoft app store. In our case it was resolved after re-installing Python by downloading and using the installation package directly from the Python website.
I got a similar error recently. Adding my solution so that it might help someone facing the error due to the same reason.
I was facing an issue where all my pip installed packages were going to an older python brew installation folder.
As part of debugging, I was trying to install awscli-local package to user site-package using:
pip install --user awscli-local
Then I got:
ERROR: cannot combine --user and --target
In my case, it was due to the changes in pip config I had set some time back for some other reason.
I had set the 'target' config globally - removing which removed this error and my actual issue I was debugging for.
Check the following if solutions given above doesn't resolve your issue:
try the command:
pip config edit --editor <your_text_editor>
For me:
pip config edit --editor sublime
This will open the current config file where you can check if there's any conflicting configuration like the 'target' set in my case.
Adding --no-user at the end does work, and by far the easiest solution.
I am trying to install web3.py through the command pip install web3 however I cannot succeed without getting an error.
I have tried the advice on this website however that did not work, below is the error that I receive:
Error
Full Console Log
As advised here in a related stackoverflow thread, grab various wheel files that are required from here.
In this case it seems you are failing at cytoolz so you can manually install the whl files.
Let's say you are running a 64 bit environment, you can download cytoolz‑0.10.1‑cp38‑cp38‑win_amd64.whl file and run pip install cytoolz‑0.10.1‑cp38‑cp38‑win_amd64.whl in the same directory as your whl file
Since this is probably windows platform you are using, you need to install Microsoft C++ build tools and then also add them to your path, if it still doesn't work I suggest switching to Linux or using WSL
You may need to install those packages
sudo apt install python3-dev
sudo apt-get install libevent-dev
sudo apt update
Related answers
I'm new to using virtualenv and I'm having trouble installing MySQLdb on my virtualenv.
I'm currently using Python 2.7 and here is what my current virtualenv looks like
click==6.7
Flask==1.0.2
Flask-SQLAlchemy==2.3.2
itsdangerous==0.24
Jinja2==2.10
MarkupSafe==1.0
MySQL-python==1.2.5
mysqlclient==1.3.12
SQLAlchemy==1.2.8
Werkzeug==0.14.1
I first saw this error when I was coding on my normal machine (Mac 10.13), and when I initially tried to install MySQLdb, I got this error.
Command "python setup.py egg_info" failed with error code 1 in /private/tmp/pip-install-rxnRuR/MySQL-python/
I was able to fix it by using the second solution in this question
However, when I start up my virtual environment and attempt to install MySQLdb I get the same error code as above, but I do not have the same directories that are provided in the solution I originally found.
I've tried to piece together solutions from the follow questions trying to see if there is a solution for installing MySQLdb in virtualenv
Link1, Link2, Link3, but none of them seem to work
I was hoping someone might be able to explain what's going on so that I work with MySQLdb in a virtual environment.
Commands tried:
sudo pip install --upgrade setuptools
brew install mysql
brew install mysql-python
brew uninstall mysql
brew install mysql-connector-c
brew unlink mysql-connector-c
brew install mysql
pip install mysql-python
UPDATE: This seems to be a known issue and is in a Github thread I ended up solving the above error code using the solution found here, but now when I start up Python and I try to import MySQLdb, I get the following error code
Reason: image not found
Try this :
brew uninstall mysql-connector-c
brew install mysql
invoke "mysql_config --libs" and confirm its output include correct library options: "-L/usr/local/Cellar/mysql/5.7.20/lib -lmysqlclient -lssl -lcrypto"
export LDFLAGS=-L/usr/local/opt/openssl/lib && pip install mysqlclient
I hope this helps
The answer in this other question solved the problem, below is the command I used to make it work.
export DYLD_FALLBACK_LIBRARY_PATH=/anaconda2/lib/:$DYLD_FALLBACK_LIBRARY_PATH
A few notes however...
I had to run this command WITHIN my virtual environment for it to work, not my global environment
I was told this is a problem with Anaconda managing my packages and my virtual environment variables not being able to find the correct paths
You'll notice that my folder is "~/anaconda2/..." check to see where your lib files are installed on your global environment and make sure you adjust the directory name accordingly
Also I was suggested to keep this command in an initialization file for my virtual environment, that way whenever my virtual environment loads, this command is already executed
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.