I have psycopg2 installed on my computer under C:\Python34\Lib\site-packages\psycopg2
If I use a postgresql database in a django project outside a virtual environment, I get no error.But, when I want to transfer the project to a virtual env so that I can deploy it on heroku. But when I try to migrate the database I get an error saying psycopg2 module is not present. I even tried to install it inside the virtual env using pip install psycopg2 and even that didn't work. Here is the full traceback.
(denv) C:\Users\Saket\denv\musicalguru>python manage.py migrate
Traceback (most recent call last):
File "C:\Users\Saket\denv\lib\site- packages\django\db\backends\postgresql_psycopg2\base.py", line 20, in <module>
import psycopg2 as Database
File "C:\Users\Saket\denv\lib\site-packages\psycopg2\__init__.py", line 50, in<module>from psycopg2._psycopg import BINARY, NUMBER, STRING, DATETIME, ROWID
ImportError: DLL load failed: The specified module could not be found.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\Saket\denv\lib\sitepackages
\django\core\management\__init__.py", line 338, in execute_from_command_line
utility.execute()
File "C:\Users\Saket\denv\lib\site- packages\django\core\management\__init__.py", line 312, in execute
django.setup()
File "C:\Users\Saket\denv\lib\site-packages\django\__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\Saket\denv\lib\site-packages\django\apps\registry.py", line 108, in populate
app_config.import_models(all_models)
File "C:\Users\Saket\denv\lib\site-packages\django\apps\config.py", line 198,in import_models
self.models_module = import_module(models_module_name)
File "C:\Users\Saket\denv\lib\importlib\__init__.py", line 109, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1129, in _exec
File "<frozen importlib._bootstrap>", line 1471, in exec_module
File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
File "C:\Users\Saket\denv\lib\site- packages\django\contrib\auth\models.py", line 41, in <module>
class Permission(models.Model):
File "C:\Users\Saket\denv\lib\site-packages\django\db\models\base.py", line 139, in __new__
new_class.add_to_class('_meta', Options(meta, **kwargs))
File "C:\Users\Saket\denv\lib\site-packages\django\db\models\base.py", line 324, in add_to_class
value.contribute_to_class(cls, name)
File "C:\Users\Saket\denv\lib\site-packages\django\db\models\options.py", line 250, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "C:\Users\Saket\denv\lib\site-packages\django\db\__init__.py", line 36, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "C:\Users\Saket\denv\lib\site-packages\django\db\utils.py", line 240, in__getitem__
backend = load_backend(db['ENGINE'])
File "C:\Users\Saket\denv\lib\site-packages\django\db\utils.py", line 111, in
load_backend
return import_module('%s.base' % backend_name)
File "C:\Users\Saket\denv\lib\importlib\__init__.py", line 109, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1129, in _exec
File "<frozen importlib._bootstrap>", line 1471, in exec_module
File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
File "C:\Users\Saket\denv\lib\sitepackages\django\db\backends\postgresql_psyc
opg2\base.py", line 24, in <module>
raise ImproperlyConfigured("Error loading psycopg2 module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading psycopg2 module: DLL
load failed: The specified module could not be found.
I used the instructions to install in virtual env from here
And then added PostgreSQL's 'bin' directory on the system path. That seemed to do the trick.
Intalling psycopg2 from source into virtualenv under windows is a pain.
Instead you can create the virtualenv that have access to system wide installed packages.
virtualenv --system-site-packages env_dir
Related
Every Django project that I'm trying from git is showing the same error. Although I install all the requirements it is still showing error while I try to run the server.
This is the command which I try to execute:
And this is the final error:
And here is the error.
G:\Study\Python\Django Project\Airline-reservation-django-master>py manage.py makemigration
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\vivek\Python\Python38-32\lib\site-packages\django\core\management\__init__.py", line 367, in execute_from_command_line
utility.execute()
File "C:\Users\vivek\Python\Python38-32\lib\site-packages\django\core\management\__init__.py", line 341, in execute
django.setup()
File "C:\Users\vivek\Python\Python38-32\lib\site-packages\django\__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\vivek\Python\Python38-32\lib\site-packages\django\apps\registry.py", line 108, in populate
app_config.import_models(all_models)
File "C:\Users\vivek\Python\Python38-32\lib\site-packages\django\apps\config.py", line 199, in import_models
self.models_module = import_module(models_module_name)
File "C:\Users\vivek\Python\Python38-32\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "G:\Study\Python\Django Project\Airline-reservation-django-master\Airline\models.py", line 2, in <module>
from django.contrib.auth.models import User
File "C:\Users\vivek\Python\Python38-32\lib\site-packages\django\contrib\auth\models.py", line 4, in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "C:\Users\vivek\Python\Python38-32\lib\site-packages\django\contrib\auth\base_user.py", line 52, in <module>
class AbstractBaseUser(models.Model):
RuntimeError: __class__ not set defining 'AbstractBaseUser' as <class 'django.contrib.auth.base_user.AbstractBaseUser'>. Was __classcell__ propagat
ed to type.__new__?
it is because it provide its own virtual environment and in that environment not all the requirements install try to install all the requirements again to solve this problem from pycharm
the only thing you have to do is you have to specify your python interpreter and install your require software on that
While running server import error is generated. Here I even don't use this generic types anywhere in my file.
Then how can this error is generated???
C:\Python34\python.exe manage.py runserver
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x0000000004BC8B70>
Traceback (most recent call last):
File "C:\Python34\lib\site-packages\django-2.0-py3.4.egg\django\utils\autoreload.py", line 225, in wrapper
fn(*args, **kwargs)
File "C:\Python34\lib\site-packages\django-2.0-py3.4.egg\django\core\management\commands\runserver.py", line 112, in inner_run
autoreload.raise_last_exception()
File "C:\Python34\lib\site-packages\django-2.0-py3.4.egg\django\utils\autoreload.py", line 248, in raise_last_exception
raise _exception[1]
File "C:\Python34\lib\site-packages\django-2.0-py3.4.egg\django\core\management\__init__.py", line 327, in execute
autoreload.check_errors(django.setup)()
File "C:\Python34\lib\site-packages\django-2.0-py3.4.egg\django\utils\autoreload.py", line 225, in wrapper
fn(*args, **kwargs)
File "C:\Python34\lib\site-packages\django-2.0-py3.4.egg\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Python34\lib\site-packages\django-2.0-py3.4.egg\django\apps\registry.py", line 112, in populate
app_config.import_models()
File "C:\Python34\lib\site-packages\django-2.0-py3.4.egg\django\apps\config.py", line 198, in import_models
self.models_module = import_module(models_module_name)
File "C:\Python34\lib\importlib\__init__.py", line 109, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1129, in _exec
File "<frozen importlib._bootstrap>", line 1471, in exec_module
File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
File "C:\Python34\lib\site-packages\tagging\models.py", line 5, in <module>
from django.contrib.contenttypes import generic
ImportError: cannot import name 'generic'
Your tagging library does not support Django 2.0. If you check Django's git repo, you will see that there is no more generic module in Django.contrib.contenttypes. It was removed in Django 1.9. Downgrade to Django 1.8 for your library to work or, which I would recommend, use a different tagging library, preferably one that is well enough maintained to support at least Django 1.11.
I had solved the error.
In settings.py file, there is INSTALLED_APPS. I removed 'tagging'
from that which solves all my errors.
Hope this helps.
I have been following tutorial how to import celery and run rabbitmq to my django project. and I have been following a tutorial on youtube. I do not now what I have missed but after the part where i ran python manage.py migrate djcelery it gives the result of:
root#1095ea233e7b:/app/main# python3 manage.py migrate djcelery
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.4/dist-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.4/dist-packages/django/core/management/__init__.py", line 302, in execute
settings.INSTALLED_APPS
File "/usr/local/lib/python3.4/dist-packages/django/conf/__init__.py", line 55, in __getattr__
self._setup(name)
File "/usr/local/lib/python3.4/dist-packages/django/conf/__init__.py", line 43, in _setup
self._wrapped = Settings(settings_module)
File "/usr/local/lib/python3.4/dist-packages/django/conf/__init__.py", line 99, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/usr/lib/python3.4/importlib/__init__.py", line 109, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1129, in _exec
File "<frozen importlib._bootstrap>", line 1471, in exec_module
File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
File "/app/main/actinbox/settings.py", line 6, in <module>
import djcelery
this is the tutorial that I have been following:
Django Celery Part 1
As I said in a comment, it's probably because you installed celery 4.0.0.
the tutorial you followed uses celery 3.0.23.
If you really want to use the tutorial use pip install django-celery==3.0.23
this is not recommended because it's an outdated version.
Okay, Im trying to use cryptoassets.django here. Iv got some help from Mikko about the python version being an issue(I was using 2.7.x, cryptoassets uses 3.4.x). I just solved by doing this
$virtualenv -p python3 venv
I also reinstalled Django because manage.py was pulling up error, probably because it was overwriting the bin/activate.. files.
With that out of the way. I installed the cryptoassets.django app
$pip3 install cryptoassets.django
Wonderfull. I set it up like the tutorial on bitbucket for the cryptoassets django intergration.
The problem comes in when i try to initialize the cryptoasset database with
$python manage.py cryptoassets_initialize_database
I get an Import error:
ImportError: No module named 'zope'
Here is the Traceback
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/caleb/Desktop/bitkoin/lib/python3.4/site- packages/django/core/management/__init__.py", line 351, in execute_from_command_line
utility.execute()
File "/home/caleb/Desktop/bitkoin/lib/python3.4/site-packages/django/core/management/__init__.py", line 343, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/caleb/Desktop/bitkoin/lib/python3.4/site-packages/django/core/management/__init__.py", line 190, in fetch_command
klass = load_command_class(app_name, subcommand)
File "/home/caleb/Desktop/bitkoin/lib/python3.4/site-packages/django/core/management/__init__.py", line 40, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
File "/home/caleb/Desktop/bitkoin/lib/python3.4/importlib/__init__.py", line 109, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1129, in _exec
File "<frozen importlib._bootstrap>", line 1471, in exec_module
File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
File "/home/caleb/Desktop/bitkoin/lib/python3.4/site-packages/cryptoassets/django/management/commands/cryptoassets_initialize_database.py", line 5, in <module>
from cryptoassets.core.service.main import Service
File "/home/caleb/Desktop/bitkoin/lib/python3.4/site-packages/cryptoassets/core/service/main.py", line 25, in <module>
from ..configure import Configurator
File "/home/caleb/Desktop/bitkoin/lib/python3.4/site-packages/cryptoassets/core/configure.py", line 13, in <module>
from zope.dottedname.resolve import resolve
ImportError: No module named 'zope'
What could be the issue now.
Cryptoassets is Python 3.4+ only and you are trying to run it on Python 2.
Very new to Django - I'm trying to get a site set up on Webfaction using their guide. http://docs.webfaction.com/software/django/getting-started.html
I've updated settings.py as instructed but I'm getting a syntax error in my settings.py file. I've tried going through and making sure there are no tabs and just spaces.
Here's the error message:
python3.3 manage.py syncdb
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/bstolte/webapps/mo_detector/lib/python3.3/django/core/management/__init__.py", line 399, in execute_from_command_line
utility.execute()
File "/home/bstolte/webapps/mo_detector/lib/python3.3/django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/bstolte/webapps/mo_detector/lib/python3.3/django/core/management/__init__.py", line 261, in fetch_command
commands = get_commands()
File "/home/bstolte/webapps/mo_detector/lib/python3.3/django/core/management/__init__.py", line 107, in get_commands
apps = settings.INSTALLED_APPS
File "/home/bstolte/webapps/mo_detector/lib/python3.3/django/conf/__init__.py", line 54, in __getattr__
self._setup(name)
File "/home/bstolte/webapps/mo_detector/lib/python3.3/django/conf/__init__.py", line 49, in _setup
self._wrapped = Settings(settings_module)
File "/home/bstolte/webapps/mo_detector/lib/python3.3/django/conf/__init__.py", line 128, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/usr/local/lib/python3.3/importlib/__init__.py", line 90, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1586, in _gcd_import
File "<frozen importlib._bootstrap>", line 1567, in _find_and_load
File "<frozen importlib._bootstrap>", line 1534, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 586, in _check_name_wrapper
File "<frozen importlib._bootstrap>", line 1024, in load_module
File "<frozen importlib._bootstrap>", line 1005, in load_module
File "<frozen importlib._bootstrap>", line 562, in module_for_loader_wrapper
File "<frozen importlib._bootstrap>", line 855, in _load_module
File "<frozen importlib._bootstrap>", line 982, in get_code
File "<frozen importlib._bootstrap>", line 313, in _call_with_frames_removed
File "/home/bstolte/webapps/mo_detector/mo_detector/mo_detector/settings.py", line 35
INSTALLED_APPS = (
^
SyntaxError: invalid syntax
Any ideas on why it's failing at INSTALLED_APPS?
Usually when you get a syntax error like that that's pointing at something you don't see any error with, it means there's an unclosed bracket, indentation block or other item preceding that in the file. The settings.py file follows normal Python syntax rules like any other .py file, so look for stuff preceding that line that might cause the parser to choke.