When I ran the following command :
django-admin startproject project_name
I got the following error :
The program 'django-admin' is currently not installed. You can install it by typing:
sudo apt install python-django-common
I did what it told me to and nwo I get the following error:
Cannot find installed version of python-django or python3-django.
on running the same command, I am not able to understand if I had installed django , then why was django-admin script not installed
Note that django is installed which is verified by the following:
$ python -c "import django; print(django.get_version())"
1.7
try this command, django-admin.py startproject example, if it doesnt work try creating a virtual environment and installing django again
You can try to install django with pip as stated in the answer to this question, also maybe the best option is to use a virtualenv, you may find it in the ubuntu repository via synaptic.
Related
I am starting to learn to use MongoDB with Django, so I followed this tutorial to start up.
I created my virtual environment using python3.6 -m venv MongodbTestVenv, and activated it using source MongodbTestVenv/bin/activate. Everything worked fine, so far.
I installed Django-nonrel using pip install git+https://github.com/django-nonrel/django#nonrel-1.5.
I installed djangotoolbox using pip install git+https://github.com/django-nonrel/djangotoolbox.
I installed Mongo DB engine using pip install git+https://github.com/django-nonrel/mongodb-engine.
I checked with pip list to ensure everything is installed:
(MongodbTestVenv) MacBook-Pro-de-Hugo:MongodbTestProject hugovillalobos$ pip list
Package Version
--------------------- -------
Django 1.5.11
django-mongodb-engine 0.6.0
djangorestframework 3.9.2
djangotoolbox 1.8.0
pip 19.0.3
pymongo 3.7.2
setuptools 28.8.0
But, when I type django-admin startproject MongodbTest, I get this error: -bash: django-admin: command not found.
I checked this question, but all answer are related to the location of django-admin.py file, so I found it using which django-admin.py, and this is the result:
(MongodbTestVenv) MacBook-Pro-de-Hugo:MongodbTestProject hugovillalobos$ which django-admin.py
/Users/hugovillalobos/Documents/Code/MongodbTestProject/MongodbTestVenv/bin/django-admin.py
I can see that the file is located on the active virtual environment directory, so I can't understand why it can't be located.
I don't know what I am missing, I have never had problems with Django when using relational database and I install regular Django versions using just pip install Django.
You say you ran:
django-admin startproject MongodbTest
but your bash is able to find django-admin.py from that which statement.
Try what your bash knows:
django-admin.py startproject MongodbTest
when running django-admin startproject myproject on macOS I get the error
Traceback (most recent call last):
File "/usr/local/bin/django-admin", line 2, in
from django.core import management
ImportError: No module named django.core
I checked out this question but running import django won't produce any output in a python3 shell.
/usr/local/bin/django-admin is a symlink to /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/bin/django-admin.py.
I already put /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django in my PYTHONPATH as suggested in other questions.
Am I missing something?
Even if you make it work, it is not good practice to do what you're doing! Ideally, the only python-related binaries you would want in /usr/local/bin/ would be python, pip and virtualenv (or venv, pyvenv)...
I would suggest you to delete /Library/Frameworks/Python.framework/Versions/3.6 ONLY IF you installed it there. As far as I know, macOS only comes with python2.7 installed and not python3.6!
Then open a new shell and try this:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew install python3
pip3 install virtualenv
cd ~/Desktop/
mkdir proj
cd proj
virtualenv -p python3 env
source env/bin/activate
pip install django
django-admin.py startproject testproj
skip the first step if you already have brew installed
Check your permissions in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ with an ls -la command. If you see anything owned by root, this probably needs to change. I suspect that since you installed some packages as root, the permissions are weird and it can't find the module. If this is the case, reinstall the package(s) as your own user using sudo.
Another thing you should check: as phd mentioned you need to make sure you're using the version of python you think you are. Check this by running which python to tell you the location of the one you're referencing, and python --version to tell you which version you're using. If it's not Python 3.6, then you installed Django for a different version of Python. In this case, simply install Django for version 3.6 and you'll be on your way.
For future reference, Python offers a module called venv to prevent version mishaps like this. More info can be found here.
It seems like you are trying to create or work on a django project without using a python virtual environment. I recommend reviewing the python 3 venv documenation (https://docs.python.org/3/library/venv.html). Then creating a virtual environment (venv) specifically for your web application. Once you you that project's venv setup you can install django into that venv.
On MacOS, use sudo before the command:
sudo django-admin startproject myproject
I'm a beginner in django..
I am trying to build an application using django 1.11.2 and python 3.5.2, both are installed. I have python 2.7 installed too.
I have executed this command: django-admin startproject Application1 to create a new application.
The application runs, but the project is versioned Django 1.8, however when I run python -c "import django; print(django.get_version())" to find django version, it shows 1.11.2
The command django-admin --version shows me 1.8.7
What's wrong?
Do I have two django installed versions?
Should I upgrade django-admin? How?
Please, help me.. I'm stuck.
From my understanding, you have two django installed on your system: in your python2 environment and python3 environment. So, what you have to do is to uninstall one of them so they won't be conflicted. Since you want to use python3 as your environment, you should uninstall django in your python2 environment with the following command:
pip uninstall django
If it says, "command not found" after you uninstall it, try to reinstall django with the following command
pip3 install django
I started Django in Mac OS and after installing Django using pip, I tried to initiated a new project using the command django-admin startproject mysite. I get the error -bash: django-admin: command not found. I make quick search in Google and haven't get any solution that works.
How to start a new project using Django using django-admin ?
I solved the issue after reading a webpage about the mentioned issue.
In the Python shell, write the following,
>> import django
>> django.__file__
>> django also works
It will provide the installation location of django.
Change the path to the new path /usr/local/bin/django-admin.py,
sudo ln -s the complete path of django-admin.py /usr/local/bin/django-admin.py
In Mac OS, The call needs to be django-admin.py startproject mysite than django-admin startproject mysite
Try the following:
django-admin.py startproject mysite
First install Django, lets assume you have python3.7 and want to install django 2.0.3, in this case using pip3.7 to install
sudo pip3.7 install django==2.0.3
now try to see if django-admin.py is installed using
ls /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/bin
If you see django-admin.py just link it to the /usr/local/bin using this command
ln -s /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/bin /usr/local/bin/
Then you could run this command to create new python project
django-admin startproject mysite
try this. this should work for you with no problem.
pip3 install django
python3 -m django startproject PROJECTNAME
you can use python and pip command without mentioning 3 either.
You need to add django to your path variables and then restart the terminal.
I know I'm jumping in a little late, but my installations seem to all reside away from /usr/local/bin/... . What worked for me was adding an export path in bash_profile for my django installation.
This also made me realize that it was installed globally. From what I've heard, it's better to install django locally within venv as you work on different projects. That way each virtual environment can contain its own versions and dependencies for django (and whatever else you're using). Big thanks to #Arefe.
pip install django
after
django-admin startproject nameProject
On mac, try to uninstall it via python -m pip uninstall Django, then you get the actual path to django-admin, then you can do chmod +x /Users/pano/.pyenv/versions/3.9.5/bin/django-admin
$ python -m pip uninstall Django
Found existing installation: Django 4.0.6
Uninstalling Django-4.0.6:
Would remove:
/Users/pano/.pyenv/versions/3.9.5/bin/django-admin
/Users/pano/.pyenv/versions/3.9.5/lib/python3.9/site-packages/Django-4.0.6.dist-info/*
Proceed (Y/n)? Y
Successfully uninstalled Django-4.0.6
In my case, i was forgot to activate the virtual environment.
pipenv shell
I tried to install django after python installation (3.4.0 version), the problem began when i tried to run the simple command: "pip install django" via the cmd - it did nothing (descending line and writes nothing). I forced it to apply the installation using the command: "python -m pip install django". Although it was declared that the installation was successful, when I run, for example, the command: "django-admin --version" it did nothing as well, but when i run the command: "python -m django-admin --version", it says that: "python.exe: no module named django-admin".
In general, each command associated to pip or to django does not work, such as:
pip help, pip X ot django X
Ps. I added the paths in 'Path' of the User Varuables and System Variables:
C:\Python34; C:\Python34\Scripts
For you and possible future users asking similar question:
Only the pip command runs the 2.7 Python interpreter. You are using the 3.4 version, so instead of pip you have to use the pip3.4 command.
Why? Python 2.7 is not compatible with the 3.x and higher versions.
In your case Django is installed only for the 2.7 version and if you run the python3.4 command, Django is not installed ("no module named django").