Question

I am a bloody beginner in Python and Django. To set up a environment on my Windows machine, I performed the following steps.

  1. Install Python 3.4
  2. Use pip to install virtualenv
  3. Create a project folder and set up a virtualenv there
  4. Download Django 1.7b1 release from the official site
  5. Extract the archive in my downloads folder
  6. Install it into my virtualenv

For the last step, I used pip from my virtualenv.

[project]\scripts\pip.exe install -e [downloads]\Django-1.7b1

From the global python interpreter I can't import django, as expected. When using the python executable from the virtualenv, it works. But the import only succeeds as long as I have the Django source in my downloads folder. Instead, I would like to include it into my virtualenv.

Can I make pip to automatically copy the Django source into my project folder?

Était-ce utile?

La solution

Install django via pip inside the virtualenv. I'm running Linux but you should be able to run the commands on windows.

If you need a version that's not in PyPi, download the package and install it to the virtualenv site-packages-folder.

My site-packages folder for project is in ~/venvs/project/lib/python2.7/site-packages. To install there:

pip install downloads/Django-1.7b1.tar.gz -t ~/venvs/project/lib/python2.7/site-packages

Django will install to the site-packages folder and is now importable from within the virtualenv. Downloads/Django-1.7b1 is no longer needed.

Below is an example where I'm installing Django 1.7b1 from a local archive to the site-packages-folder of my virtualenv:

(project)msvalkon@Lunkwill:/tmp$ pip install /tmp/Django-1.7b1.tar.gz -t ~/venvs/project/lib/python2.7/site-packages/
Unpacking ./Django-1.7b1.tar.gz
  Running setup.py egg_info for package from file:///tmp/Django-1.7b1.tar.gz
    -- SNIP --
Successfully installed Django
Cleaning up...
(project)msvalkon@Lunkwill:/tmp$ python -c "import django;print django.get_version()"
1.7b1
(project)msvalkon@Lunkwill:/tmp$ deactivate
# I've got a really old version installed globally, but you can see
# that the installation worked.
msvalkon@Lunkwill:/tmp$ python -c "import django;print django.get_version()"
1.5.1

After this you should find the following output when doing pip freeze while the virtualenv is activated:

(project)msvalkon@Lunkwill:/tmp$ pip freeze
Django==1.7b1
argparse==1.2.1
wsgiref==0.1.2
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top