Django error for psycopg2 ImportError: DLL load failed - django

Hi I am getting this error while I am trying to run syncdb in my virtual environment.
If I copy psycopg2 folder to my project folder (where I have my manage.py and settings.py) then this error disappears. But I still get this error when the code is pushed to heroku.
I have referred to many online materials but wasn't very lucky.
File "c:\Users\mayayadav\anteus\venv\lib\site-packages\psycopg2-2.4.5-py2.7-wi
n32.egg\psycopg2\__init__.py", line 67, in <module>
from psycopg2._psycopg import BINARY, NUMBER, STRING, DATETIME, ROWID
ImportError: DLL load failed: The specified module could not be found. (venv)

I had the same problem on Windows, The way i get it working was to install psycopg2 from:
http://www.stickpeople.com/projects/python/win-psycopg/
And doing it this way it's recomended here http://initd.org/psycopg/install/

In the case, where the install binaries are not up to date (as it happened today: latest Python is 3.4 and PostgresSQL - 9.3, while latest avaiable are 3.3 and 9.2.6 respectively), it is enough to add the PostgresSQL binary path (e.g. C:\Program Files\PostgreSQL\9.3\bin) to the path variable.
Note: you need to restart your command line to get it working.

2019 Update
I encountered the same issue with Python 3.8 and psycopg2 2.8.3 and 2.8.4. Apparently psycopg2 doesn't work with Python 3.8 yet (understandably, since 3.8 released very recently). The fix for me was to go back to using Python 3.7.

It's so old problem... I ran into a problem with PyCharm and virtualenv, PyCharm have problem with pip install psycopg2. I copied _psycopg.cp38-win_amd64.pyd from global python to \venv\Lib\site-packages\psycopg2. And all done.

Related

ImportError: No module named 'django' despite having it installed running apache2 server

I know that many have posted similar question however I tried most solution without success.
I'm trying to host a webpage with apache2 and django in python3.
In the error log I found ImportError: No module named 'django' when accessing the wsgi.pyfile, where I also added import sys, sys.version to confirm which python version is used and from the error log I can see that I'm running following python version 3.5.2 (default, Nov 23 2017, 16:37:01) [GCC 5.4.0 20160609].
When I run python3.5 I see that I uses the same python version and here I can run import django without any error!
EDIT: I checked django.__file__and saw that it was located in /home/USERNAME/.local/lib/python3.5/site-packages/django/init.py and that path /home/USERNAME/.local/lib/python3.5/site-packages wasn't in the sys.path that tried to run django. But adding it with sys.path.append(path) didn't help :(
Any thoughts what I might have messed up?
If you have Setup the whole configuration in VirtualEnv then , i suggest you to activate it by,
source /location to /env/bin activate
pip3 install django=version_id
or pip install django=version id
if you want to pass version id then its good or it will install the latest django from your repo.
Now test Django Version there.
Hope you will no get the error.
Location - means the path where env will be located in project directory, if you have followed the standard installation process of django or else you don't need, and version id- vesion of django framework.
I finally understood how to solve it! first I had to run pip3 uninstall django then run sudo pip3 install django.

django.core.exceptions.ImproperlyConfigured: Error loading either pysqlite2 or sqlite3 modules (tried in that order): No module named _sqlite3

I tried re-installing python 2 in my environment.
Re-installed pip, setuptools
when I try to run python manage.py runserver it throws the error
django.core.exceptions.ImproperlyConfigured: Error loading either pysqlite2 or sqlite3 modules (tried in that order): No module named _sqlite3
I tried installing sqlite 3 , its already installed
I tried installing pysqlite2 , its already installed
both python 2 and installed in my ubuntu 16.04, django version = 1.8.X
Still unaware of what cause the error?
For Ubuntu users:
Download the source file of the Python version that you need, from source. Extract the folder somewhere, cd into the folder,
./configure
make
make install
this should fix your issue.
(This can be done outside VE, i just had the same issues with python 3.4)

Path issue Pip (Psycopg2) inside VirtualEnv

When using Pip (6.0.8) to install Django (1.9) and Psycopg2 (2.6.1), Django got installed in the env/lib/python2.7/site-packages folder and Psycopg2 in the env/lib64/python2.7/site-packages folder.
When I'm using command line (eg python manage.py migrate) or >>> import psycopg2, this all works fine. But when Mod_WSGI is running the application it complains that there is no module Psycopg2.
I'm able to work around this issue by adding the lib64 as a python path in my Apache conf file, but I'm pretty sure this is not the best possible way.
Any suggestions for a better solution?
Btw: I noticed by the way that Pip 7.1.2 is installing Django in Lib64 as well iso Lib.
Yes, there is with the use of --install-option. Have a look at the docs

Running django in virtualenv - ImportError: No module named django.core.management?

I have installed Django after activating my virtualenv but still I am getting following error
from django.core.management import execute_from_command_line
ImportError: No module named django.core.management
If you already activated your virtualenv (source /path/bin/activate) then check if you have installed Django.
pip install django
With next command you can see if Django was installed.
pip freeze | grep django
Another thing that you can try is to remove first line (#!/usr/bin/env python) in the manage.py file.
You should check if django is installed
Activate your environment, then run the following command to see which version is installed :
python -c "import django; print(django.get_version())"
I am using virtual environment so I added this line in manage.py:
sys.path.append('./myvenv/lib/python3.5/site-packages')
in which myvenv is the name of my virtual environment and version of my installed Python is 3.5.
This solved my issued.
I found that I had Python 3.4 and 2.7 installed concurrently, and the pip install django==1.7 command automagically decided the Python 3.4 /dist-packages was where it should live. I CD'd over to the Python 2.7 directory and re-piped it... and all is well.
sudo pip install django --upgrade
worked for me, i am not having virutal environment by the way.
I had the same problem when I was running Django from inside a virtual environment and then using another terminal window ran the command
python manage.py shell without first switching to the venv.
The problem was resolved after I switched back.
I found that I could import the django module from the python interpreter, but django-admin.py could not import it when run from the command line.
I confirmed that I was using the python interpreter in my virtual environment.
I was using a 64-bit version of python. Uninstalling, and installing the 32-bit version, then re-creating my venv solved this for me.
If you're using virtualenv, you can add it to your path using sys.path.append('./myvenv/lib/python3.5/site-packages').
Try closing and opening the terminal again. That worked for me too.

importerror: No module named django

I installed python 2.6 alongside my mac's 2.5.2 version. As soon as I did, python2.6 manage.py runserver failed because it couldn't find django.core.management.
From a shell, import django returns importerror: No module named django.
Why?
Did you reinstall Django?
This happens when I install side by side versions of Python on Gentoo. Whenever I install a new version, I have to either reinstall the new ones or make a symlink to the old site-packages.
Because each installation of Python uses its own directory to store libraries. On a Mac, they are in /Library/Python/2.x/site-packages/. Presumably you originally installed Django in the 2.5 directory, but it isn't yet in the 2.6 one. You can symlink it there if you want to, or reinstall it using the new version.
Add site-packages to PYTHONPATH:
export PYTHONPATH="/home/jerome/bin/django-1.1/lib/python2.6/site-packages:$PYTHONPATH"
Worked on Ubuntu, with a python/django virtual environment using virtualenv and pip.
Source: http://benfsayer.com/importerror-no-module-named-django-core-management/
I use Bitnami's Django installer, and this happened for me when I wasn't in their custom shell, which I believe sets related python path environment variables. I ran ./use_djangostack in the root of the Bitnami package and then was successful running the server again.