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"
Related
tutorial --- venv --- lib
--- include
--- bin
--- first
--- manage.py
my problem is , trying to open in pychrem and when i try to run the manage.py i have this error.
in terminal evreything work , but in pychrem not .
/usr/local/bin/python3.8 /Users/alekseyzgeria/Desktop/tutorial/manage.py
Traceback (most recent call last):
File "/Users/alekseyzgeria/Desktop/tutorial/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:**
File "/Users/alekseyzgeria/Desktop/tutorial/manage.py", line 22, in <module>
main()
File "/Users/alekseyzgeria/Desktop/tutorial/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?
Just go to your command line and type the following:
pip install django
You may have been running your Django project through a virtual environment, you could either download the framework to your main Python environment by running "pip install Django" in your terminal and continue your work however you could also locate your previous virtual environment and activate it by navigating to the venv directory (On Windows it should be your user folder) and running the activate script and then work from there. (If Django wasn't installed on that environment either run the same pip command from earlier)
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
I have a venv setup with Python 3.7 with several packages installed. I installed them using the UI in settings and the scripts run fine.
However, when I go to the Terminal window and try to run my script there there, it gives me an error message saying "No module named xxxx".
Running python3 run_glue.py, it curiously gives me the following error:
sh-3.2$ python3 run_glue.py
Traceback (most recent call last):
File "run_glue.py", line 27, in <module>
import torch
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/torch/__init__.py", line 79, in <module>
from torch._C import *
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/torch/_C.cpython-36m-darwin.so, 9): Library not loaded: /usr/local/opt/libomp/lib/libomp.dylib
Referenced from: /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/torch/lib/libshm.dylib
Reason: image not found
It seems that it is looking at a python 3.6 environment despite my virtual environment being 3.7. I checked my settings and I dont see why it would be looking at the python 3.6 environment.
Any thoughts here?
You need to activate your environment first:
sh-3.2$ source path_of_your_venv/bin/activate
You should now see an (env) before your bash prompt:
(env) sh-3.2$
Then you can check if python3 is correctly referencing the environment by which python3.
Alternatively, execute python3 directly from within your environment:
./path_of_your_venv/bin/python3 run_glue.py.
I would like to run the following project:
https://github.com/pyl0ne/flaskSaaS
At the 2nd step of executing causes the error
python manage.py initdb (if I run it like this it has no problem, but he have run it with python3 with no problem as well: https://youtu.be/NzmoPqte4V4?t=1623 )
I Do want to run it with python 3 so instead I use:
python3 manage.py initdb
To run it in python3 I have corrected in the code manage file:
ORIGINAL (tried with this one before): from flask.ext.script import Manager, prompt_bool, Shell, Server
Mine: from flask_script import Manager, prompt_bool, Shell, Server
based on: importerror: no module named flask.ext.script
I have tried to run it in PyCharm directly and checked the DE's interpreter all set to python 3.7 importerror: no module named flask.ext.script (It gives errors similar to the terminal)
Final Error:
Beli:flaskSaaS-master peterSimon$ python3 manage.py runserver
Traceback (most recent call last):
File "manage.py", line 1, in <module>
from flask_script import Manager, prompt_bool, Shell, Server #ORIGINAL: from flask.ext.script import Manager, prompt_bool, Shell, Server
ModuleNotFoundError: No module named 'flask_script'
You can get rid of confusion by using a virtual environment. So you only have one Python interpreter (version 3.x) and one pip version for this Python version:
git clone git#github.com:pyl0ne/flaskSaaS.git
cd flaskSaaS/
python3 -m venv venv
source venv/bin/activate
make install
python manage.py initdb
should work.
Check if make install actually installed flask_script.
If not, do pip install Flask-Script
and for python3
pip3 install Flask-Script
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