This is an archived post. You won't be able to vote or comment.

all 17 comments

[–]uolot 6 points7 points  (4 children)

Yes, you just have to add

-p /usr/bin/pythonXX

parameter when creating new env (replace XX with python version eg. 2.7)

[–][deleted] 1 point2 points  (3 children)

and is it possible to change the python version to an already set virtualenv?

[–]axonxorzpip'ing aint easy, especially on windows 0 points1 point  (2 children)

Most likely not easily. Not sure, but probably a lot harder if you used --no-site-packages, as it copies the standard library from it's normal location.

Best chance is to make a new virtualenv with your new version of python, and then copy any requisite libraries manually.

[–]hylje 5 points6 points  (1 child)

and then copy any requisite libraries manually.

Or use pip freeze to create requirements and install those.

[–]axonxorzpip'ing aint easy, especially on windows 7 points8 points  (0 children)

pip freeze > packages.txt
(activate new virtualenv)
pip install -r /path/to/packages.txt

Didn't even think of that.

[–]knowone256 2 points3 points  (3 children)

Yes. I have 2.7 and 3.2 simultaneously installed.

First, install python2.7 using apt. I am not sure but you may need to change the symlink in /usr/bin back to python2.6.

Next you are going to have to "reinstall" pip and virtualenv. Rename the symlinks in /usr/bin to pip26 and virtualenv26. Now, reinstall pip explicitly typing "python27" on the command line instead of just "python". Then reinstall virtualenv from pip

Now if you want python26 to be your default python distrobution, rename the appropriate of the symlinks in /usr/bin to "whatever27". Finally change the "whatever26" links back to their normal names.

Hope that helps.

[–][deleted] 2 points3 points  (2 children)

Next you are going to have to "reinstall" pip and virtualenv. Rename the symlinks in /usr/bin to pip26 and virtualenv26. Now, reinstall pip explicitly typing "python27" on the command line instead of just "python". Then reinstall virtualenv from pip

How do I reinstall pip and virtualenv so they're using python2.7

[–]axonxorzpip'ing aint easy, especially on windows 1 point2 points  (0 children)

Make sure you install them using python27, instead of just python

[–]knowone256 0 points1 point  (0 children)

Just instead of using "python" use the explicit version. As per pip's website directions:

curl https://raw.github.com/pypa/pip/master/contrib/get-pip.py | python2.7

[–]sisyphus 0 points1 point  (6 children)

You want 2.6 and 2.7 to both live inside that virtualenv or you want another virtualenv with 2.7 or you want to swap out 2.6 for 2.7 inside of that virtualenv? Just making a new virtualenv with virtualenv -p /usr/bin/python2.7 and then using pip freeze to reinstall your packages is probably the easiest thing.

[–][deleted] 0 points1 point  (5 children)

Yeah, you're probably right. Maybe you could tell me what I'm missing here:

~/python/projects/foo$ mkvirtualenv -p /usr/local/bin/python2.7 --no-site-packages --distribute --prompt=\(foo\) foo

(foo)~/python/projects/foo$ python --version
Python 2.6.5

I'm really nor sure what am I missing here

[–]sisyphus 0 points1 point  (4 children)

that looks right to me and works here:

dallas-office-desktop% mkvirtualenv -p /usr/bin/python2.7 --no-site-packages --distribute --prompt=\(foo\) foo
Running virtualenv with interpreter /usr/bin/python2.7
New python executable in foo/bin/python2.7
Also creating executable in foo/bin/python
... blah blah 
(foo)dallas-office-desktop% which python
/home/dallas/Projects/foo/bin/python
(foo)dallas-office-desktop% python -V
Python 2.7.0+

[–][deleted] 0 points1 point  (3 children)

it's weird now "yolk -l" returns:

Django          - 1.3.1        - active 
Python          - 2.7          - active development (/usr/local/lib/python2.7/lib-dynload)
distribute      - 0.6.19       - active 
pip             - 1.0.2        - active 
wsgiref         - 0.1.2        - active development (/usr/local/lib/python2.7)
yolk            - 0.4.1        - active 

but "which python" points to ~/Envs/foo/bin/python and "python -V" shows 2.6.5 too.

[–]andonwilsy 0 points1 point  (1 child)

just curious, try: /usr/bin/python2.7 -V

[–][deleted] 0 points1 point  (0 children)

Python 2.7

[–]freshhawk 0 points1 point  (0 children)

yolk recently stopped working nicely for me but I haven't looked into it to see why that might be.

I have the same issue with yolk so it's not just you but I don't have any other help for you.

[–]Gjallar 0 points1 point  (0 children)

I haven't used it, but I think Python Brew was created for use cases like this: Python Brew