Error Running createsuperuser in virtualenv - python

I have a Django project, that's already been deployed. I'm using a virtualenv for the project and have installed django in it. I have activated the virtualenv.
When I type pip freeze I get:
Django==1.7.1
django-jalali==1.1
django-multiselectfield==0.1.3
jdatetime==1.3
But when I try this command: python3 manage.py createsuperuser I get the following error:
(.env)benyamin#i-bmn:/srv/bmn-reg$ python3 manage.py createsuperuser
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'
(.env)benyamin#i-bmn:/srv/bmn-reg$
How can I fix this?

Check whethere pip is using python3 by issuing the following command:
pip -V
You may need to use pip3 or pip3.x to install packages into Python 3.x environment if pip is using Python 2.x.
UPDATE
You're using virtualenv, you should use python (which references proper python executable), not python3 (probably references system version of python 3.x).

Related

./runtests (in django) ImportError: cannot import name 'NullTimeKeeper'

The following command was executed in the tests directory inside the development version of django
./runtests.py
Traceback (most recent call last):
File "./runtests.py", line 26, in <module>
from django.test.utils import NullTimeKeeper, TimeKeeper, get_runner
ImportError: cannot import name 'NullTimeKeeper'
I am using python 3.8 and am following the instructions for contributing to django from https://docs.djangoproject.com/en/3.1/intro/contributing/ where I have resolved all errors up to this point. Could someone explain what I would have to do as I already ran
python3.8 -m pip install -r requirements/py3.txt
in my virtual environment that I created using
python3.8 -m venv /path/to/venv
Never mind I found the answer. It is solved by configuring python3 to 3.8 version instead of 3.6 in the following link configuring python and then executing all of this in the virtual environment.

ImportError Django (but I think its because of python)

I working in a project that uses python 3.6.9 and django 3.1.1 using it on a virtual enviroment with virtualenv, somerall python in my computer updated to the version 3.8.2 (I think it's because i updated ubuntu to 20.04 version) and somerall changed the virtual enviroment too , and now i can't even run the server.
this is the steps that i do:
source bin/activate
in the folder of my project i do that:
python manage.py runserver
but It keeps given this error:
Traceback (most recent call last):
File "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 "manage.py", line 22, in <module>
main()
File "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?
if I enter this comand on virtual environment:
$ python3 --version
//gives:
Python 3.8.2
to solve this i tried some think's like:
installing python 3.6.9 with requirements.txt
pip install -r requirements.txt
but it didn't localizate the command pip
soo i tried with pip3
pip3 install -r requirements.txt
but it didn't work again..
if I miss some information about the problem please tell me...
I new here!

Django: python3 manage.py migrate ModuleNotFoundError: No module named 'django'

i'm a total noob in django so go easy on me..
i tried to run these commands on ubuntu terminal and gave me the same error
python3 manage.py migrate
python manage.py makemigrations MyAppName
python manage.py migrate
python manage.py syncdb --all
error message:
Traceback (most recent call last):
File "manage.py", line 8, in <module>
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 14, in <module>
) 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?
and i was told that i should never edit manage.py
update: i manged to run the project and made some modifications on it.
Django is not installed, use this comamnd to install it:
pip install django
Just do a check of all modules installed using command - pip list
If it does not show django in the list of modules install it using - pip install django
If it shows django in the list then the version of django installed may not be compatible with the version of python you are using. You can try installing a compatible version of django.
Also, you can create a virtual environment and install django inside the environment.

Installed Django with Pip but Python cant find it

I am trying to install django, but I am not sure how to proceed. I think I have installed django, but python python doesn't seem to be able to seethe package.
$ sudo pip install django
Requirement already satisfied (use --upgrade to upgrade): django in /usr/local/lib/python2.7/site-packages
Cleaning up...
$ python -c "import sys; sys.path = sys.path[1:]; import django; print(django.__path__)"
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named django
How do I fix this? When I try to run the server I get this error
$ python manage.py runserver
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
Your pip is using a different version of Python than your python. Check the output of these commands:
pip -V
python -V
python -c 'import sys; print(sys.path)'
There can be multiple versions of Python and Pip installed in your system.
For example in a Bash shell if you type python + Tab a few times it will show you the available Python binaries on your PATH, for example python2.7, python3.4, and similarly for pip + Tab too.
It depends on your system how to configure correctly so that both python and pip are using the same versions.
It would be best to use virtualenv. You wouldn't have such problems, as in a virtualenv your Python version and Pip version would be well synchronized.
Judging by your command output, pip is using Python 2.7. One quick fix could be to try running Django like this:
python2.7 manage.py runserver
Or, to run the pip version corresponding to your default Python version.
This "quick fix" is a dirty fix. It would be best to use virtualenv.

Python Error: No module named django.core.management

First time here!
And first time with Django also!
I read same issue here on StackOverFlow, e.g: Django:No module named django.core.management but without any result
Purpose:
Install a Django app (based on 1.5.1 on windows 8
I have + tested (e.g: pip --version):
Python 2.7
Pip 1.5.6
Virtualenv 1.11.6
I followed the instructions, and when I run:
python manage.py runserver
P.S:
I created my env,
$ virtualenv --distribute myenv
and activate it using:
source myenv/Scripts/activate
I got this error:
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
Any help how to debug the issue?
PPS: Please read the comments bellow!
Regards
You don't have django installed in your virtual environment.
Just do this: pip install django
In your case, to make sure the right one pip is used: env/Scripts/pip install django
Virtual environment is isolated "python + packages folder", so you need to install your packages again, but for this virtual evironment.
It is obvious, because you have exception at 8 line of manage.py, which tries to import special django function to run command-line commands.

Categories

Resources