I installed python 2.6 alongside my mac's 2.5.2 version. As soon as I did, python2.6 manage.py runserver failed because it couldn't find django.core.management.
From a shell, import django returns importerror: No module named django.
Why?
Did you reinstall Django?
This happens when I install side by side versions of Python on Gentoo. Whenever I install a new version, I have to either reinstall the new ones or make a symlink to the old site-packages.
Because each installation of Python uses its own directory to store libraries. On a Mac, they are in /Library/Python/2.x/site-packages/. Presumably you originally installed Django in the 2.5 directory, but it isn't yet in the 2.6 one. You can symlink it there if you want to, or reinstall it using the new version.
Add site-packages to PYTHONPATH:
export PYTHONPATH="/home/jerome/bin/django-1.1/lib/python2.6/site-packages:$PYTHONPATH"
Worked on Ubuntu, with a python/django virtual environment using virtualenv and pip.
Source: http://benfsayer.com/importerror-no-module-named-django-core-management/
I use Bitnami's Django installer, and this happened for me when I wasn't in their custom shell, which I believe sets related python path environment variables. I ran ./use_djangostack in the root of the Bitnami package and then was successful running the server again.
Related
I have tried to create envelope on my linux pop os system using miniconda. When I activate it, I can install packages using pip, but when I run my django instance it doesn't find the modules.
If I type which python is shows the miniconda path correctly. I can look in the site-packages folder and see the packages installed.
I've tried installing django-anymail and corsheaders and they are both not being found. It does find my locally installed apps.
If I use the command line and open python and then import, it does not recognize my modules installed in the virtual envelope either. I thought it was a problem with conda, so I also created an envelope using python's native method: python3 -m venv
I have the same problem with it finding pip install site-packages.
Is there a command I can run to show all available packages?
I hadn't realized I had aliased my python. Now it is working.
I know that many have posted similar question however I tried most solution without success.
I'm trying to host a webpage with apache2 and django in python3.
In the error log I found ImportError: No module named 'django' when accessing the wsgi.pyfile, where I also added import sys, sys.version to confirm which python version is used and from the error log I can see that I'm running following python version 3.5.2 (default, Nov 23 2017, 16:37:01) [GCC 5.4.0 20160609].
When I run python3.5 I see that I uses the same python version and here I can run import django without any error!
EDIT: I checked django.__file__and saw that it was located in /home/USERNAME/.local/lib/python3.5/site-packages/django/init.py and that path /home/USERNAME/.local/lib/python3.5/site-packages wasn't in the sys.path that tried to run django. But adding it with sys.path.append(path) didn't help :(
Any thoughts what I might have messed up?
If you have Setup the whole configuration in VirtualEnv then , i suggest you to activate it by,
source /location to /env/bin activate
pip3 install django=version_id
or pip install django=version id
if you want to pass version id then its good or it will install the latest django from your repo.
Now test Django Version there.
Hope you will no get the error.
Location - means the path where env will be located in project directory, if you have followed the standard installation process of django or else you don't need, and version id- vesion of django framework.
I finally understood how to solve it! first I had to run pip3 uninstall django then run sudo pip3 install django.
I am trying to use chartit in django and in its documentation it says add chartit to INSTALLED APPS in "settings.py".
When I try to do that, it gives this error:
ImportError: No module named 'chartit'
How do I import it?
Thank you.
PS-Sorry, it's a silly question.
You missed installing it with pip install django_chartit.
EDIT:
The error you described is thrown by python if a module is not found in the running environment. You need to make sure, that you've installed it in the environment that is used by your django.
Try typing pip list in the shell you usually use to kick your django with python manage.py runserver to figure out what is installed there.
If your django lives inside of a IDE like PyCharm - you need to check the project settings there for the environment used to launch django.
As you don't use virtualenv (which is highly recommended) you install your modules system wide. If you are on linux there might be python3 and python (which is python 2). If your pip belongs to python2 and you have installed django in python3 or vice versa this might be the issue.
from chartit import DataPool, Chart
When using Pip (6.0.8) to install Django (1.9) and Psycopg2 (2.6.1), Django got installed in the env/lib/python2.7/site-packages folder and Psycopg2 in the env/lib64/python2.7/site-packages folder.
When I'm using command line (eg python manage.py migrate) or >>> import psycopg2, this all works fine. But when Mod_WSGI is running the application it complains that there is no module Psycopg2.
I'm able to work around this issue by adding the lib64 as a python path in my Apache conf file, but I'm pretty sure this is not the best possible way.
Any suggestions for a better solution?
Btw: I noticed by the way that Pip 7.1.2 is installing Django in Lib64 as well iso Lib.
Yes, there is with the use of --install-option. Have a look at the docs
I have installed Django after activating my virtualenv but still I am getting following error
from django.core.management import execute_from_command_line
ImportError: No module named django.core.management
If you already activated your virtualenv (source /path/bin/activate) then check if you have installed Django.
pip install django
With next command you can see if Django was installed.
pip freeze | grep django
Another thing that you can try is to remove first line (#!/usr/bin/env python) in the manage.py file.
You should check if django is installed
Activate your environment, then run the following command to see which version is installed :
python -c "import django; print(django.get_version())"
I am using virtual environment so I added this line in manage.py:
sys.path.append('./myvenv/lib/python3.5/site-packages')
in which myvenv is the name of my virtual environment and version of my installed Python is 3.5.
This solved my issued.
I found that I had Python 3.4 and 2.7 installed concurrently, and the pip install django==1.7 command automagically decided the Python 3.4 /dist-packages was where it should live. I CD'd over to the Python 2.7 directory and re-piped it... and all is well.
sudo pip install django --upgrade
worked for me, i am not having virutal environment by the way.
I had the same problem when I was running Django from inside a virtual environment and then using another terminal window ran the command
python manage.py shell without first switching to the venv.
The problem was resolved after I switched back.
I found that I could import the django module from the python interpreter, but django-admin.py could not import it when run from the command line.
I confirmed that I was using the python interpreter in my virtual environment.
I was using a 64-bit version of python. Uninstalling, and installing the 32-bit version, then re-creating my venv solved this for me.
If you're using virtualenv, you can add it to your path using sys.path.append('./myvenv/lib/python3.5/site-packages').
Try closing and opening the terminal again. That worked for me too.