How to force new version of Django in virtualenv?

I want to install version 1.3.1 of Django in a new virtualenv. I already have Django version 1.3.0 installed on the system. I installed virtualenv using no-site-packages and tried to reinstall Django as follows, but without success:

 $ virtualenv --no-site-packages pyenv New python executable in pyenv/bin/python Installing setuptools............done. Installing pip...............done. $ source pyenv/bin/activate (pyenv)$ python Python 2.6.6 (r266:84292, May 26 2011, 21:27:16) [GCC 4.2.1 (Apple Inc. build 5664)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import django >>> django.VERSION (1, 3, 0, 'final', 0) 

OK, so although I did not install Django and I used no-site-packages , virtualenv still somehow took the system version.

Now try rewriting it with version 1.3.1:

 (pyenv)$ pip install django==1.3.1 Downloading/unpacking django==1.3.1 Downloading Django-1.3.1.tar.gz (6.5Mb): 6.5Mb downloaded Running setup.py egg_info for package django Installing collected packages: django Found existing installation: Django 1.3 Not uninstalling Django at /opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages, outside environment /Users/anna/Dropbox/code-local/pyenv/pyenv/bin/.. Running setup.py install for django changing mode of build/scripts-2.6/django-admin.py from 644 to 755 changing mode of /Users/anna/Dropbox/code-local/pyenv/pyenv/bin/django-admin.py to 755 Successfully installed django Cleaning up... (pyenv)$ python Python 2.6.6 (r266:84292, May 26 2011, 21:27:16) [GCC 4.2.1 (Apple Inc. build 5664)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import django >>> django.VERSION 

This did not work, it still points to 1.3.0!

Pay attention to the line: Found existing installation: Django 1.3 Not uninstalling Django .

How can I get my virtualenv to use 1.3.1? Do I need to edit my local Python path?

I am confused why virtualenv can even see the Django system when I am explicitly installed with no-site-packages . Is this the way it should work?

+4
source share
4 answers

Once you have created and activated virtualenv using --no-site-packages , you should not have access to the django package. I assume that you have somehow modified PYTHONPATH to provide it. echo $PYTHONPATH (my empty line) Try running pip freeze , here is what it looks like for me:

  $> virtualenv --no-site-packages testenv New python executable in testenv/bin/python2.7 Also creating executable in testenv/bin/python Installing setuptools............done. Installing pip...............done. $> source testenv/bin/activate (testenv)$> pip freeze wsgiref==0.1.2 
+4
source

You can use the -U option to update.

pip install -U django == 1.3.1

+1
source

I think that instead of forcing django 1.3.1, you should take one step back and investigate the reasons that could go wrong:

  • What is the contents of the site-packages directory in a virtual environment?
  • What is the django.__file__ for the imported version
  • Is there any setting in site.py or are you using the user's site directory?

For what it's worth, I used the same command with the --no-site-packages option, and I was not able to import the django version installed at the system scale.

+1
source

I have the same situation with my virtualenv. I solved the problem with these steps:

Open a shell and enter:

 python import django django.__path__ 

this will tell you the path by which you should remove the old version of django.

Go to this directory and use the root options (I think you need this to delete the directory) using sudo and enter the following commands:

 rm -r Django rm -r Django-1.3.0.egg-info/ 

Finally, install Django 1.3.1

0
source

Source: https://habr.com/ru/post/1391490/


All Articles