You are not logged in.
Hello,
I was wondering if there is a way to have some kind of virtual python2 environment for a specific application. What I mean is that in this environment every call to python (or "/usr/bin/env python") will point to python2 instead of python3. I read the wiki and I know that it should be as simple as changing the first line of a script - but sometimes it isn't. In my case I'd like to use ns3 (network simulator) which relies heavily on python. And even though I managed to get it somehow built with the approach suggested in the wiki (and some search and replace in the python scripts) I constantly run into python errors due to scripts (or modules, included scripts etc.) using the old syntax. I already asked on the ns3 mailing list and they won't migrate to python3 in the near future, thus I need another solution. Any ideas?
Kind regards and thank you in advance,
Karsten
Last edited by rocktale (2011-05-28 13:55:00)
Offline
If the scripts call `/usr/bin/env python` (instead of `/usr/bin/python`) you could create a temporary bin directory with a symlink from /path/to/your/bin/python to /usr/bin/python2 and then prepend this directory to your PATH.
Offline
Use python-virtualenv[1], if you create a python2 virtualenv it will link python to python2 within that environment. Personally I would combine that with virtualenvwrapper (should be linked from the page I linked to IIRC) to enabling and switching virtualenvs simpler.
Offline
+1 for virtualenv + virtualenvwrapper. Pip is a plus for installing programs.
Offline
Thank you for your ideas. I feel almost ashamed that I haven't had the symlink and PATH prepend idea myself. That's almost too easy. :-)
virutalenv and virtualenvwrapper are a more sophisticated solution (working as well, of course). I'm not entirely sure what else I might need it for but that's probably because I haven't done much python development yet. However, I'll stick with it since you never know.
Thank you again.
Offline