0

In the activate_this.py script:

site_packages = os.path.join(base, 'lib', 'python%s' % sys.version[:3], 'site-packages')

It uses sys.version[:3] and this evaluates to python2.6 (the system default). But I had installed python2.7 and created my virtualenv with:

virtualenv -p /usr/local/bin/python2.7 venv

How do I make virtualenv work with the correct version of python?

Creating a symlink from /usr/bin/python to /usr/local/bin/python2.7 is not a solution because the CentOS system depends on python2.6.

allenylzhou
  • 1,431
  • 4
  • 19
  • 36
  • How are you running / using the `activate_this.py`? – Simeon Visser Oct 09 '14 at 21:34
  • `activate_this = '/path/to/venv/bin/activate_this.py' execfile(activate_this, dict(__file__=activate_this))` – allenylzhou Oct 09 '14 at 21:54
  • In what Python instance are you running that code? I presume that's the system Python? – Simeon Visser Oct 09 '14 at 22:06
  • @SimeonVisser yes, it is running using the system python2.6. I am not sure how to make it run with python2.7. Being able to do that would solve my problem. I use a virtual host, and that code is run when I hit the virtual host. – allenylzhou Oct 09 '14 at 22:39
  • What server software are you running? Nginx/Apache/uwsgi? I think it's better to run your server **after** activating the virtualenv in your shell – l04m33 Oct 10 '14 at 00:35
  • Think about it this way: the system Python is 2.6 and you'll only get Python 2.7 after being inside the virtualenv. So it won't make sense to "activate the virtualenv" with Python 2.7 when that's only available inside the virtualenv. You need to figure what's failing and why. In the worst case, it may even be a bug in `activate_this.py` as I see various posts online about people struggling with Python versions and this file. – Simeon Visser Oct 10 '14 at 09:02

1 Answers1

0

Let's face it, python virtualenv is very limited and has very specific usecases. The only way i've been able to accomplish this is by rebuilding mod_wsgi against the desired version of python

How i say the interpreter version for wsgi apache

Community
  • 1
  • 1
Stanton
  • 497
  • 3
  • 14