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/
Related
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.
To install sklearn, I installed miniconda in my win10 computer, and in the Anaconda command line, I input:
(C:\Python\Miniconda3) C:\Users\apple>conda install sklearn
and it shows that install successfully
(C:\Python\Miniconda3) C:\Users\apple>conda install scikit-learn
Fetching package metadata ...........
Solving package specifications: .
# All requested packages already installed.
# packages in environment at C:\Python\Miniconda3:
#
scikit-learn 0.18.1 np113py36_1
There are python 2.7 and python 3.6 in my computer, and the default environment is python 3.6. However, I found that there is no sklearn in my python 3.6, when I input this order in python 3.6 command line:
Python 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 08:06:12) [MSC v.1900 64
bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> import sklearn
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import sklearn
ModuleNotFoundError: No module named 'sklearn'
and I input the same order in python 2.7 command line, there is also:
>>> import sklearn
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
import sklearn
ImportError: No module named sklearn
however in conda command line, it shows the sklearn has been installed successfully.
Could you please tell me the reason and solve it?
NOTE: It is normally inadvisable to have multiple installations of Python; use virtual environments instead if you require the use of different Python versions.
First, check which python version are you using in the command prompt.
python --verison
It should display Miniconda somewhere in your version information. If not, then it would mean that your python is executing in a different path. You would have to set the PATH variable to point to the location where the Miniconda executables are stored.
Explanation:
Usually, when a fresh installation takes place in Windows, the path for the executables is appended to the PATH variable. Using conda would use the Miniconda (or Anaconda) executables because the normal Python installation would not contain it. If you have multiple installations, your python command would point to the executables of the distribution initially installed and not Miniconda (where you have successfully installed sklearn).
You would have to go to the Environment Variables settings to change the order of the installation.
So i wanted to use the Quandl package to learn some data processing. I installed Quandl in the pycharm package, and it worked out pretty well.
import Quandl, math
and then, i use the Quandl to get some data from the internet
data = Quandl.get('some form of data')
But then when i tried to run the python script
bash-3.2$ python Regression.py
Traceback (most recent call last):
File "Regression.py", line 2, in <module>
import Quandl, math
ImportError: No module named Quandl
In my Pycharm interpreter, i have 4 different types:
-2.7.11 (/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/bin/python2.7) I installed Quandl here
-3.5.1 (/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/bin/python3.5) I also installed it here
-2.6.9 (/System/Library/Frameworks/Python.framework/Versions/2.6/bin/python2.6) It has an error to install packaging tools
-/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7 Permission denied for installing
When i tried to import Quandl in the terminal through python shell, i also retired an error
Python 2.7.10 (default, Oct 23 2015, 19:19:21)
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import Quandl
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named Quandl
I also tried the same thing for Simple CV, it also says that it's not in the module, even though I've already installed it both in 3.5 and 2.7.
from SimpleCV import Camera
cam = Camera()
while True:
img = cam.getImage()
img = img.binarize()
img.drawText("Hello World")
img.show()
bash-3.2$ python simplecv.py
Traceback (most recent call last):
File "simplecv.py", line 1, in <module>
from SimpleCV import Camera
ImportError: No module named SimpleCV
For installing 'pip', i also had an error installing it in the Pycharm terminal. I've already asked a question about it Installing pip in Pycharm 2016.3
Try to install it using pip2.7. I suspect that you are trying to execute the script with python3 (python command), however, your python interpreter in pyCharm is python2.7.
If you keep getting errors I suggest you to research a bit about virtualenvs, as it can help you had your several dependencies and interpreters easly organized by proyect. (PyCharm has support for virtualenvs)
When you invoke "python" in your console it launches the default Python interpreter (in your case Python 2.7.10). Looks like in PyCharm you selected different interpreter and installed packages on it. Make sure you use the same interpreter in PyCharm (Settings | Project | Project interpreter)
I installed django using pip install django==1.5.4 and I see it in the following directory:
/usr/local/lib/python2.7/site-packages/django
however, when I type in python and then say import django, I see the following output:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named django
Is there anything else I can/need to do? I tried to uninstall and reinstall several times! I can confirm that 2.7.5 is the version of python used on my system...
EDIT
I realized now that if I type in python it defaults to Python 2.7.5. But if I type in python2 it defaults to 2.7.6.
They are installed in these locations:
/System/Library/Frameworks/Python.framework/Versions/2.7 -- 2.7.5
/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7 -- 2.7.6
Is there anyway to make the 2.7.6 version the default when I type in python? Seems like django is installed there....
I figure that you have a link /usr/bin/python that points to your 2.7.5 version, so remove it and create other with the same name (python) to the version you want to use as default.
Nevertheless I recommends you to use virtualenvwrapper.
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