ImportError: No module named 'django_select2' - django

I am trying to deploy my django application on the pythonanywhere. I have install all the packages that requires for the application. I am also using django_select2 reusable app in my application.
Firstly, i activate virtual environment and install the django_select2 by this command :
$ pip install django_select2
When i execute below command
$ pip freeze
cryptography==2.2.2
Django==2.0.7
django-appconf==1.0.2
django-select2==6.1.0
Flask==1.0.2
Flask-JWT==0.3.2
Flask-SQLAlchemy==2.3.2
furl==1.2
idna==2.7
As you see django_select2 is also in the installed list. I also check site-packages inside my virual environment. There is also django_select2 folder.
However when i run my app it generates the ImportError: No module named 'django_select2' inside my error.log
Here is the part of my error.log
2018-07-14 14:18:53,934: Error running WSGI application
2018-07-14 14:18:53,934: ImportError: No module named 'django_select2'
2018-07-14 14:18:53,934: File "/var/www/harunergul_pythonanywhere_com_wsgi.py", line 22, in <module>
2018-07-14 14:18:53,935: application = get_wsgi_application()
2018-07-14 14:18:53,935:
2018-07-14 14:18:53,935: File "/usr/local/lib/python3.5/dist-packages/django/core/wsgi.py", line 13, in get_wsgi_application
2018-07-14 14:18:53,935: django.setup(set_prefix=False)
2018-07-14 14:18:53,935:
2018-07-14 14:18:53,935: File "/usr/local/lib/python3.5/dist-packages/django/__init__.py", line 27, in setup
2018-07-14 14:18:53,935: apps.populate(settings.INSTALLED_APPS)
2018-07-14 14:18:53,935:
2018-07-14 14:18:53,935: File "/usr/local/lib/python3.5/dist-packages/django/apps/registry.py", line 85, in populate
2018-07-14 14:18:53,936: app_config = AppConfig.create(entry)
2018-07-14 14:18:53,936:
2018-07-14 14:18:53,936: File "/usr/local/lib/python3.5/dist-packages/django/apps/config.py", line 90, in create
2018-07-14 14:18:53,936: module = import_module(entry)
Any suggestions? What i have missing?

The problem is application is not using virtual environment in this case. If we look at the below line we will see /usr/local/... . So the application is using pythonanywhere.com default environment.
File "/usr/local/lib/python3.5/dist-packages/django/core/wsgi.py", line 13,
which means whatever we install in our virtualenv has no effect on default server. In pythonanywhere.com there is virtualenv menu, be sure if you input correct path info in this menu.

The default pip on PythonAnywhere is for Python 2.7, so you've been installing your modules into the wrong version of Python (your web app is using 3.5). Use pip3.5 to install your modules.

Related

openstack-dashboard-ubuntu-theme Error while installing package

I'm trying implement elastic search in my Django application.
For that i need to install open JDK-7 in my ubuntu 16.04 system.
While installing i'm getting the following error.
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
libatk-wrapper-java libatk-wrapper-java-jni openjdk-7-jre
Suggested packages:
openjdk-7-demo openjdk-7-source visualvm icedtea-7-jre-jamvm sun-java6-fonts
fonts-ipafont-gothic fonts-ipafont-mincho fonts-indic
The following packages will be REMOVED:
openstack-dashboard-ubuntu-theme
The following NEW packages will be installed:
libatk-wrapper-java libatk-wrapper-java-jni openjdk-7-jdk openjdk-7-jre
openjdk-7-jre-headless
0 upgraded, 5 newly installed, 1 to remove and 28 not upgraded.
2 not fully installed or removed.
Need to get 0 B/55.9 MB of archives.
After this operation, 77.7 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
(Reading database ... 515256 files and directories currently installed.)
Removing openstack-dashboard-ubuntu-theme (2:9.1.0-0ubuntu1) ...
Collecting and compressing static assets...
Traceback (most recent call last):
File "manage.py", line 25, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 350, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 302, in execute
settings.INSTALLED_APPS
File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 55, in __getattr__
self._setup(name)
File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 43, in _setup
self._wrapped = Settings(settings_module)
File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 99, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/usr/share/openstack-dashboard/openstack_dashboard/settings.py", line 381, in <module>
from openstack_auth import policy
File "/usr/lib/python2.7/dist-packages/openstack_auth/policy.py", line 24, in <module>
from openstack_auth import user as auth_user
File "/usr/lib/python2.7/dist-packages/openstack_auth/user.py", line 18, in <module>
from django.contrib.auth import models
File "/usr/local/lib/python2.7/dist-packages/django/contrib/auth/models.py", line 4, in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "/usr/local/lib/python2.7/dist-packages/django/contrib/auth/base_user.py", line 49, in <module>
class AbstractBaseUser(models.Model):
File "/usr/local/lib/python2.7/dist-packages/django/db/models/base.py", line 94, in __new__
app_config = apps.get_containing_app_config(module)
File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py", line 239, in get_containing_app_config
self.check_apps_ready()
File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py", line 124, in check_apps_ready
raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
dpkg: error processing package openstack-dashboard-ubuntu-theme (--remove):
subprocess installed post-removal script returned error exit status 1
Errors were encountered while processing:
openstack-dashboard-ubuntu-theme
E: Sub-process /usr/bin/dpkg returned an error code (1)
I also tried following commands to fix these issues.But it didn't worked
apt-get remove --auto-remove openstack-dashboard-ubuntu-theme
Thanks in advance
I was able to discern in my case it was an issue to do with apache not restarting due to a missing module namely : wsgi
I installed it :
apt-get install libapache2-mod-wsgi
The activated it :
sudo a2enmod wsgi
sudo /etc/init.d/apache2 reload
or
service apache2 restart
The I was able to uninstall the openstack-dashboard-ubuntu-theme:
dpkg --remove --force-remove-reinstreq openstack-dashboard-ubuntu-theme
Hope it helps.

PythonAnywhere WSGI error

in spite of my best efforts in the past weeks I've been stuck at deploying the WSGI file on Pythonanywhere while trying to set up a django framework. There are similar topics on here, but none were adoptable to my case.
I'm following this tutorial and I get the following error message:
2017-03-04 22:28:05,284 :Error running WSGI application
2017-03-04 22:28:05,285 :ImportError: No module named 'mysite'
2017-03-04 22:28:05,285 : File "/var/www/iamcsongor_pythonanywhere_com_wsgi.py", line 11, in <module>
2017-03-04 22:28:05,285 : application = get_wsgi_application()
2017-03-04 22:28:05,285 :
2017-03-04 22:28:05,285 : File "/home/iamcsongor/my-first-blog/myvenv/lib/python3.5/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application
2017-03-04 22:28:05,285 : django.setup(set_prefix=False)
2017-03-04 22:28:05,285 :
2017-03-04 22:28:05,285 : File "/home/iamcsongor/my-first-blog/myvenv/lib/python3.5/site-packages/django/__init__.py", line 22, in setup
2017-03-04 22:28:05,286 : configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
2017-03-04 22:28:05,286 :
2017-03-04 22:28:05,286 : File "/home/iamcsongor/my-first-blog/myvenv/lib/python3.5/site-packages/django/conf/__init__.py", line 53, in __getattr__
2017-03-04 22:28:05,286 : self._setup(name)
2017-03-04 22:28:05,286 :
2017-03-04 22:28:05,286 : File "/home/iamcsongor/my-first-blog/myvenv/lib/python3.5/site-packages/django/conf/__init__.py", line 41, in _setup
2017-03-04 22:28:05,287 : self._wrapped = Settings(settings_module)
2017-03-04 22:28:05,287 :
2017-03-04 22:28:05,287 : File "/home/iamcsongor/my-first-blog/myvenv/lib/python3.5/site-packages/django/conf/__init__.py", line 97, in __init__
2017-03-04 22:28:05,287 : mod = importlib.import_module(self.SETTINGS_MODULE)
Here's my WSGI file:
import os
import sys
path = '/home/iamcsongor/my-first-blog/firstweb' # use your own PythonAnywhere username here
if path not in sys.path:
sys.path.append(path)
os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'
from django.core.wsgi import get_wsgi_application
from django.contrib.staticfiles.handlers import StaticFilesHandler
application = StaticFilesHandler(get_wsgi_application())
I've taken a few screenshots of the code and Git Repo, if you could help, I'd be grateful. Thanks
As the error says, your DJANGO_SETTINGS_MODULE environment variable is set to "mysite", but that directory does not exist. Your settings file actually appears to be in "firstweb".
follow it
Start by saving your environment variables into a .env file in your project folder
You can run something like this in a Bash console, or edit the .env file directly using our "Files" tab:
cd ~/my-project-dir
echo "export SECRET_KEY=sekritvalue" >> .env
echo "export OTHER_SECRET=somethingelse" >> .env
Install python-dotenv into your virtualenv
workon my-virtualenv-name
pip install python-dotenv
or, if you're not using a virtualenv:
pip3.6 install --user python-dotenv
and, optionally, add it to your requirements.txt, if you're using one:
echo python-dotenv >> requirements.txt
and in wsgi file before get_wsgi_application()
import os
from dotenv import load_dotenv
project_folder = os.path.expanduser('~/my-project-dir') # adjust as appropriate
load_dotenv(os.path.join(project_folder, '.env'))
and make changes in setting.py file and remove secret key and put
import os
SECRET_KEY = os.getenv("SECRET_KEY")
and at last, do in bash console
set -a; source ~/my-project-dir/.env; set +a
echo 'set -a; source ~/my-project-dir/.env; set +a' >> ~/.virtualenvs/my-project-virtualenv/bin/postactivate
all done remove wsgi related error

ImportError: No module named phonenumbers in Odoo (OpenERP v8)

I'm trying to intall the asterisk_click2dial module on ODOO and this error comes to me in the log file:
ValueError: Routing: posting a message without model should be with a parent_id (private mesage).
2015-03-09 15:23:38,262 11093 ERROR ? werkzeug: Error on request:
Traceback (most recent call last):
File "/home/odoo/odoo/lib/python2.7/site-packages/werkzeug/serving.py", line 177, in run_wsgi
execute(self.server.app)
File "/home/odoo/odoo/lib/python2.7/site-packages/werkzeug/serving.py", line 165, in execute
application_iter = app(environ, start_response)
File "/opt/odoo/openerp/service/server.py", line 281, in app
return self.app(e, s)
File "/opt/odoo/openerp/service/wsgi_server.py", line 216, in application
return application_unproxied(environ, start_response)
File "/opt/odoo/openerp/service/wsgi_server.py", line 202, in application_unproxied
result = handler(environ, start_response)
File "/opt/odoo/openerp/http.py", line 1274, in __call__
self.load_addons()
File "/opt/odoo/openerp/http.py", line 1293, in load_addons
m = __import__('openerp.addons.' + module)
File "/opt/odoo/openerp/modules/module.py", line 79, in load_module
mod = imp.load_module('openerp.addons.' + module_part, f, path, descr)
File "/opt/odoo/addons/base_phone/__init__.py", line 23, in <module>
from . import wizard
File "/opt/odoo/addons/base_phone/wizard/__init__.py", line 23, in <module>
from . import number_not_found
File "/opt/odoo/addons/base_phone/wizard/number_not_found.py", line 25, in <module>
import phonenumbers
ImportError: No module named phonenumbers
The problem is just that I installed that module (phonenumbers) plus the py-Asterisk module without errors using pip install phonenumbers and pip install py-Asterisk and the error persists.
I noticed I have at least two versions of python installed (2.6 and 2.7) but both modules are installed at the same version from odoo (I can see the modules in the python2.7 cli when, for example, I write phonenumbers or search).
Has anybody any idea what is happening to me? I'd be gratefull for some specific response. Thanks.
Here the connector's page: OpenERP - Asterisk connector
Ok, my bad. During odoo instalation I created a virtual environment under the Odoo system user account which was used solely by the Odoo server so I just need to install these modules under that enviorment. This works for me:
First let’s switch from root to the odoo user, then create a new virtual environment called odoo and activate it:
su - odoo
/usr/local/bin/virtualenv --python=/usr/local/bin/python2.7 odoo
source odoo/bin/activate
(If you have the virtual environment created like me just ignore the second line). Before starting the module installation we need to add the path to the PostgreSQL binaries, otherwise the PsycoPG2 module install will fail (I ignored this one too):
export PATH=/usr/pgsql-9.3/bin:$PATH
Then I can do pip install... Thank you all for your help.

Django - rest framework errors when python runserver

File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/handlers.py", line 85, in run
self.result = application(self.environ, self.start_response)
File "/Library/Python/2.7/site-packages/dj_static.py", line 83, in __call__
return self.application(environ, start_response)
File "/Library/Python/2.7/site-packages/django/core/handlers/wsgi.py", line 255, in __call__
response = self.get_response(request)
File "/Library/Python/2.7/site-packages/django/core/handlers/base.py", line 178, in get_response
response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
File "/Library/Python/2.7/site-packages/django/core/handlers/base.py", line 220, in handle_uncaught_exception
if resolver.urlconf_module is None:
File "/Library/Python/2.7/site-packages/django/core/urlresolvers.py", line 342, in urlconf_module
self._urlconf_module = import_module(self.urlconf_name)
File "/Library/Python/2.7/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/Users/WillRedington/Desktop/Django Projects/propadev/propvocab/urls.py", line 3, in <module>
from rest_framework import routers
File "/Library/Python/2.7/site-packages/rest_framework/routers.py", line 23, in <module>
from rest_framework import views
File "/Library/Python/2.7/site-packages/rest_framework/views.py", line 11, in <module>
from rest_framework.compat import HttpResponseBase, View
File "/Library/Python/2.7/site-packages/rest_framework/compat.py", line 13, in <module>
from django.utils.six.moves.urllib import parse as urlparse
ImportError: No module named urllib
The server error message: [17/Dec/2014 16:26:45] "GET / HTTP/1.1" 500 59
This is checking if python returns the modules:
>>> import django.utils.six.moves
>>> import django.utils.six.moves.urllib
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named urllib
>>>
My current python version is 2.7.2, Django is 1.5.1, rest framework is in 2.7 site-package.
I have already tried uninstalling and reinstalling Django several times and get the same error.
This is running on Mac OS X 10.9.5, please help me, I've been at this for 5 hours.
it seems like a dependency error. Maybe you downgraded your django, or randomly installed the rest framework package without controlling the dependencies.
django.utils.six.moves.urllib doesnt exist in django==1.5.1 yet. You can try to upgrade django to 1.5.7 for example. Then this import will work. Other things might still be broken though, I can´t tell from here. If you post the output of pip freeze here, it may be easier to help.
You aren´t working in a virtual environment, which is dangerous for dependencies. Best is to make a virtualenv, then install your packages with pip, taking care of dependencies.
Then run:
pip freeze > requirements.txt
and use that file in the future like this:
pip install -r requirements.txt
and edit the file accordingly if you install, update or remove packages.
Something that might be of interest is this: it generally never works to uninstall and reinstall the same package several times; if it doesn´t work once, it won´t work the second time either.
As someone mentioned before my response wasn't really an answer. I solved this error and potentially many more by installing a python virtual environment. To do this run the following
sudo pip install virtualenv
Then create a new folder for your virtual environments. cd into the created folder.
cd myvirtualenv
Then create a new virtual environment by running the following:
virtualenv venv
To run the virtual env:
source venv/bin/activate
This makes a seperate environment with it's own site packages, which is essential for any python developer, especially when working on multiple projects.
Source: http://docs.python-guide.org/en/latest/dev/virtualenvs/

failed to install django-chronograph in django 1.7

I tried to install django-chronograph to django-1.7 for assigning scheduled task in my django web-app.
I followed the instruction as shown here but it gives me the following error when running python manage.py makemigrations or python manage.py syncdb:
user#(none):~/mysite$ python manage.py makemigrations
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 354, in execute
django.setup()
File "/usr/local/lib/python2.7/dist-packages/django/__init__.py", line 21, in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py", line 115, in populate
app_config.ready()
File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/apps.py", line 22, in ready
self.module.autodiscover()
File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/__init__.py", line 23, in autodiscover
autodiscover_modules('admin', register_to=site)
File "/usr/local/lib/python2.7/dist-packages/django/utils/module_loading.py", line 74, in autodiscover_modules
import_module('%s.%s' % (app_config.name, module_to_search))
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/usr/local/lib/python2.7/dist-packages/chronograph/admin.py", line 2, in <module>
from django.conf.urls.defaults import patterns, url
ImportError: No module named defaults
Is it django-chronograph not supported by django-1.7?
I've never heard of this package, but if you search for that error you will find that that import path hasn't worked since Django 1.6.
It could be that it's just the PyPI version that's old, and that the master branch works fine. However, the last commit to this package was in March 2013, and there's an open issue on the project's bitbucket page indicating that it fails to work on 1.6, so I doubt it.
In sum, it appears that this package supports neither Django 1.6 nor 1.7.
They already committed a fix, so to get rid of this error, don't go through:
pip install django-chronograph
I've just installed on Django 1.8 without issues (so far..) using:
pip install -e hg+https://bitbucket.org/wnielson/django-chronograph#f561106f6aaab62f2817e08e51c799320fd916d9#egg=django-chronograph