Python path issue with django - python

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

Related

How can I fix a problem with runing conda django virtual enviroment?

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

How to run GitHub Code quickly when your environment missing modules?

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

Pip install is not working with python but working with python2

I have an issue with Python on my Mac with High Sierra.
After running pip install pysal, I have a successful installation. However, the module is not found when I run in python:
> import pysal
Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: No module named pysal
I do not face such errors when running the same command in python2. However, most of my python scripts call the interpreter at the beginning of the file with #!/usr/bin/env python, so I would prefer not having to rely on python2 (I don't know how to do it either).
I figured out that this is python's executable is not on the same location where pip installs the modules:
macbook-pro-3:~ ME$ which -a python
/usr/bin/python
macbook-pro-3:~ ME$ which -a pip
/usr/local/bin/pip
I tried to follow the solution proposed by #J0ANMM in Modules are installed using pip on OSX but not found when importing . It recommeds downloading the script get-pip.py and executing it with sudo /usr/bin/python get-pip.py. I tried, but it did not change anything (the previous which commands still yield the same thing).
How do I manage to make pip work with my version of python?

How to run Django with Python 3.5?

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

django wont show up in virtualenv

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"

Categories