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
Related
I have downloaded anaconda and Django, but VS code shows
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?
so, I check out Get out of root conda environment and Problem with django after installing anaconda, installed django in virtual environment. Then follow https://docs.djangoproject.com/en/4.0/topics/install/. But I can't check out version by''' django-admin.py --version''' it shows command not found: django-admin
According to what you describe, I believe that you didn't activate the env or you don't have one in your directory, run this command py -m venv env && .\env\Scripts\activate then python -m pip install Django to create an env and activated and install Django if you have an env in your directory you need to activate using this .\env\Scripts\activate and then install Django finally run server Django using py manage.py runserver should works.
You're getting that error because you're calling django with the system's python and not the one inside your virtualenv.
Activate your virtualenv and then type:
python -m pip install django
That's it! Django will be recognized.
Also, when wanting to check django version, just simply do:
django-admin --version
without the .py piece
Remember to always call python inside your virtualenv. Let's say, like so:
python .\manage.py runserver
So to clarify, I had already got Django to work. The main thing I had done between installing Django and having this problem is that I installed miniconda3 and MySQLdb.
I'm running Python 3.7.1, pip 18.1 and as far as I know should have Django 2.1.4.
From /Users/me I run:
python3 -m django --version
and I get:
/Users/me/miniconda3/bin/python3: No module named django
From this I can see that the path seems to have been changed to miniconda, and I'm not sure how that has happened. If I run:
pip3 install Django
It then tells me:
Requirement already satisfied: Django in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (2.1.4)
Does anyone have either any idea of what could have happened and how to rectify it?
Create a vitual environment :
cd /a/b
virtualenv -p C:/Python36-32/python.exe venv
cd venv
pip install django
pip install ...
go to your BASE_DIR
cd /projet_django_app/
python manage.py runserver
It could be that you were using another conda env and then activate another conda env (your current one) wihout deactivate your previous env.
I got the same issue. And I deactivated all evns, went all they way back to 'base', and then activate the particular env that has the package I installed it before, then it worked.
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.
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 cloned my Django Project from Github Account and activated the virtualenv using famous command source nameofenv/bin/activate
And when I run python manage.py runserver
It gives me an error saying:
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?
I was thinking that every and each dependency I need, might be present inside virtualenv.
Well, no. By default, a newly created virtualenv comes empty, that is, with no third-party library. (Optionaly, you may allow a virtualenv to access libraries installed system-wide, but that's another story.)
Once the virtualenv is created, you need to install the dependencies you need.
(How could virtualenv know what dependencies you need?)
The procedure is to install the virtualenv, activate it, and then install the libraries needed for the project (in you case Django and perhaps others).
If you project has a requirements.txt, you may install every required dependency with the command:
pip install -r requirements.txt
If your project has a setup.py, you may also execute
pip install -e path/to/your/project/clone/.
to install the project in the virtualenv. This should install the dependencies.
Of course, if the only dependency is Django, you can just type
pip install django
on ubuntu version
#install python pip
sudo apt-get install python-pip
#install python virtualenv
sudo apt-get install python-virtualenv
# create virtual env
virtualenv myenv
#activate the virtualenv
. myenv/bin/activate
#install django inside virtualenv
pip install django
#create a new django project
django-admin.py startproject mysite
#enter to the folder of the new django project
cd mysite
#run the django project
python manage.py runserver
If you have several python on your machine, for example,python2.7, python3.4, python3.6, it is import to figure out which version the python really reference to, and more over, which version does pip reference to.
The same problem got in my way after I installed the let's encrypt when I run the following command.
(python3 manage.py runserver 0:8000 &)
I inspected the python version and found that python3, python3.4, python3.6, python3.4m were all available.
I just change python3 to python3.6 and solved the problem.
(python3.6 manage.py runserver 0:8000 &)
So, this is probably a version mismatching problem if it is OK for a long time and crashes down suddenly.
I'm guessing you also upload the virtual environment from your other pc. And you hope that only activating that will work, bzz.
It's not recommended to upload the virtualenv files to your git repository, as #Alain says it's a good practice to have a requirements.txt file containing the project dependencies. You can use pip freeze > requirements.txt (when the environment is activated) to generate the project requirements file.
By doing so, when you clone the repository from another computer, you need to create a new virtualenv by issuing the command:
virtualenv nameofenv
then activate it:
source nameofenv/bin/activate
and finally, use the requirements file to install the requirements for your project using:
pip install -r requirements.txt
I had installed Django 2 via pip3 install Django, but I was running python manage.py runserver instead of python3 manage.py runserver. Django 2 only works with python 3+.