I have a Django "project" that I have inherited, which I am developing in Eclipse. On my OS (windows 7 32 bit), I have Python 2.7.4 installed, likewise for my virtualenv. However, on my project (extracted from SVN) the Python version is 2.7 only.
This causes a conflict when trying to create another superuser (I do not know the original superuser name/password) where I get the message:
cannot import maxrepeat
How do I upgrade the python version located at:
c:\users\"username"\workspace\"project"\scripts
from 2.7 to 2.7.4?
Apologies if I have omitted some important details, or if I am asking the wrong question as I am newbie to Django/python development.
EDIT
Having spoken to a friend before referring back to these responses (thanks btw), he advised me to copy over the contents of the 'scripts' folder within my virtualenv to the folder:
c:\users\"username"\workspace\"project"\scripts
I did that, so in theory, they are both now running from python version 2.7.4.
However, when I run the script
python manage.py createsuperuser
I get the following FULL Traceback:
Traceback (most recent call last):
File "manage.py", line 10, in
execute_from_command_line(sys.argv)
File "C:\users\alecc\workspace\hub\lib\site-packages\django\core\management\__init__.py"
, line 453, in execute_from_command_line
utility.execute()
File "C:\users\alecc\workspace\hub\lib\site-packages\django\core\management\__init__.py"
, line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\users\alecc\workspace\hub\lib\site-packages\django\core\management\__init__.py"
, line 263, in fetch_command
app_name = get_commands()[subcommand]
File "C:\users\alecc\workspace\hub\lib\site-packages\django\core\management\__init__.py"
, line 109, in get_commands
apps = settings.INSTALLED_APPS
File "C:\users\alecc\workspace\hub\lib\site-packages\django\conf\__init__.py", line 53,
in __getattr__
self._setup(name)
File "C:\users\alecc\workspace\hub\lib\site-packages\django\conf\__init__.py", line 48,
in _setup
self._wrapped = Settings(settings_module)
File "C:\users\alecc\workspace\hub\lib\site-packages\django\conf\__init__.py", line 134,
in __init__
raise ImportError("Could not import settings '%s' (Is it on sys.path?): %s" % (self.SE
TTINGS_MODULE, e))
ImportError: Could not import settings 'hub.settings' (Is it on sys.path?): No module name
d hub.settings
I have checked the system variables and I'm sure my project is on the Python system path. I have also checked 'django.contrib.auth' is enabled in my INSTALLED_APPS in the settings.pyfile.
Edit 2
Many other posts suggest it's a cross over of Python versions. However when I check the version number using the command:
$scripts\python.exe --version
I get Python 2.7.4 for each installation (Project & virtualenv)
Based on this information:
File "C:\users\alecc\workspace\hub\lib\site-packages\django\conf\__init__.py", line 134,
in __init__
raise ImportError("Could not import settings '%s' (Is it on sys.path?): %s" % (self.SE
TTINGS_MODULE, e))
ImportError: Could not import settings 'hub.settings' (Is it on sys.path?): No module name
d hub.settings
It looks like your application is called hub? The problem here is that it's trying to import hub.settings - but it can't find it. So for some reason, your settings.py is not on the path.
You can check this by editing C:\users\alecc\workspace\hub\lib\site-packages\django\conf\__init__.py, and somewhere before line 134 you can put import sys; print(sys.path). Then check to see that the path where your settings.py file lives is available. If it is, something else weird is happening.
If not, just go ahead and pull those lines from the __init__, and try running manage from the same directory your settings file is in.
Related
I have a Django project running under Django 1.8.4 that I'm trying to upgrade to latest version of Django. Since I was still using Python 2.7 on a Debian 8 server, I first upgraded my server to Debian 9 and then I upgraded my Django project's virtual environment to Python 3.5.3 (the default version of Python 3 on Debian 9).
After I rebuilt the virtual environment to use Python 3, I ran the command 2to3 -w . in my project's root folder. 2to3 found and fixed 62 problems without any difficulties. I also have 216 unit tests and only two of them failed under Python 3.5.
I then went to my Django website and the site appeared to be working except that the forms that contain pull-down elements show "SomeThingobject" instead of the values from the SomeThing table. I ran a few SQL queries directly against the database and confirmed that my SomeThing lookup table is populated.
Now I want to run a Django queryset command in the Python shell like the following to see why my pulldowns are not showing my column values:
queryset=SomeThing.objects.all()
However, if I activate my virtual environment and try to run the command ./manage.py shell, I get the following error:
Traceback (most recent call last):
File "./manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/srv/https/my_project.com/venvs/0bc664fa2a7b562d0b7e42a7acb3f095fe5df3cf/lib/python3.5/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/srv/https/my_project.com/venvs/0bc664fa2a7b562d0b7e42a7acb3f095fe5df3cf/lib/python3.5/site-packages/django/core/management/__init__.py", line 330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/srv/https/my_project.com/venvs/0bc664fa2a7b562d0b7e42a7acb3f095fe5df3cf/lib/python3.5/site-packages/django/core/management/base.py", line 393, in run_from_argv
self.execute(*args, **cmd_options)
File "/srv/https/my_project.com/venvs/0bc664fa2a7b562d0b7e42a7acb3f095fe5df3cf/lib/python3.5/site-packages/django/core/management/base.py", line 444, in execute
output = self.handle(*args, **options)
File "/srv/https/my_project.com/venvs/0bc664fa2a7b562d0b7e42a7acb3f095fe5df3cf/lib/python3.5/site-packages/django/core/management/commands/shell.py", line 69, in handle
self.run_shell(shell=options['interface'])
File "/srv/https/my_project.com/venvs/0bc664fa2a7b562d0b7e42a7acb3f095fe5df3cf/lib/python3.5/site-packages/django/core/management/commands/shell.py", line 58, in run_shell
return getattr(self, shell)()
File "/srv/https/my_project.com/venvs/0bc664fa2a7b562d0b7e42a7acb3f095fe5df3cf/lib/python3.5/site-packages/django/core/management/commands/shell.py", line 41, in ipython
ip()
File "/srv/https/my_project.com/venvs/0bc664fa2a7b562d0b7e42a7acb3f095fe5df3cf/lib/python3.5/site-packages/django/core/management/commands/shell.py", line 34, in _ipython
from IPython import start_ipython
File "/srv/https/my_project.com/venvs/0bc664fa2a7b562d0b7e42a7acb3f095fe5df3cf/lib/python3.5/site-packages/IPython/__init__.py", line 48, in <module>
from .terminal.embed import embed
File "/srv/https/my_project.com/venvs/0bc664fa2a7b562d0b7e42a7acb3f095fe5df3cf/lib/python3.5/site-packages/IPython/terminal/embed.py", line 19, in <module>
from IPython.terminal.ipapp import load_default_config
File "/srv/https/my_project.com/venvs/0bc664fa2a7b562d0b7e42a7acb3f095fe5df3cf/lib/python3.5/site-packages/IPython/terminal/ipapp.py", line 30, in <module>
from IPython.core.magics import ScriptMagics
File "/srv/https/my_project.com/venvs/0bc664fa2a7b562d0b7e42a7acb3f095fe5df3cf/lib/python3.5/site-packages/IPython/core/magics/__init__.py", line 22, in <module>
from .execution import ExecutionMagics
File "/srv/https/my_project.com/venvs/0bc664fa2a7b562d0b7e42a7acb3f095fe5df3cf/lib/python3.5/site-packages/IPython/core/magics/execution.py", line 21, in <module>
import cProfile as profile
File "/usr/lib/python3.5/cProfile.py", line 22, in <module>
run.__doc__ = _pyprofile.run.__doc__
AttributeError: module 'profile' has no attribute 'run'
Now I do have an application named 'profile' in my INSTALLED_APPS. If I try to open the Python shell on my production server which is still using Python 2.7, the shell executes without a problem. It's only having this problem with Python 3.5. What's interesting is that my Django 1.8/Python 2.7 project contains .pyc files but now under Python 3, they're replaced with __pycache__/<filename>.cpython-35.pyc files.
I read the Django document Porting to Python 3 but it doesn't seem to allude to this problem. What do I have to do to make this Django project operate properly under Python 3.5? Is there perhaps something new in Python 3.5 that is having a conflict with my profile application or is it something else?
After much digging around in the Python code I surmised that the problem was being caused by the fact that one of my applications inside the Django project was called "profile" and this was conflicting with a profile module in the newer version of cPython in Python 3.5. After I changed the name of the application to "userprofile" I could start the shell without any problems. These two articles help me change the app's name:
Stackoverflow: How to change the name of a Django app?
How to Change Name of Django Application
I can't seem to get my manage.py script to recognize the django module. pip install req/dev.txt installs all of the modules I would expect it to into my my python virtual environment (stored at .venv).
I think I've narrowed it down to a problem with either my $PYTHON_PATH or with my pip requirements files. I've looped through sys.path, and I see that one of the values points to a folder in .venv that I can confirm contains the django module.
I'm unfortunately at a loss. I've searched through a dozen related questions on Stack Overflow and have yet to find a solution that works. Does anyone have any clues to point me in the right direction?
Error message:
$ python manage.py syncdb
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Users/nathan/www/myapp/.venv/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/Users/nathan/www/myapp/.venv/lib/python2.7/site-packages/django/core/management/__init__.py", line 312, in execute
django.setup()
File "/Users/nathan/www/myapp/.venv/lib/python2.7/site-packages/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Users/nathan/www/myapp/.venv/lib/python2.7/site-packages/django/apps/registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File "/Users/nathan/www/myapp/.venv/lib/python2.7/site-packages/django/apps/config.py", line 119, in create
import_module(entry)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
ImportError: No module named django
Contents of reqs/dev.txt
-r common.txt
django-debug-toolbar==1.3.2
Contents of reqs/common.txt
django==1.8
Fabric==1.10.2
ShopifyAPI>=2.1.5
Sphinx==1.3.1
celery>=3.1.20
django-compressor>=1.5
django-toolbelt>=0.0.1
jdcal>=1.0
kombu>=3.0.35
openpyxl==2.2.5
python-dateutil>=2.4.2
psycopg2>=2.5
requests==2.7.0
whitenoise==2.0
shippo==1.4.0
Contents of manage.py:
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myapp.settings.dev")
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
Problem solved after a good night's rest.
The issue was that my INSTALLED_APPS had a reference to kombu.transport.django, which seems to be a completely unnecessary dependency we added for celery. More information on that here: Celery, kombu and django - import error
How I discovered the solution, in case the debugging technique helps anyone else:
I started by diving into the stack trace. I (temporarily) modified the files in .venv/ to add print statements for the input variables until I found my first clue in populate() in .venv/lib/python2.7/site-packages/django/apps/registry.py
Printing through each entry in populate() allowed me to see that the package that was breaking was kombu.transport.django and NOT the django module proper. Deleting that entry from my INSTALLED_APPS solved the problem.
To cleanup I reverted the files in .venv/ by removing my print statements and I was off and running!
I once wrote an django app, named superlists, and settings was in superlists.settings. It was for tutorial, and I was changing differnt settings, little realizing what I was doing.
And now when i starting new django project - it tells me it could not import superlists.settings
I reinstalled Pycharm, django, python (both versions 2.7 and 3.3), deleted all virtual envs, deleted everything that might be connected to it several times... IT IS STILL THERE! on a new, clean version of python, which even dont have django - there is DJANGO_SETTINGS_MODULE in sys.path pointing to superlists.settings. Each new project on a clean, with default settings, version of pycharm, tells me that it cannot import superlists.settings.
I delete DJANGO_SETTINGS_MODULE pointing to that settings from sys.path from cmd - exit then watch again - its there.
Where it takes it? I got no idea.
here is traceback:
Traceback (most recent call last):
File "D:/Python27/Lib/site-packages/django/bin/django-admin.py", line 5, in <module>
management.execute_from_command_line()
File "D:\Python27\Lib\site-packages\django\core\management\__init__.py", line 399, in execute_from_command_line
utility.execute()
File "D:\Python27\Lib\site-packages\django\core\management\__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "D:\Python27\Lib\site-packages\django\core\management\__init__.py", line 261, in fetch_command
commands = get_commands()
File "D:\Python27\Lib\site-packages\django\core\management\__init__.py", line 107, in get_commands
apps = settings.INSTALLED_APPS
File "D:\Python27\Lib\site-packages\django\conf\__init__.py", line 54, in __getattr__
self._setup(name)
File "D:\Python27\Lib\site-packages\django\conf\__init__.py", line 49, in _setup
self._wrapped = Settings(settings_module)
File "D:\Python27\Lib\site-packages\django\conf\__init__.py", line 132, in __init__
% (self.SETTINGS_MODULE, e)
ImportError: Could not import settings 'superlists\settings.py' (Is it on sys.path? Is there an import error in the settings file?): Import by filename is not supported.
It turned out that I created new environment system variable DJANGO_SETTINGS_MODULE. So evident, but it almost cost me sanity.
Change the environment variable from
DJANGO_SETTINGS_MODULE=superlist.superlist.settings
To DJANGO_SETTINGS_MODULE=superlist.settings
or use an __init__.py in superlist
I am trying to follow this tutorial on getting tinymce working with django and zinnia. It's not working, so I am attempting to do "Testing" but get this error when I run django-admin.py syncdb. How do I fix this?
$django-admin.py syncdb
Traceback (most recent call last):
File "/usr/local/bin/django-admin.py", line 5, in <module>
pkg_resources.run_script('Django==1.5.1', 'django-admin.py')
File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 505, in run_script
self.require(requires)[0].run_script(script_name, ns)
File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 1245, in run_script
execfile(script_filename, namespace, namespace)
File "/usr/local/lib/python2.7/dist-packages/Django-1.5.1-py2.7.egg/EGG-INFO/scripts/django-admin.py", line 5, in <module>
management.execute_from_command_line()
File "/usr/local/lib/python2.7/dist-packages/Django-1.5.1-py2.7.egg/django/core/management/__init__.py", line 453, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/dist-packages/Django-1.5.1-py2.7.egg/django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.7/dist-packages/Django-1.5.1-py2.7.egg/django/core/management/__init__.py", line 263, in fetch_command
app_name = get_commands()[subcommand]
File "/usr/local/lib/python2.7/dist-packages/Django-1.5.1-py2.7.egg/django/core/management/__init__.py", line 109, in get_commands
apps = settings.INSTALLED_APPS
File "/usr/local/lib/python2.7/dist-packages/Django-1.5.1-py2.7.egg/django/conf/__init__.py", line 53, in __getattr__
self._setup(name)
File "/usr/local/lib/python2.7/dist-packages/Django-1.5.1-py2.7.egg/django/conf/__init__.py", line 48, in _setup
self._wrapped = Settings(settings_module)
File "/usr/local/lib/python2.7/dist-packages/Django-1.5.1-py2.7.egg/django/conf/__init__.py", line 134, in __init__
raise ImportError("Could not import settings '%s' (Is it on sys.path?): %s" % (self.SETTINGS_MODULE, e))
ImportError: Could not import settings 'testtinymce.staticfiles_settings' (Is it on sys.path?): No module named staticfiles_settings
Thank you.
I found out the django-tinymce documentation is outdated, i.e. partially wrong.
What I discovered is that different versions of tinymce and django-tinymce packages are not compatible.
I solved it adding some variables to my project/settings.py and altering the tinymce directory and file names.
django-tinymce urls.py had some hardcoded paths in it which assumed the directories were named "tiny_mce" when in reality they were named "tinymce", hence I had to rename them, or alternatively you can change the hardcoded paths in django-tinymce's urls.py.
# project setting.py
STATIC_ROOT = os.path.join(BASE_DIR, "static")
STATIC_JS_DIR = os.path.join(STATIC_DIR, "js")
TINYMCE_JS_ROOT = os.path.join(STATIC_JS_DIR, "tiny_mce")
TINYMCE_JS_URL = os.path.join(TINYMCE_JS_ROOT, "tiny_mce.js")
#TINYMCE_JS_ROOT = os.path.join(STATIC_JS_DIR, "tiny_mce")
#TINYMCE_JS_URL = os.path.join(TINYMCE_JS_ROOT, "tiny_mce.js")
A simple shutdown of the terminal, then restarting the app again fixed it for me (without needing to configure anything extra). I followed the instructions here:
pip install django-tinymce
Add tinymce to the INSTALLED_APPS of 'settings.py'
Add (r'^tinymce/', include('tinymce.urls')), to the urlpatterns in urls.py
Do a python manage.py syncdb (not sure if this is needed)
In terminal: $ export DJANGO_SETTINGS_MODULE='testtinymce.staticfiles_settings'
Do another python manage.py syncdb just in case and then a python manage.py runserver
I then received the error when I tried to open up the browser to: http://localhost:8000/admin/myapphere
I restarted the terminal, did a 'collect static' just in case, then did python manage.py runserver and it worked (I was able to see the new fields)
The latest version of tinymce has a different configuration.
instead of Importing HTMLField like
from tinymce import HTMLField
but rather
from tinymce.models import HTMLField
I'm new to python and django but wanted to start following some tutorials. I installed python, then django, and then the pydev plugin for eclipse. I created a new django project and tried running it. In eclipse I set up a run configuration for manage.py with argument runserver and it said "Validating Models" but never said anything else.
I tried running via command line also but got some errors that I didn't see in eclipse:
C:\Users\JP\workspace\mysite\src\mysite>python manage.py runserver
Validating models...
Unhandled exception in thread started by <function inner_run at 0x02851E30>
Traceback (most recent call last):
File "c:\Python27\lib\site-packages\django\core\management\commands\runserver.
py", line 48, in inner_run
self.validate(display_num_errors=True)
File "c:\Python27\lib\site-packages\django\core\management\base.py", line 245,
in validate
num_errors = get_validation_errors(s, app)
File "c:\Python27\lib\site-packages\django\core\management\validation.py", lin
e 22, in get_validation_errors
from django.db import models, connection
File "c:\Python27\lib\site-packages\django\db\__init__.py", line 75, in <modul
e>
connection = connections[DEFAULT_DB_ALIAS]
File "c:\Python27\lib\site-packages\django\db\utils.py", line 91, in __getitem
__
backend = load_backend(db['ENGINE'])
File "c:\Python27\lib\site-packages\django\db\utils.py", line 32, in load_back
end
return import_module('.base', backend_name)
File "c:\Python27\lib\site-packages\django\utils\importlib.py", line 35, in im
port_module
__import__(name)
File "c:\Python27\lib\site-packages\django\db\backends\mysql\base.py", line 14
, in <module>
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No mo
dule named MySQLdb
I assume it has something to do with my sql setup, but I'm not sure since it's a blank project and I haven't written any code yet. I'm more concerned with why nothing showed up in eclipse.
I'm just starting myself. Apparently there's a MySQLdb plugin (sorry if that's not the right term) that you need to use in addition to a standard MySQL install. This is so Python can communicate with MySQL.
It sounds like that you need to include the module in Eclipse System PYTHONPATH.
Go to Windows -> Preference -> Pydev -> Interpreter - Python.
After Select your desired python interpreters (if you have a virtual env), include your MySQL egg and all your other dependencies in your library.
It seems you don't have mysql installed. If you're only trying out django, you could use sqlite which ships with python. You can change the db backend in your settings.py file.