ImportError Django (but I think its because of python) - 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!

Related

I'm working on a django project and anytime i activate the virtual environment the server will not run

I use vscode and it does not highlight any error though...django is also added to path
This is the error
(myenv) C:\Users\GH\Desktop\Developments\The Blog\blogsite>python manage.py runserver
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 12, 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?
Sometimes it happens and I don't know why. A few things you can do:
always save your venv configuration: pip freeze > requirements.txt,
check if the packages "missing" are actually installed,
reinstall your virtual environment: deactivate and delete the old one, create a new one, then reinstall everything specified in requirements.txt (pip install -r requirements.txt)
Hope that helps!
The error says that Django is not installed in the current enviroment. Are you sure you activated your Virtual Enviroment?
Are you executing the server from terminal or from some VSCode interface? If so, try to execute directly from a terminal.
Also, it's not clear from your question if this is the first time you see the error. Did you grab this project from Git or somewhere else? Type pip freeze while Virtual Env activated and see the packages installed. Maybe you created the virtual enviroment but didn't installed the packages needed.

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.

Python 3.5 - Django -- virtualenv on shared folder -- Windows to Mac

I've created a virtualenv in Windows 7 on a shared folder so that I can work on it with other colleagues.
I set up the virtualenv to have python3.5 and installed Django but when I activate it from my mac I see python 2.7 and I cannot run the runserver command and I get this error as if Django was not installed.
(WebSite) UNKNOWN:myenv user$ python3 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'
I'm fairly sure it could be an easy fix, but cannot find a guide online that explains if Windows and Mac are "compatibles".

How to use Python 3 (3.5) as the default interpreter in my virtual environment?

I ran into problems when I installed Python 3.5 on Mac. I wanted to use Python 3.5 as the interpreter when I ran my Django development server. I got this issue when I tried it (I know I must install a virtualenv, read below):
$ python3 manage.py runserver
Traceback (most recent call last):
File "manage.py", line 7, in <module>
from mezzanine.utils.conf import real_project_name
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/Mezzanine-4.0.1-py3.5.egg/mezzanine/utils/conf.py", line 7, in <module>
from django.conf import global_settings as defaults
ImportError: No module named 'django'
The first was when I tried installing pip packages it installed by default on the Python 2.7 in my virtual environment:
pip install django==1.9rc2
Collecting django==1.9rc2
Downloading Django-1.9rc2-py2.py3-none-any.whl (6.4MB)
100% |████████████████████████████████| 6.4MB 66kB/s
Installing collected packages: django
Successfully installed django-1.9rc2
I use Django so I tried also install a virtual environment for the first time. First I tried it with pip, but that didn't work.
So how do I setup so that my Python3.5 is the default usage when using Python interpreter and in my virtual environment? I can't figure this out or I have done something wrong in my process.
Edit:
Thanks for the answer and comment. I tried with the both solutions and the same error persisted. See output below:
$ virtualenv -p /Library/Frameworks/Python.framework/Versions/3.5/bin/python3.5 Django/
Running virtualenv with interpreter /Library/Frameworks/Python.framework/Versions/3.5/bin/python3.5
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/virtualenv.py", line 14, in <module>
import shutil
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/shutil.py", line 10, in <module>
import fnmatch
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/fnmatch.py", line 15, in <module>
import functools
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/functools.py", line 21, in <module>
from collections import namedtuple
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/collections/__init__.py", line 16, in <module>
from reprlib import recursive_repr as _recursive_repr
File "/Library/Python/2.7/site-packages/reprlib/__init__.py", line 7, in <module>
raise ImportError('This package should not be accessible on Python 3. '
ImportError: This package should not be accessible on Python 3. Either you are trying to run from the python-future src folder or your installation of python-future is corrupted.
My virtualenv version: 13.1.2
Your error is related to a known virtualenv bug regarding python-future and mixing up the 2.7 and 3.x module paths, the solution is to downgrade virtualenv to a version < 12.04, 12.0.2 is suggested in the link.
Firstly, If you are going to use multiple versions of python,then you must use Virtual Env.Also then Create your virtualenv using the following command so that it uses python 3.5 as default environment :
virtualenv -p python3 envname
and then install django in the virtualenv.after activating your virtualenv

Error Running createsuperuser in virtualenv

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).

Categories

Resources