django, python, postgres and web deployment - python

This error has been haunting me. I have actually developed fixes and I document it and I successfully run the server on the below IP address. I try to reproduce my success after reinstalling the Ubuntu OS... with the same errors the same fixes won't do it anymore... now I need outside help. I have combed the internet for solutions. I try to add django to the PYTHONPATH and it IS added but when I exit the python interpreter the appended django path disappears!
Another item of detail that may help is that my website www.doman.com/admin is directed to the django admin login screen. I tried to log in using username and password but it fails which makes me think django is not working properly.
$ sudo python3 manage.py runserver 192.165.4.3:80
I get the error:
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?
Django is installed within my environment:
$ django-admin --version
2.0.6
Python path attempt:
$ PYTHONPATH=/home/kap/dev_env/lib/python3.6/site-packages/django python
Python 3.6.5 (default, Apr 1 2018, 05:46:30)
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>> sys.path
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'sys' is not defined
>>> import sys
>>> sys.path
['', '/home/kap/dev_env/lib/python3.6/site-packages/django', '/usr/lib/python36.zip', '/usr/lib/python3.6', '/usr/lib/python3.6/lib-dynload', '/home/kap/dev_env/lib/python3.6/site-packages']
>>> quit()
Immediately confirm django is added but it disappeared:
$ python3
Python 3.6.5 (default, Apr 1 2018, 05:46:30)
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['', '/usr/lib/python36.zip', '/usr/lib/python3.6', '/usr/lib/python3.6/lib-dynload', '/home/kap/dev_env/lib/python3.6/site-packages']

sudo bypasses your virtual-environment it runs as a root user and django is not installed in root account. That is why it is throwing error .you can run without sudo or you can install django in your root account by
sudo python3 -m pip install django

Try this:
sudo python3 -m pip install django
Or if you have a requirements.txt
sudo python3 -m pip install -r requirements.txt
It is better to manage port 80 by nginx.

I actually solved it before anyone posted:
`pip install django`
is what I used. More specifically I used 'pip install django psycopg2 and gunicorn' since installing all three together seemed to fix another issue. I was using pip3 instead of pip. There are so many 'sensitivities' so that the order of installation, specific flags and package versions of installations can break or make the whole thing. I'm thinking of making a tutorial of the whole thing and putting a video online. Maybe I can set a link on this page.

Consider pipenv - git repo is here, with more information. Better control of packages, ease of deployment, and better control of virtual environments.

Related

How can I change my python path permanently?

I recently just installed Inkscape to my Windows 10 computer, and it changed my python path.
C:\Users\Chinyere\Documents\Django Files\Commercial>python
Python 3.8.9 (default, Apr 13 2021, 15:54:59) [GCC 10.2.0 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print(sys.path)
['', 'C:\\Program Files\\Inkscape\\lib\\python38.zip', 'C:\\Program Files\\Inkscape\\lib\\python3.8', 'C:\\Program Files\\Inkscape\\lib\\python3.8\\lib-dynload', 'C:\\Program Files\\Inkscape\\lib\\python3.8\\site-packages']
I can't run my Django files. When I try, it pops-up error
C:\Users\Chinyere\Documents\Django Files\Commercial>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?
Please, how can I change it to the default python path without uninstalling Inkscape.
First, you can try install the package again. If you can not install it again try to reinstall your python.
*Note: You should use virtual environment in python so it is easier to manage your library. After finished, you can note what library you use and install all the library by once.
py -m pip freeze
( Virtual Env: https://docs.python.org/3/tutorial/venv.html
Pip freeze : https://pip.pypa.io/en/stable/cli/pip_freeze/ )
Uninstall Inkscape and reinstall.
While reinstalling Inkscape, be sure to uncheck "add to path" if it is checked.

virtualenv - ModuleNotFoundError: No module named 'django'?

New to linux, I have install django in virtualenv, but i am not able to import django. Is there any variable path i need to set ?
(virs) akash#akash-Inspiron-3542:/usr/virs/bin$ django-admin --version
1.11.10
(virs) akash#akash-Inspiron-3542:/usr/virs/bin$ python
Python 3.6.4 (default, Jan 28 2018, 17:52:01)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'django'
You need to use manage.py if you want to access django library inside python shell.
Here's a little bit example.
Try:
django-admin startproject mysite
cd mysite
./manage.py shell
or
python manage.py shell
Here's what it looks like accessing django library inside python shell. In this case, I use IPython. If you don't have IPython installed, manage.py automatically using python shell.
In [1]: import django
In [2]: django.__version__
Out[2]: '3.0'
In [3]: django.get_version()
Out[3]: '3.0'
Please run this command and write result here.
whereis django-admin
probably! django-admin command run from out of virtualenv
run the command
pip install django

Ubuntu and Django, no module named 'django'

I have a problem with Django on Ubuntu. When I type python in terminal, terminal returns
Python 3.4.1 (default, Jun 2 2015, 15:13:43) [GCC 4.8.2] on linux
so it's allright. When I type admin-django.py version terminal returns 1.8.2
so it's still allright. But when I go with
python
import django
terminal returns:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'django'
I'm fighting with it whole day, I'm quite new to linux. Do you know any solution?
As a more general case I recomend you to start working with virtual environments. It is a very easy tool to manage diferent projects with their respective dependencies.
After opening the terminal. Type:
$virtualenv 'name of your virtual environment'
$cd 'name of your virtual environment'
$source bin/activate
Afterwards you could use pip install with no trouble.
I recommend you the following blogpost:
http://docs.python-guide.org/en/latest/dev/virtualenvs/

ImportError: No module named 'paramiko'

I have done through the other questions online here, and I feel that mine is different enough to warrant a new question.
So I have a Centos 6 box, which is running a small website for me, acts as an office git server and I am trying to configure Python3 on it.
So I followed the following these steps to set up python3 on the server. However it seems that I cannot import paramiko into my script.
I downloaded the paramiko rpm however I get this message:
When I try to import paramiko I get:
[root#GIT Python-3.4.2]# rpm -ivh /usr/lib/Python-3.4.2/Modules/python-paramiko-1.7.5-2.1.el6.noarch.rpm
Preparing... ########################################### [100%]
package python-paramiko-1.7.5-2.1.el6.noarch is already installed
When I run python3 directly:
[root#GIT inserv_health_check]# python3
Python 3.4.2 (default, Jan 21 2015, 06:28:04)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-11)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import paramiko
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'paramiko'
>>>
I am sure there is a simple solution to this problem perhaps the path is wrong, or I should have put a symbolic link in somewhere. Any help would be appreciated :)
Before anyone asks, which python output:
[root#GIT Python-3.4.2]# which python
/usr/bin/python
[root#GIT Python-3.4.2]# which pytho~n3
/usr/bin/which: no pytho~n3 in (/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin)
[root#GIT Python-3.4.2]# which python3
/usr/local/bin/python3
Thanks
You need to do pip install paramiko so that python sees that module. If you work on a virtual environment, you need to workon <env_name> first and then pip install the desired module.
type pip3 install paramiko
if you want to install it for python3

Mac OS 10.9's (Mavericks) deinstalled Django

After installing Mac OS 10.9 (Mavericks) the Django version is no longer installed or apparently the system can't find the right paths to make it runs. How can I repair this?
This are the errors I'm getting trying to run Django:
Python 2.7.5 (default, Aug 25 2013, 00:04:04)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named django
>>>
$ python manage.py
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
Did you install Django into your main Python directory? If so, the version of Python might have been upgraded. This might have wiped your central site-packages. If, so, just reinstall Django.
Alternatively, and more advisable, use virtualenv. This will create a separate Python environment (including site-packages for each project), preventing this (probably) from happening again in future.
Install VirtualEnv Systemwide then setup virtual env
Installing
sudo easy_install virtualenv
now create project folder and cd into that after that
virtualenv venv
. venv/bin/activate
then install django using pip
pip install django

Categories