python2.7 manage.py runserver - python

I'm using python 2.7 and am having trouble running the server. I have entered
python2.7 manage.py runserver and got the following error message
Traceback (most recent call last):
File "manage.py", line 8, in <module>
from django.core.management import execute_from_command_line
ImportError: No module named django.core.management
I went into the manage.py portion of the app and can see that I have
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myesite.settings")
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
can someone please explain what I have done wrong or what I need to do?

Do you have the django package installed? go to your command line and type "pip list" and see if django is in the list.
If it is not, "pip install django" should allow you to download and install the package.

Related

Run django application on Background with PM2

Hello i have a django application which runs smoothly with python3 manage.py runserver. But to run it all time i need to use any process manager or manually create a service. I want to run it with pm2.
But problem occurs when i try to run the app with pm2 as a process. Below is my pm2 config file.
{
apps:
[{
name: "lab",
script: "/home/ubuntu/sample-django-app/manage.py",
args: ["runserver", "0.0.0.0:8080"],
exec_mode: "fork",
instances: "1",
wait_ready: true,
autorestart: true,
max_restarts: 5,
interpreter : "/home/ubuntu/venv/bin/python3"
}]
}
But the following error occurs
raise ImportError(
ImportError: Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment?
Traceback (most recent call last):
File "/home/ubuntu/sample-django-app/manage.py", line 11, in main
from django.core.management import execute_from_command_line
ModuleNotFoundError: No module named 'django'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/ubuntu/sample-django-app/manage.py", line 22, in <module>
main()
File "/home/ubuntu/sample-django-app/manage.py", line 13, in main
raise ImportError(
ImportError: Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment?
here I have installed Django and the app runs smoothly with
**`python3 manage.py runserver`** Any help with this? Is my config file okay or not?

Django & VSCode: can't create super user

I don't know why but I can't run any comands in the vSCode Terminal.
For example, when I try python manage.py createsuperuser I get an error that can't find Python. So I do py manage.py createsuperuser and then I get a syntax error saying that manage.py doesn't exist or something like that.
Anyone know why this is and how I could fix it?
UPDATE:
I currently have the following error:
Traceback (most recent call last):
File "C:\XXXXX\argon-dashboard-django\manage.py", line 13, in main
from django.core.management import execute_from_command_line
ModuleNotFoundError: No module named 'django'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\XXXXX\argon-dashboard-django\manage.py", line 23, in <module>
main()
File "C:\XXXXX\argon-dashboard-django\manage.py", line 15, in main
raise ImportError(
ImportError: Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment?
Here's my manage.py
import os
import sys
def main():
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'core.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
if __name__ == '__main__':
main()
So there seems to be an import error somewhere. And I tried it with my venv activated:
(env) C:\Users\valen\OneDrive\Bureau\DOCARET\Autres\argon-dashboard-django>py manage.py createsuperuser
Traceback (most recent call last):
File "C:\Users\valen\OneDrive\Bureau\DOCARET\Autres\argon-dashboard-django\manage.py", line 13, in main
from django.core.management import execute_from_command_line
ModuleNotFoundError: No module named 'django'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\valen\OneDrive\Bureau\DOCARET\Autres\argon-dashboard-django\manage.py", line 23, in <module>
main()
File "C:\Users\valen\OneDrive\Bureau\DOCARET\Autres\argon-dashboard-django\manage.py", line 15, in main
raise ImportError(
ImportError: Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment?
When I got the same issue in my windows machine..(probably occurred because I did some C drive repair)
I also can't able to run python manage.py runserver , I got the same error
ModuleNotFoundError: No module named 'Django'
I did the following steps.. to overcome my error:
On my main folder terminal Check If you have already a "requiremnts.txt" file skip this step else run this command: pip freeze > requirements.txt ,if it saves all your packages then only do other steps
Delete Venv folder from the main directory.
Again install virtual environments and activate Venv.
then run this command pip install -r requirements.txt this will install all your packages back.
Run again python manage.py runserver , It will work fine

Problems after run: heroku run python manage.py migrate

While I was deployed my django app in heroku, I run:
heroku run python3 manage.py migrate
and I get this messahe in my console:
File "manage.py", line 16
) from exc
^
SyntaxError: invalid syntax
my manage.py file is actually:
#!~/.virtualenvs/djangodev/bin/python
"""Django's command-line utility for administrative tasks."""
import os
import sys
def main():
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myApp3.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
if __name__ == '__main__':
main()
When I run python => python3, the next message is displayed:
Traceback (most recent call last):
File "manage.py", line 10, in main
from django.core.management import execute_from_command_line
ModuleNotFoundError: No module named 'django'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 21, in <module>
main()
File "manage.py", line 16, in main
) from exc
ImportError: Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment?
You need to set up a virtual enviorment first. Then install django in the virtual environment. You can do this through a thing called pipenv. you need to add this to your project by doing. python install pipenv. Then install python in that virtual enviorment by doing pipenv install django. when django installs you can then do your migrations.

twisted module not found error from Python Flasky

I am having trouble in running a flask file that is manager.py on Windows 10. Although I installed requirements, it still aborts an import error.What's funny is the errors are different in PyCharm and cmd. And I activated the same virtual environment.I will appreciate it if someone can help me!
In PyCharm:
Traceback (most recent call last):
File "C:/Users/Administrator/Desktop/Online-serial-debugging/manage.py", line 6, in <module>
from app import create_app
File "C:\Users\Administrator\Desktop\Online-serial-debugging\app\__init__.py", line 2, in <module>
from flask.ext.twisted import twisted
File "C:\Users\Administrator\Desktop\online\Online-serial-debugging\enve\lib\site-packages\flask\exthook.py", line 87, in load_module
raise ImportError('No module named %s' % fullname)
ImportError: No module named flask.ext.twisted.twisted
Process finished with exit code 1
In CMD:
(enve) C:\Users\Administrator\Desktop\online\Online-serial-debugging>python manage.py
Traceback (most recent call last):
File "manage.py", line 5, in <module>
from flask.ext.script import Manager
ImportError: No module named flask.ext.script
Here are my requirments.txt:
construct==2.5.2
dominate==2.1.16
Flask==0.10.1
Flask-Bootstrap==3.3.5.3
Flask-Moment==0.5.0
Flask-Twisted==0.1.1
Flask-Script==2.0.5
itsdangerous==0.24
Jinja2==2.7.3
MarkupSafe==0.23
observable==0.1.0
pyserial==2.7
six==1.10.0
Twisted==15.4.0
txsockjs==1.2.2
pypiwin32
Werkzeug==0.10.4
zope.interface==4.1.2
Please fix your import statement as follows, and could you try?
from flask_script import Manager
EDIT
Sorry, even using flask.ext.{}, it seems still works.
If you run the following command, what come back?
pip install Flask-Script==2.0.5
It means that 'Flask-Script' was not installed, check your 'pip freeze'.
Was there any error when installing the requirements? If so, try to identify the issue.
Try installing it:
$ pip install Flask-Script
OK. The problem is solved.orz. My command line is :
python manage.py
Actually, I used the Python interpreter in system path by mistake.And I run this command :
./enve/Scripts/python.exe manage.py
There are no import errors again, thank you who answered me still.

Satchmo clonesatchmo.py ImportError: cannot import name execute_manager

I get satchmo to try, but I have a great problem at first try, and I don't understand whats wrong.
When I making $ python clonesatchmo.py into clear django project, it trows an error:
$ python clonesatchmo.py
Creating the Satchmo Application
Customizing the files
Performing initial data synching
Traceback (most recent call last):
File "manage.py", line 18, in <module>
from django.core.management import execute_manager
ImportError: cannot import name execute_manager
Traceback (most recent call last):
File "manage.py", line 18, in <module>
from django.core.management import execute_manager
ImportError: cannot import name execute_manager
Error: Can not copy the static files.
Error: Can not syncdb.
AND creates a store folder.
trying smth like this is working!!:
$ python manage.py shell
>>> import os, sys
>>> print sys.executable
/some/path/to/python
>>> os.system('bash')
$ /some/path/to/python manage.py validate
# this is NOT fail on "from django.core.management import execute_manager"
I have Django 1.6 and Satchmo 0.9.3, python 2.7.5
(I do not use virtualenv)
Replace the contents of manage.py with the following (from a new django 1.6 project).
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "<app>.settings")
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
execute_manager was put on the deprecation path as part of the project layout refactor in Django 1.4 https://docs.djangoproject.com/en/1.4/releases/1.4/#django-core-management-execute-manager. Per the deprecation policy that means that the code for execute_manager has been completely removed in 1.6. If you are seeing this import error then the version of Satchmo you are using has not been updated to be compatible with Django 1.6.

Categories

Resources