Dude, at least you’re running some command from outside the virtual environment or you’re creating a virtual environment with version 2 of Python (there pip3 will match your system’s Pip and not your environment’s).
I will pass the complete recipe of how to do what you want, so eliminates the possibility of doubts.
First of all it’s good to make it clear that you nay you must install Django with packages from your system. Both @jsbueno and @mgibsonbr and all existing literature on Jango will tell you to create your application using a virtual environment.
First of all you will need the virtualenv
. This I let you use the system repository. Install the version according to the version of Python you want to use if you want to make your life easier, but in real, whatever.
With it installed, create a folder for your project and enter it:
mkdir super_project
cd super_project
Create a virtual environment:
virtualenv venv
Again, use the virtualenv version according to the Python version you want. However, nothing prevents you from telling virtualenv which version of Python you want to take as a basis:
virtualenv venv -p /usr/bin/python3
Regardless of the way, the two commands will create a folder called venv
inside your project folder:
super_project
└── venv
Now comes the most important step, activate the virtual environment:
source venv/bin/activate
Or simply:
. venv/bin/activate
Now you can install whatever you want:
pip install django==1.9.6
Since 1.9.6 is the latest stable version of Django today, you do not need to make explicit the version can only do:
pip install django
With Django installed, you can start developing your application:
django-admin startproject project
cd project
python manage.py runserver
And that’s it.
I’m assuming you were within virtual environment when you installed with Pip, right? (i.e. first you used the command
source
, then you used the commandpip3
to install Django)– mgibsonbr
Tried to install Django by
apt-get
? I usually use the distro’s own installer, I’ve avoided a lot of headaches with it– Brumazzi DB
@Brumazzidb The problem is that the virtual environment uses its own
site-packages
independent of the global environment (and depending on how virtualenv was created, it does not even inherit the globally installed packages). So install viaapt-get
I don’t think that’s a good idea in that context.– mgibsonbr
In fact, it makes no sense to use the installation of Django via apt-get - the idea of virtualenv’s is to just avoid the problems that this brings (To begin with, you would have to have an operating system on your server that would have to have exactly the same version of Django as your development s.o. - and so on for all Python dependencies)
– jsbueno
@mgibsonbr yes, was already inside the virtual environment
– Erick
Right... I think I should check the version of python being called, many linux distros have python 2.x by default, if you try
python3 manage.py runserver
, can solve– Brumazzi DB
@Brumazzidb was the first thing I tried when error appeared kkk. I tried everything but so far nothing solved =/
– Erick