I am following the following tutorial at http://flailingmonkey.com/install-django-justhost/ to install Django on my Justhost web server. So far I have managed to install Django and Python on my Justhost shared web server.
However, I am now stuck when trying to configure my new site. Every time I run the command: python mysite.fcgi I keep getting the following error message:
Traceback (most recent call last):
File "mysite.fcgi", line 9, in <module>
from django.core.servers.fastcgi import runfastcgi
ImportError: No module named fastcgi
Content of mysite.fcgi
#!/home4/xxxxx/python/bin/python
import sys, os
# Where /home/your_username is the path to your home directory
sys.path.insert(0, "/home4/xxxxx/python")
sys.path.insert(13, "/home4/xxxxx/public_html/django-project/admin")
os.environ['DJANGO_SETTINGS_MODULE'] = 'admin.settings'
from django.core.servers.fastcgi import runfastcgi
runfastcgi(method="threaded", daemonize="false")
How do I fix it?
I had the exact same issue. Heres how to solve it
load up your ssh client
cd ~/
pip install django==1.8.7
pip install flup==1.0.2
and you should be good
If you need FastCGI support for Django version 1.9 or higher, see https://github.com/NetAngels/django-fastcgi. You still need to install flup separately as #dvicemuse advised.
Also, official Django version 1.8 FastCGI docs may help, see https://docs.djangoproject.com/en/1.8/howto/deployment/fastcgi/#running-django-on-a-shared-hosting-provider-with-apache
Related
I am using "flask+nginx+uwsgi" for my website. Everything works fine at first.Then in order to transform my *.txt file to excel format, I install tablib in my environment and add just "import tablib" into my init.py , then I cannot access my website any more. Once I comment out "import tablib", it works again. And I notice the uwsgi.log, it tells me that:
> *** Operational MODE: preforking *** Traceback (most recent call last): File "./__init__.py", line 14, in <module>
> import tablib ImportError: No module named tablib unable to load app 0 (mountpoint='') (callable not found or import error)
> *** no app loaded. going in full dynamic mode ***
I check uwsgi setting carefully and i don't think it's uwsgi that create this error(because whenever I remove "import tablib", everything works perfectly). I also checked the installation of tablib, it was installed successfully. Can anyone give me a suggestion on how to fix this error? thanks a lot!
Are you running uwsgi as root? If so, running sudo -H pip install tablib in terminal should fix the issue for you. It is possible that you have installed tablib in your own profile, but not in the root profile.
I'm trying to deploy a hello-world type app on Elastic Beanstalk. Just about everything seems to work, packages are installed, etc. up to the point where mod_wsgi attempts to retrieve the "application" object from wsgi.py. At that point, the following appears in the logs (once in the logs for each unsuccessfuly HTTP request):
mod_wsgi (pid=6114): Target WSGI script '/opt/python/current/app/myapp/wsgi.py' cannot be loaded as Python module.
mod_wsgi (pid=6114): Exception occurred processing WSGI script '/opt/python/current/app/myapp/wsgi.py'.
Traceback (most recent call last):
File "/opt/python/current/app/caserails/wsgi.py", line 20, in <module>
application = get_wsgi_application()
File "/opt/python/run/venv/lib/python2.7/site-packages/django/core/wsgi.py", line 14, in get_wsgi_application
django.setup()
File "/opt/python/run/venv/lib/python2.7/site-packages/django/__init__.py", line 18, in setup
from django.utils.log import configure_logging
File "/opt/python/run/venv/lib/python2.7/site-packages/django/utils/log.py", line 16, in <module>
from logging import NullHandler # NOQA
ImportError: cannot import name NullHandler
Link to concurrent AWS Forum Post.
The NullHandler is only available on Python version 2.7+. You could create the NullHandler yourself on an ImportError:
import logging
try:
from logging import NullHandler
except ImportError:
class NullHandler(logging.Handler):
def emit(self, record):
pass
logging.getLogger(__name__).addHandler(NullHandler())
More information about logging.NullHandler: https://docs.python.org/3/library/logging.handlers.html#logging.NullHandler.
I had similar problem and in my case the issue was that for some unrelated project I created logging.py file in home folder and when I ran something in home, it was importing this file instead of the real module.
You can check which file is being imported like this:
import logging
print(logging.__file__)
I fixed it by deleting logging.py I created previously.
NullHandler was introduced in version 2.7. Are you sure you are running 2.7 on your server?
After much trial and error, the (immediate) problem was solved by removing python logging from requirements.txt and rebuilding the environment.
I do not yet fully understand why this is a problem. On my local machine, I'm able to install logging and run Django without error. I suspect as vikramls pointed out that something weird is happening in the intersection between mod_wsgi, the baselineenv in which mod_wsgi executes, and the virtualenv in which my app operates.
But, at least for now, I'm fixing this error by not including "logging" in requirements.txt when deploying Django 1.7 on Elastic Beanstalk.
I had this issue while creating a build for python 2.7 with PyInstaller.So, I uninstalled logger from my ENV.else you can also remove the package name from the requirement.txt.
This approach solves my issue [Happy Coding:)]
I'm working through a flask tutorial and am trying to run a script that creates a database instead of doing it through the command line. It uses the SQLAlchemy-migrate package, but when I try to run the script, it gives an ImportError.
This is the terminal output:
Sean:app seanpatterson$ python ./db_create.py
Traceback (most recent call last):
File "./db_create.py", line 2, in <module>
from migrate.versioning import api
ImportError: No module named migrate.versioning
This is the db_create.py script:
#!flask/bin/python
from migrate.versioning import api
from config import SQLALCHEMY_DATABASE_URI
from config import SQLALCHEMY_MIGRATE_REPO
from app import db
import os.path
db.create_all()
if not os.path.exists(SQLALCHEMY_MIGRATE_REPO):
api.create(SQLALCHEMY_MIGRATE_REPO, 'database repository')
api.version_control(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
else:
api.version_control(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO, api.version(SQLALCHEMY_MIGRATE_REPO))
This is the config file it references:
#!/usr/bin/env python
import os
basedir = os.path.abspath(os.path.dirname(__file__))
SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join(basedir, 'app.db')
SQLALCHEMY_MIGRATE_REPO = os.path.join(basedir, 'db_repository')
This application is being run with a virtual environment. This are the module that relates to it that I have installed in the environment:
sqlalchemy_migrate-0.7.2-py2.7.egg-info
Any help appreciated
pip install sqlalchemy==0.7.9
and
pip install sqlalchemy-migrate==0.7.2
and
optionally this flask-whooshalchemy==0.55a should solve the problem
ImportError: No module named migrate.versioning probably means the module is not installed. Make sure it has been installed in the correct virtual environment, it is activated (you ran the activate script in that environment) and the selected Python binary is actually making use of that environment (i.e. you are using Python2 and not Python3).
As said by #BoppreH earlier
ImportError: No module named migrate.versioning
means that the module named 'migrate' is not installed in your virtual environment or your system. First make sure that you are using the proper environment and that it is activated using the activate script.
I had the same problem and had the correct environment set up. But still the error was not solved.
What worked for me was installing the sqlalchemy-migrate package from pip. After activating my environment, I ran the following code to install it :
pip install sqlalchemy-migrate
flask/bin/pip install flask-sqlalchemy without defining the version worked fine for me.
run :
easy_install Flask-SQLAlchemy
to install Flask-SQLAlchemy
sudo pip install flask-migrate
to install flask-migrate
I think this error might pop up for several obscure reasons, I would like to add another which I experienced:
I had the same exact error while having sqlalchemy-migrate correctly installed, and guess what, it didn't work just because I had named the migration script file as migrate.py, this created some conflict with the migrate package.
In fact PyCharm warned me with this message:
"Import resolves to its containing file... This inspection detects names that should resolve but don't."
I renamed the migration script as db_migrate.py and everything started working fine.
I could understand what was the issue cause I had another project with an identical set-up but with migrate-sqlalchemy working perfectly and the only difference was indeed that file name...
Hope this might help someone one day...
I had the same problem - "No module named migrate.versioning", and everything is much easier than we are talking about, you need to perform the commands "run"
file: db_create.py or file: db_migrate.py if you using PyCharm (not from the terminal). And you will have the expected output: "New migration saved as D:...there is my path...\microblog\db_repositort/versions/001_migration.py
Current database version: 1"
Without any code changing, my django app started throwing an exception while loading the WSGI script. I'm using django 1.3 with python 2.7, and the top-level .wsgi is essentially unmodified from the default:
import os
import sys
from django.core.handlers.wsgi import WSGIHandler
os.environ['DJANGO_SETTINGS_MODULE'] = 'api.settings'
application = WSGIHandler()
It started producing these errors on any request, as reported by Apache:
mod_wsgi (pid=3283): Target WSGI script '/home/beder/webapps/api/api.wsgi' cannot be loaded as Python module.
mod_wsgi (pid=3283): Exception occurred processing WSGI script '/home/beder/webapps/api/api.wsgi'.
Traceback (most recent call last):
File "/home/beder/webapps/api/api.wsgi", line 4, in <module>
from django.core.handlers.wsgi import WSGIHandler
File "/home/beder/webapps/api/lib/python2.7/django/core/handlers/wsgi.py", line 10, in <module>
from django import http
File "/home/beder/webapps/api/lib/python2.7/django/http/__init__.py", line 122, in <module>
from django.utils.http import cookie_date
File "/home/beder/webapps/api/lib/python2.7/django/utils/http.py", line 7, in <module>
from email.Utils import formatdate
File "/usr/local/lib/python2.7/email/__init__.py", line 79, in __getattr__
__import__(self.__name__)
File "/usr/local/lib/python2.7/email/utils.py", line 27, in <module>
import random
File "/usr/local/lib/python2.7/random.py", line 47, in <module>
from os import urandom as _urandom
ImportError: cannot import name urandom
I restarted the server, and it now works normally (no errors). I'm at a loss for what to do - I want to make sure this doesn't happen again, but it's not happening now, and I have no idea why that import error appeared.
Are you executing Django inside a virtualenv? Did you updated or upgraded your system? If so and you upgraded to Python 2.7 from Python 2.6 for example you need to regenerate the virtualenv:
$ virtualenv [your-options] [your-django-project-directory]
For anyone using webfaction like Jesse and myself to run his django app but is not using virtualenv, it can happen that after the upgrade, the custom apache installation for the webapp was never restarted. This means that the stdlib changed but apache still uses python 2.7.2 because its the version it has loaded into memory.
The solution in this case is simple: login to your account via ssh and execute:
[username#webXX ~]$ ~/webapps/<webapp-name>/apache2/bin/restart
This restarts the web server and causes apache to reload the new interpreter binary.
I also found the same error when I updated Python 2.6.5 to 2.6.8, building from source. I also had built mod_wsgi from source, and initially forgot to recompile mod_wsgi for the new version of Python, and that led to the same error concerning urandom.
I have a ubuntu lucid VPS server where I try to run my django development server.
Running python manage.py runserver gives me the following error:
Traceback (most recent call last):
File "manage.py", line 2, in <module>
from django.core.management import execute_manager
ImportError: No module named core.management
I can import django without any problem in a python shell. I looked in the django install directory and noticed there is no \__init__.py in the django/core folder. Which I beleive is the source of the problem for python to register django.core as a module.
It then looks like an installation issue. I installed django using apt-get.
FYI the django install worked perfectly on my home computer with same OS.
Any ideas?
solved.
Thank you for all the suggestions. I installed django using the tar ball as instructed in the django website.
apt-get is not a good idea to install django. I also had to manually remove the left over django folder in /usr/lib/pymodules/python2.6 after using apt-get remove.