After source ./bin/activate, on doing a which python3.5 I get the following response
/path/to/virtualenv/bin/python3.5
I am using Django 1.10.5 which according to their documentation supports Python 3.5. But on doing python3.5 manage.py runserver, I get the following 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'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 14, in <module>
import django
ImportError: No module named 'django'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 17, in <module>
"Couldn't import Django. Are you sure it's installed and "
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?
My project works perfectly fine with the default python 3 (3.4) in my Ubuntu 14.04 system. What is the issue here?
If it's any help, I followed this process to install python 3.5. I did not remove the existing python3 from the machine as given in the end of the answer. I have both python3 and python3.5
After some digging, it seems we are not able to add a new Python version into an existing virtualenv. So, I created a new virtual environment using the command
virtualenv -p python3.5 project-name
Here -p specifies which python you want in the environment. Although the default python and python3 are also included, which is a good thing.
I then copied my existing django project there, and installed all the dependencies with pip3 install -r requirements.txt. I used pip3 because I am using python3.5.
After this, doing a python3.5 manage.py runserver worked like it's supposed to. Hope this helps someone.
It seems like you have not installed django in the virtual environment.
You need to install all the dependencies in your virtual environment.
try using pip:
pip install Django
you can find more details here https://docs.djangoproject.com/en/1.10/topics/install/.
Related
I'm at my first experience with django and I'm having already a little obstacle: I've menaged to create and use a virtual enviroment successufully yesterday, but today I can't seem to be able to reload it. This is how I'm doing it:
cd /c/website
python -m venv virt
spurce virt/scripts/activate
cd /c/website/project
python manage.py runserver
And this is the error I'm getting
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?
(virt)
before doing some mistakes, do I need to reinstall django everytime or I'm just messing up the procedure to reload the ve I created?
Thanks for your help!
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 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
Can anyone help me with following problem? I encountered that during one of the courses I am taking.
I use ios Catalina 10.15 therefor I use zhs as bash is no longer supported by mac
I am trying to run virtual server so I can see my webpage
I managed to run the virtual server once only (python manage.py runserver) and after the restart I have problem with it eversince.
> first_proj 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 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?
when I check for django (django-admin --version), turns out it is installed, I am getting this ouput:
2.2.5 (version of Django installed).
my django directory is: /Users/myname/opt/anaconda3/envs/projectname/lib/python3.8/site-packages/django
maybe it is something about the directory django is installed (?)
thanks for any help.
First of all I recommend you to install Anaconda in /opt/anaconda3, not in /somepath/opt/anaconda3. And when you install it, accept the auto-init.
Second, Zsh and Anaconda must be configured separately so they can work together. Add Anaconda to your paths (/etc/paths). You can check to see if everything is going well by applying any conda command:
$ conda info -e
Third, remember to activate your environment before applying runserver.
$ source activate <conda-env-name>
Using this command, you can see all the libraries installed in your environment: (and check if django is there)
(<conda-env-name>) username#mac: ~ $ conda list -e
And then make runserver:
(<conda-env-name>) username#mac: ~ $ python3 manage.py runserver
When I create a new project in Google Cloud Console and just try to run
pip
I get this error:
Traceback (most recent call last):
File "/usr/local/bin/pip", line 5, in <module>
from pkg_resources import load_entry_point
File "/home/sguergachi/.local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 70, in <module>
import packaging.version
ImportError: No module named packaging.version
I'm not sure how to fix this. Reinstalling doesn't seem to be an option for google cloud as it would for local environment.
It seems to be able to do anything in pip on GCP you need to run as sudo.
sudo pip
This fixed my issue.
First, pip and python are for Python 2; pip3 and python3 are for Python 3. Prefer Python 3 as most apps are finally getting away from Python 2.
Install Python apps in your $HOME folder, which persists across your GCP time/space continuum:
pip3 install --user <app>
Note you'll want to add ~/.local/bin to your PATH environment variable, discussed at length in https://unix.stackexchange.com/a/26059/46798, by adding the following to ~/.profile:
# add local Python apps to PATH
if [ -d "$HOME/.local/bin" ] ; then
PATH="$HOME/.local/bin:$PATH"
fi
In centos 6.7 python 2.6 is pre installed. I installed django==1.7.0.
But while running server i am getting a issue:
python manage.py runserver
Traceback (most recent call last):
File "manage.py", line 10, in <module>
from django.core.management import execute_from_command_line
ImportError: No module named django.core.management
After that i installed python2.7. I just need to know is there any way so that i ll set the path of python version in manage.py
May be any lead to find out the solution.
anyone having any idea?
Thanks
Probably you are not using the correct python version where you installed django.
You can check your python versions on system with command:
ls /usr/local/lib | grep python
normaly if you don't have more than 1 instalation of python 2 and one of python3 pip installs on python2 and pip3 installs on python3
you can set the new virtualenv by setting the path of python you want to use
virtualenv -p /usr/bin/python3.4 <project_name>
If you are using Django 1.7 you probably want to use
python3 manage.py runserver
I am trying to use virtualenv.
I installed it on my ubuntu system followed simple steps given here
but when I activate my virtual environment and try to do
$ python manage.py runserver
it throws 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
I tried to see if django is accessible from my virtual env so it tried to
$ python
>>> import django
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named django
and the same import django works fine out of the virtualenv.
I also tried to delete the django folder from root python setup and reinstalling it. but all in vain, the problem is still the same. What should I do now ?
PS: I tried to run easy_install Django & easy_install django gazillion times from the virtual env everytime it says django is already their.
PPS: I dont know if it is of importance but their was a django installation present prior doing all this in the system.
Check your manage.py, the first line needs to define the python executable, usually #!/usr/bin/env python. This should be the path to the python executable in your virtualenv and not to the global executable. If you had installed Django system wide this wouldn't be a problem.
Just in case
virtualenv venv
source venv/bin/activate
python manage.py runserver
[Adding this info for Windows users who hit the same problem]
If you're running into this problem on Windows then make sure that your virtual env is active (your prompt will be something like (venv) d:\myproject) and that you're running python.exe explicitly.
On the latter point, do not run py.exe (the Python Launcher introduced in 3.3) or rely on a .py file association to run Python. Both of those will run a version of Python outside of your virtual env and therefore will have the wrong site-packages.
If your virtual env has django 1.8.6 but your core Python installation does not have django, then:
python -c "import django;print(django.get_version())" will work and print 1.8.6
py -c "import django;print(django.get_version())" will fail with "ImportError: No module named django"