I am using imports :-
import psycopg2
But while running the code in local, I am facing an issue of :-
from psycopg2._psycopg import (
ModuleNotFoundError: No module named 'psycopg2._psycopg'
I have installed psycopg2 using cmd [pip install psycopg2]
psycopg2 version 2.8.4
python version 3.7.3
python 3.7 32bit
How should I import the ._psycopg.py file in windows? or any other solution if possible?
I'm also facing the same problem. It took me 2 days to pulled out my hair until I found the solution.
What I've been tried
Here's what I have been doing to solve this issue BUT DIDN'T SOLVE THE PROBLEM. I hope it will help anybody else who has the same problem.
Install "psycopg2" and "psycopg2-binary"
pip install psycopg2
pip install psycopg2-binary
Install "libpq-dev"
sudo apt install libpq-dev
Install "python-psycopg2" and "python3-psycopg2"
sudo apt install python-psycopg2 python3-psycopg2
Install "python-dev" and "python3-dev" and "python3.9-dev"
sudo apt install python-dev python3-dev python3.9-dev
Install "python-setuptools"
sudo apt install python-setuptools
Unfortunately, none of my effort above solve my problem.
What's the solution
So, here's my solution that I've been try and IT WORKS
Install the latest mod_wsgi from Github.
You should install this latest 'mod_wsgi' in order to your wsgi able to use Psycopg2 library. Here's my step to do it :
Go to release page mod_wsgi on Github (https://github.com/GrahamDumpleton/mod_wsgi/releases)
Download the file from latest version. As I write this, the latest version is 4.7.1 (https://github.com/GrahamDumpleton/mod_wsgi/archive/4.7.1.tar.gz)
Follow the installation guide from official docs.
Unpacking source code
tar xvfz mod_wsgi-4.7.1.tar.gz
Configure source code
./configure
Build the source code and install
make
make install
Restart apache server
sudo service apache2 restart
This solution has works on my machine (Ubuntu 18.04 & Python 3.9 Venv).
Alternative solution
Here's some solution from others.
Saray Chak's solution
Related
I am unable to install module pandas in my linux vm. I tried all ways to install it, but it says it has version 1.1.5 requirement already satistied. But when I try running the code, it says, no module found. The latest version of python in it is 2.7.3, but I want to install 3.8 or 3.7, but I'm unable to. Where am I going wrong?
Did you try installing python3 from your package manager? You can install python 3.9 from apt using the below command
apt install python3 pip -y
You can also install the below package to use python in the terminal instead of python3 every time
apt install python-is-python3 -y
I cant comment yet so using the answer section, kindly give me an upvote so I can start using the comment feature, sorry for the trouble
I'm attempting to make a website with a few others for the first time, and have run into a weird error when trying to use Django/Python/VirtualEnv. I've found solutions to this problem for other operating systems, such as Ubuntu, but can't find any good solutions for Mac.
This is the relevant code being run:
virtualenv -p python3 venv
source venv/bin/activate
pip install -r requirements.txt
After running that block, I get the following errors:
AssertionError
Failed building wheel for django-toolbelt
Running setup.py bdist_wheel for psycopg2
...
AssertionError
Failed building wheel for psycopg2
Failed to build django-toolbelt psycopg2
I believe I've installed the "django-toolbelt" and "psycopg2", so I'm not sure why it would be failing.
The only difference I can think of is that I did not use the command
sudo apt-get install libpq-dev
as was instructed for Ubuntu usage as I believe that installing postgresql with brew took care of the header.
Thanks for any help or insight!
For MacOS users
After trying all the above methods (which did not work for me on MacOS 10.14), that one worked :
Install openssl with brew install openssl if you don't have it already.
add openssl path to LIBRARY_PATH :
export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/
install psycopg2 with pip pip3 install psycopg2
I had the same problem on Arch linux. I think that it's not an OS dependant problem. Anyway, I fixed this by finding the outdated packages and updating then.
pip uninstall psycopg2
pip list --outdated
pip install --upgrade wheel
pip install --upgrade setuptools
pip install psycopg2
I was also getting same error.
Using Python 3.7.3 and pip 19.1.1.
I used following command.
pip install psycopg2-binary==2.8.3
TDLR
If you aren't used to installing Python C-extensions, and psycopg2 isn't a core part of your work, try
pip install psycopg2-binary
Building Locally
psycopg2 is a C-extension, so it requires compilation when being installed by pip. The Build Prerequisites section of the docs explain what must be done to make installation via pip possible. In summary (for psycopg 2.8.5):
a C compiler must be installed on the machine
the Python header files must be installed
the libpq header files must be installed
the pg_config program must be installed (it usually comes with the libpq headers) and on $PATH.
With these prerequisites satisfied, pip install psycopg2 ought to succeed.
Installing pre-compiled wheels
Alternatively, pip can install pre-compiled binaries so that compilation (and the associated setup) is not required. They can be installed like this:
pip install psycopg2-binary
The docs note that
The psycopg2-binary package is meant for beginners to start playing with Python and PostgreSQL without the need to meet the build requirements.
but I would suggest that psycopg2-binary is often good enough for local development work if you are not using psycopg2 directly, but just as a dependency.
Concluding advice
Read the informative installation documentation, not only to overcome installation issues but also to understand the impact of using the pre-compiled binaries in some scenarios.
I had same problem and this appears to be a Mojave Issue, I was able to resolve with:
sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /
For Mac OS X users:
1. First check your postgresql path by running this command in terminal:
pg_config
If this fails lookup how to add pg_config to your path.
2. Next install Xcode Tools by running this command in terminal:
xcode-select --install
If you have both those sorted out now try to install psycopg2 again
For MacOS users, this question has the correct solution:
install command line tools if necessary:
xcode-select --install
then
env LDFLAGS="-I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib" pip install psycopg2
I was also facing the same after running all the above commands, but the following two commands worked for me:
Instead of pip, use this:
sudo apt-get install libpq-dev
then run this command:
pip install psycopg2
On OS X, I was able to solve this by simply upgrading wheel before installing psycopg2:
pip install --upgrade wheel
For OSX Sierra users, it seems that an xcode update is the solution: Can't install psycopg2 package through pip install... Is this because of Sierra?
I tried all the above solutions but they did not work for me. What I did was change the psycopg2 version in my requirements.txt file from psycopg2==2.7.4 to psycopg2==2.7.6
Is your error message complete? the most encountered reason for failing to install psycopg2 on mac from pip is pg_config is not in path.
by the way, using macports or fink to install psycopg2 is more recommended way, so you don't have to worry about pg_config, libpq-dev and python-dev.
plus, are using Python 3.5? then upgrage your wheel to > 0.25.0 using pip.
I faced the same issue, but the answers above didn't work for me.
So this is what I did in my requirements.txt
psycopg2-binary==2.7.6.1 and it worked fine
I had this issue on several packages, including psycopg2, numpy, and pandas. I simply removed the version from the requirements.txt file, and it worked.
So instead of psycopg2-binary==2.7.6.1 I just had psycopg2-binary.
I know you are asking for development environment but if you are deploying on server say, Heroku. Just add below line in the requirements.txt of your project.
django-heroku==0.3.1
As this package itself will install the required packages like psycopg2 on server deployment.So let the server(heroku) should take care of it.
sudo apt install libpq-dev python3.X-dev
where X is the sub version,
these should be followed by :
pip install --upgrade wheel
pip install --upgrade setuptools
pip install psycopg2
Enjoy !!!
I solved my problem by updating/installing vs_BuildTools. The link to the software was given in the error itself.
Error Image
Fixed by installing python3.7-dev: sudo apt install python3.7-dev, based on the link.
Python: 3.7
Ubuntu: 20.04.3 LTS
I am trying to install pyzipcode package using
pip install pyzipcode
I have a list of lat,lon data from which I require the Zipcodes. I checked online and pyzipcode came across as the most dependable solution for python. While trying to install I get the error below:
In file included from src/module.c:24:0:
src/connection.h:33:21: fatal error: sqlite3.h: No such file or directory
compilation terminated.
error: command 'Anac\Scripts\gcc.bat' failed with exit status 1
Also there are other results with same errors but haven't found any solution from those.
P.S: Any other way to get ZIPCODES in python from lon,lat will be helpful in the meantime
I encountered the same problem when installing pyzipcode on EC2 linux. Solved the issue by sudo yum install sqlite-devel before pip install pyzipcode==1.0. On Ubuntu or other system, it could be sudo apt-get install sqlite-dev or so.
From the error. It is expected to install sqlite3 in the system.
Install sqlite3 in ubuntu system with this command:
sudo apt-get install sqlite3
sudo apt-get install libsqlite3-dev
In mac use brew:
brew install sqlite3
In windows follow these steps:
Go to SQLite3 download page, “Precompiled Binaries For Windows”
section
Download “sqlite-shell” and “sqlite-dll” archive files
Unpack them and set environmental path (i.e., C:\program_files\sqlite3)
Install the sqlite3 Ruby gem.
I have a fresh debian install with :
+ default 2.6.6 python installed
+ also installed python3 at /opt/python3/
+ installed psycopg2
Problem :
>>> import psycopg2
works with standard python
but not the alternate python /opt/python3/bin/python3.
I presume it is an import path problem, but I don't know how to solve it being a newbie on python.
You need to install psycopg2 separately for your Python 3 installation.
You need to follow the installation instructions for installing from source, using pip or easy_install will be easiest (provided you have the libpq-dev debian package installed).
You cannot reuse the system-installed psycopg2 because that'll only work on Python 2.
I had the same issue and installing the python3 include files sorted the issue (while in the active virtualenv)
sudo apt-get install python3-dev as per solution provided in this post
Psycopg2 fails to install on python 3 with pip issuing a fatal error
So I recap for the record and any one stumbing on this
1. Install virtualenv. instructions here
2. Install pip for your version, in my case it was pip-3.3 instructions here in order to get distribute_setup.py and get-pip.py
3. enjoy > pip-3.3 install psycopg2
I just got some space on a VPS server(running on ubuntu 8.04), and I'm trying to install django on it. The server has python 2.5 installed, but I guess its non standard installation. When I run install script for django, I get
amitoj#ninja:~/Django-1.2.1$ python setup.py install
Traceback (most recent call last):
File "setup.py", line 1, in <module>
from distutils.core import setup
ImportError: No module named distutils.core
I'm stumped. All the articles on internet tell me how to install modules using distutils. But how do I get distutils itself? Can anyone point me to the archive for distutils? I looked in /usr/lib/local/python2.5, /usr/lib/python2.5 etc, and as expected there is no distutils to be found.
I know this is an old question, but I just come across the same issue using Python 3.6 in Ubuntu, and I am able to solve it using the following command (this works in Ubuntu 18.04, 20.04 and 22.04):
sudo apt-get install python3-distutils
If you are unable to install with either of these:
sudo apt-get install python-distutils
sudo apt-get install python3-distutils
Try this instead:
sudo apt-get install python-distutils-extra
Ref: https://groups.google.com/forum/#!topic/beagleboard/RDlTq8sMxro
you can use sudo apt-get install python3-distutils by root permission.
i believe it worked here
You can install the python-distutils package. sudo apt-get install python-distutils should suffice.
I ran across this error on a Beaglebone Black using the standard Angstrom distribution. It is currently running Python 2.7.3, but does not include distutils. The solution for me was to install distutils. (It required su privileges.)
su
opkg install python-distutils
After that installation, the previously erroring command ran fine.
python setup.py build
The simplest way to install setuptools when it isn't already there and you can't use a package manager is to download ez_setup.py and run it with the appropriate Python interpreter. This works even if you have multiple versions of Python around: just run ez_setup.py once with each Python.
Edit: note that recent versions of Python 3 include setuptools in the distribution so you no longer need to install separately. The script mentioned here is only relevant for old versions of Python.
The module not found likely means the packages aren't installed.
Debian has decided that distutils is not a core python package, so it is not included in the last versions of debian and debian-based OSes. You should be able to do
sudo apt-get install python3-distutils
sudo apt-get install python3-apt
If you are in a scenario where you are using one of the latest versions of Ubuntu (or variants like Linux Mint), one which comes with Python 3.8, then you will NOT be able to have Python3.7 distutils, alias not be able to use pip or pipenv with Python 3.7, see:
How to install python-distutils for old python versions
Obviously using Python3.8 is no problem.
This didn't work for me: sudo apt-get install python-distutils
So, I tried this: sudo apt-get install python3-distutils
If the system Python is borked (i.e. the OS packages split distutils in a python-devel package) and you can’t ask a sysadmin to install the missing piece, then you’ll have to install your own Python. It requires some header files and a compiler toolchain. If you can’t have those, try compiling a Python on an identical computer and just copying it.
By searching all python-distutils related package:
apt-cache search x
I get python3-distutils-extra - enhancements to the Python3 build system
Then just try:
sudo apt-get install python3-distutils-extra