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
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
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+.
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