22đź‘Ť
No, the directory where you create the virtual environment is completely separate and is not where you would go and create your django project.
In fact, you would usually put all your virtual environments in a separate directory; for me I put them in $HOME/work/.envs
(note the .
, this makes the directory hidden by default), so then my workflow becomes:
$ virtualenv $HOME/work/.envs/new_env
$ source $HOME/work/.envs/new_env/bin/activate
(new_env)$ pip install django
(new_env)$ cd ~/projects
(new_env)/projects$ django-admin.py startproject atestproj
So you see, you don’t actually do anything with the virtual environment directory; it is completely managed by virtualenv
and pip
.
The virtualenvwrapper
project makes this easier by managing your virtual environments in a central location.
2đź‘Ť
Directory structure for use with virtualenv should be as follows:
|-- project_name
|-- django
|-- project_name
|-- virtualenv
|-- project_name
|-- bin
This of course is not the definitive answer to how your project directory structure should be laid out—it has however worked for me, and others I know, over the years.
I highly recommend “twoscoops’s” django project directory structure and tutorial for beginners:
https://github.com/twoscoops/django-twoscoops-project
I also recommend virtualenvwrapper, to make managing virtual environments easier:
http://virtualenvwrapper.readthedocs.org/en/latest/
- Django nested if else in templates
- Django South Error: AttributeError: 'DateTimeField' object has no attribute 'model'`
- Moving django apps into subfolder and url.py error
- Commit manually in Django data migration
1đź‘Ť
This goes to the very heart of how you use virtualenv: cd to the virtualenv directory, then activate it (or the other way around – it doesn’t really matter). The usual way to do this on linux (or cygwin) is to source ./bin/activate/
from inside the virtualenv.
At that point, if you use pip
or python
they will be local to that virtualenv. You should only perform your installations, and run your stuff after activating the virtualenv.
So, to answer your question: switch and activate before you start to install or do anything. Do everything inside the virtualenv, with it activated.
- Where do I import the `DoesNotExist` exception in Django 1.10 from?
- Token Authentication Django Rest Framework HTTPie
- OpenCV imread hanging when called from a web request