9

Seems everyone recommends virtualenv for multiple python versions (on osx), but does it even work with python 3.0? I downloaded it, and it doesn't seem to.. And I don't really understand how it works, Can you 'turn on' on env at a time or something? What I want is to leave the system python 2.5 (obviously), and to have python 3.1.1 with subversion pygame to write my own stuff, and python 2.6 with normal stable pygame to use to run other things, like pygame games downloaded from pygame.org. Any help on how to accomplish that? Thanks.

OK I realized virtualenv is not what I'm looking for.

1
  • 4
    As of version 1.6 virtualenv has Python 3 support. Commented Apr 4, 2011 at 19:47

5 Answers 5

14

It's an old question by now, but I found it myself on top of google search for the answer, and I don't think the answers provided are what people are looking for.

As I understand it you want to create different virtual environments with different Python versions?

This is very easy, and you only need virtualenv itself.

For, say, a Python 3:

$ virtualenv -p python3 p34env

(...)
New python executable in p34env/bin/python3.4
Also creating executable in p34env/bin/python
Installing setuptools, pip...done.

$ source p34env/bin/activate

(p34env)$ python -V
Python 3.4.2

(p34env)$ deactivate 
$

You use the source command to activate the venv, and deactivate to - you guessed it - deactivate it. Notice the prompt changes to indicate the env.

For your system's standard version of Python you just skip the -p python3 argument, and you can use the argument to point to any version you want given a path.

The last argument is the name (p34env) and you can make as many as you like, just give them different names.

3

Your use case doesn't actually need virtualenv. You just need to install several different Python versions.

6
  • I just like using the newest version, I just teach myself programming as a hobby, so It doesn't really matter to anyone else which version I use.
    – mk12
    Commented Sep 12, 2009 at 22:11
  • So, for using with pygame, you think I should stick with 2.6?
    – mk12
    Commented Sep 12, 2009 at 22:17
  • Yes, you should stick with 2.6.
    – Ned Deily
    Commented Sep 12, 2009 at 22:20
  • I'm not that advanced in programming, like I said, self-taught, but I might help if I can, it sounds interesting.
    – mk12
    Commented Sep 12, 2009 at 22:35
  • Are you one of the core developers then?
    – mk12
    Commented Sep 12, 2009 at 22:35
1

virtualenv is designed to create isolated environments of a Python environment. The trick to using it with multiple Python instances is to either install virtualenv into each of the Python versions you want to use it with, for example:

/usr/bin/easy_install-2.6 virtualenv
/usr/local/bin/easy_install virtualenv
sudo port install py26-virtualenv

or to invoke it with the intended Python version, for example:

/usr/bin/python2.6 virtualenv.py ENV
/usr/local/bin/python2.6 virtualenv.py ENV
/opt/local/bin/python2.5 virtualenv.py ENV

So, as such, it doesn't directly solve the problem (particularly acute on OS X) of which Python you want to work with. There are various ways to deal with that issue: use absolute paths to the intended Python (as in the above examples), define shell aliases, carefully manage the $PATH search order, among others.

At the moment, AFAIK, virtualenv is not supported with Python 3 because, among other things, setuptools (the magic behind easy_install) is not yet supported on Python 3, although there is work in progress towards a solution for that.

BTW, many people use Doug Hellman's virtualenvwrapper to simplify use of virtualenv.

1
  • i have already Python 3.2.3 , but i must install Python 3.3.2 for some stuff in a course , and my old codes are related to pygame , i want to use virtualenv after installing it and and also pip , i don't know how to include pygame to each environments either python 3.3.2 or python 3.2.3 , i am using windows xp , any opinion or instruction or reference is welcome.
    – mazlor
    Commented Jul 3, 2013 at 21:45
1

For me virtualenv3 works very well. I also have pypi.python.org/pypi/distribute installed. That also works with the mentioned www.doughellmann.com/docs/virtualenvwrapper/ . I've only tested that on Linux though.

0
0

Not sure if I understood you correctly, but here goes :)

I don't know about OS X, but in Linux you can install both 2.6 and 3. Then you can either specify to use python25 or python3, or change the /usr/bin/python symlink to the version you want to use by default.

2
  • Are you talking about without virtualenv?
    – mk12
    Commented Sep 12, 2009 at 20:30
  • No, I'm talking about using multiple python versions. For what I know, virtualenv is used to work with dependencies of multiple versions, not multiple versions of python itself. But I may be wrong :-)
    – l3dx
    Commented Sep 12, 2009 at 20:44

Not the answer you're looking for? Browse other questions tagged or ask your own question.