if i run
(My_Virtual_Env) G:\My-Project\My_Code>python ..\My_Virtual_Env\Scripts\django-admin.py startproject My_django_project
its working fine and new project is getting created.
But when i run
(My_Virtual_Env) G:\My-Project\My_Code>django-admin.py startproject My_django_project
am getting error
ImportError: No module named django.core
i want to know why it is happening ? and what are the changes need to do to run second command as it is ?
The My_Virtual_Env/Scripts folder is not added to the classpath by default. That is why you get that error. If you install django, the directory of this will directly be added to classpath. Why do you execute from another place?
Related
I have been working on a Django Project for a bit, until I took a break. One month later I dug back in to the project and went to run the server. I received an error:
django.core.exceptions.ImproperlyConfigured: Requested setting DEBUG, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
I figured I must have tweaked something by accident. So I created a brand new Django Project (using a virtual environment), and just went to test the server. I received the same error. I tried the python manage.py shell solution listed in another answers but to no avail.
If it helps I'm on Linux with Django version 2.1.5 and Python 3.6.
Edit:
If anyone encounters something similar I found using python3 manage.py runserver works in place of using django-admin. Per Greg's answer below, I did begin to receive a new error ModuleNotFoundError: No Module named "mysite" exists. I will continue to search for an answer on that front.
Going off of the comments here.
If "env | grep DJANGO_SETTINGS_MODULE" returns empty, it means you have to set an environment variable stating where your settings.py file is located.
This can be done by doing the following:
export DJANGO_SETTINGS_MODULE=mysite.settings
Be sure to replace "mysite" with the name of your app!
Trying to run a management command with no success.
Was getting an error in terminal ImportError, and in my IDE it would not resolve the models.
I found the answer and the issue was that I was not running the management command via manage.py.
The error in terminal would come up when running
../management/commands$ python import_puzzle.py
Instead of calling the management command directly from it's folder. You should run it from the src folder using manage.py:
`../src$ python manage.py import_puzzle`
The reason is that import_puzzle is actually a management command and must be called using the manage.py. I'm too much of a beginner to elaborate any further! :)
I'm trying to figure out if its possible to get django 1.3 running on heroku. I have been going off of their tutorial which assumes the user is using the latest version (1.4) of django. If I follow the tutorial, with the exception of explicitly using Django==1.3 instead of the most recent django version, I get an error when I run django-admin.py startproject hellodjango . (note the dot)
Error:
File "/home/my_dir/.virtualenvs/hellodjango/local/lib/python2.7/site-packages/django/utils/importlib.py", line 28, in import_module
raise TypeError("relative imports require the 'package' argument")
TypeError: relative imports require the 'package' argument
It still creates the project and the welcome page comes up on http://127.0.0.1:8000/. If I keep going with the tutorial and push it to heroku I get
ImportError at /
No module named hellodjango.urls
Seems like there is some mismatch between file structure between the tutorial and django 1.3.
Instructions on how to install Django 1.3 would be very helpful.
This '.' option don't work for me even with Django 1.4 i get same error as you did. So i ignored the dot:
django-admin.py startproject hellodjango
Then i moved all files from hellodjango folder to it's parent folder (that's what Heroku need) and deleted the hellodjango folder.
Followed all steps so i could get the app running on heroku but i got same error as you again, "No module named hellodjango.urls". I solved this removing this hellodjango part from settings.py as i changed the files to a new path so settings.py reflect that change now and everything is fine.
The '.' at the end of the ./manage.py startproject myproject . means start a project "in the current directory"(This feature was added in djago 1.4). In django 1.4 instead of importing from myproject import myapp, you just import yourapp directly. Your apps are not longer tied to your projects.
I found this article online that may help you solve your problem:
http://bitkickers.blogspot.com/2012/04/djangoheroku-quickstart-for-existing.html
I'm new to Django, and I can't figure out why my app isn't loading. I've created all the files: models.py, views.py, urs.py with default code in. But when I run python manage.py runserver, it says the following:
Error: No module named app_name
What am I doing wrong?
Did you remember to include __init__.py in your folder?
If you did, make sure the permissions on the file are also correct. There's also a similar question here.
Just an additional hint: Instead of manually creating the files you can use django-admin.py startapp APPNAME to automatically create a directory with all necessary files for a new app.
I got your point the init file thing also dosen't work out for me as well. Just ensure that are you writing the proper command inside the proper directory while creating the app, using the terminal.
Like while writing the command "django-admin startapp APP_NAME", ensure that the command is written inside your root configuration directory (which gets created after you typein command "django-admin startproject PROJECT-NAME"), not anywhere else. Then mention the app name inside the settings.py file, under the INSTALLED_APPS[ ] list. Then finally run the command "python manage.py runserver" in the same root configuration directory. I assure you, this will work for sure and the "No modules found" thing will disappear. Have a try and tell me if it don't. Thank you.
This is blowing my mind because it's probably an easy solution, but I can't figure out what could be causing this.
So I have a new dev box and am setting everything up. I installed virtualenv, created a new environment for my project under ~/.virtualenvs/projectname
Then, I cloned my project from github into my projects directory. Nothing fancy here. There are no .pyc files sitting around so it's a clean slate of code.
Then, I activated my virtualenv and installed Django via pip. All looks good so far.
Then, I run python manage.py syncdb within my project dir. This is where I get confused:
ImportError: No module named projectname
So I figured I may have had some references of projectname within my code. So I grep (ack, actually) through my code base and I find nothing of the sorts.
So now I'm at a loss, given this environment why am I getting an ImportError on a module named projectname that isn't referenced anywhere in my code?
I look forward to a solution .. thanks guys!
Is projectname exactly (modulo suffix) the name of the directory the project is in? Wild guess, but I know Django does some things with the current directory…
Also, what is trying to import projectname? Do you get a traceback? If not, try running with py manage.py --traceback syncdb and see what happens.