23π
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
14π
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
- Celery beat not picking up periodic tasks
- Django β Override admin site's login form
- Django 2.0: sqlite IntegrityError: FOREIGN KEY constraint failed
5π
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.
4π
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
- How does django-nose differ from the default Django test-runner
- Create a canonical "parent" product in Django Oscar programmatically
- How to display "This many months ago" in Django using Humanize?
- How can I easily convert a Django app from mySQL to PostgreSQL?
1π
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+.
- How do you get Django to make a RESTful call?
- Should I use Celery or Carrot for a Django project?
- How to manage.py loaddata in Django
- How to print pretty JSON on a html page from a django template?
- How to show more than 100 items on each paginated "Change List" page in Django Admin?