sto facendo questo su FedoraErrore: Impossibile importare impostazioni 'mysite.settings' dopo aver impostato virtualenv per Django
Problema:
(sandbox)[[email protected] mysite]# django-admin.py runserver
Error: Could not import settings 'mysite.settings' (Is it on sys.path?): No module named mysite.settings
Setup virtualenv
mkdir pythonenv # that's the /home/yeukhon/pythonenv/*.*
cd pythonenv
virtualenv --no-site-packages --distribute sandbox
Installa Django
pip install -E sandbox django
# changing mode of /home/yeukhon/pythonenv/sandbox/bin/django-admin.py to 755
# Successfully installed django
Under/home/yeukhon/pythonenv/sandbox
bin include lib mysite
Sotto lib
You have /lib/python2.7/site-packages/django/*.*
creare il progetto va bene
(sandbox)[[email protected] sandbox]# django-admin.py startproject mysite
# the path is now /home/yeukhon/pythonenv/sandbox/mysite/*.*
Non è possibile eseguire server di
django-admin.py runserver
Error: Could not import settings 'mysite.settings' (Is it on sys.path?): No module named mysite.settings
Python Shell sotto sandbox (seguendo questa guida: How to troubleshoot - ImportError: Could not import settings 'mysite.settings' when deploying django?)
(sandbox)[[email protected] mysite]# python
Python 2.7.2 (default, Oct 27 2011, 01:36:46)
[GCC 4.6.1 20111003 (Red Hat 4.6.1-10)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>> import os
>>> os.environ['DJANGO_SETTINGS_MODULE']
'mysite.settings'
>>> os.path.exists('/home')
True
>>> os.path.exists('/home/yeukhon/pythonenv/sandbox/mysite')
True
>>> os.path.exists('/home/yeukhon/pythonenv/sandbox/mysite/settings.py')
True
>>> from django.core.management import setup_environ
>>> import mysite.settings
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named mysite.settings
>>> setup_environ(mysite.settings)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'mysite' is not defined
>>> print sys.path
['',
/home/yeukhon/pythonenv/sandbox/lib/python2.7/site-packages/distribute-0.6.14-py2.7.egg',
'/home/yeukhon/pythonenv/sandbox/lib/python2.7/site-packages/pip-0.8.1-py2.7.egg',
'/home/yeukhon/pythonenv/sandbox/lib/python27.zip',
'/home/yeukhon/pythonenv/sandbox/lib/python2.7',
'/home/yeukhon/pythonenv/sandbox/lib/python2.7/plat-linux2',
'/home/yeukhon/pythonenv/sandbox/lib/python2.7/lib-tk',
'/home/yeukhon/pythonenv/sandbox/lib/python2.7/lib-old',
'/home/yeukhon/pythonenv/sandbox/lib/python2.7/lib-dynload',
'/usr/lib/python2.7',
'/usr/lib/python2.7/plat-linux2',
'/home/yeukhon/pythonenv/sandbox/lib/python2.7/site-packages'
Che cosa devo fare per risolvere questo problema? Grazie per il tuo tempo.
EDIT
Grazie per la risposta.
Ho provato quanto segue:
(sandbox)[[email protected] mysite]# export PYTHONPATH="/home/yeukhon/pythonenv/sandbox/"
(sandbox)[[email protected] mysite]# export PYTHONPATH="/home/yeukhon/pythonenv/"
(sandbox)[[email protected] mysite]# deactivate
[[email protected] mysite]# source ../bin/activate
(sandbox)[[email protected] mysite]# django-admin.py runserver
Error: Could not import settings 'mysite.settings' (Is it on sys.path?): No module named mysite.settings
>>> sys.path
['',.... '/home/yeukhon/pythonenv'.....]
E 'ora sul percorso pitone. Ma non riesco ancora a eseguire il server.
centralizzata Django Progetto
Sì. Questo è un buon suggerimento. Quindi suppongo che tutto ciò che devo fare sia "creare una directory chiamata mydjango, quindi creare progetti all'interno di mydjango". Ma quali comandi devono essere modificati/aggiunti? Sono disposto ad apprendere le buone pratiche.
Grazie mille.
Solution (Aggiungi variabile d'ambiente)
PYTHONPATH=$PYTHONPATH:path-to-your-directory
# PYTHONPATH=$PYTHONPATH:/home/yeukhon/pythonenv/sandbox/
Pratt. La ringrazio molto per il vostro tempo. Ho appena aggiunto il percorso a sys.path. Vedi la mia modifica. Forse l'ho aggiunto in modo errato? Senza fortuna. Grazie comunque. – CppLearner
Non puoi semplicemente aggiungerlo a 'sys.path'. Questo ha creato un runtime. Deve essere nella variabile di ambiente 'PYTHONPATH'. –
Hai ragione. Ho dovuto PYTHONPATH = $ PYTHONPATH:/home/yeukhon/pythonenv/sandbox /. Grazie. – CppLearner