How to use Python virtualenv

前端 未结 2 400
花落未央
花落未央 2021-02-03 11:28

The scenario is: I am on Ubuntu 11 which comes with Python 2.7, I want to run Mozilla JetPack which supports Python 2.5/2.6 and Google App Engine which only supports Python 2.5

2条回答
  •  既然无缘
    2021-02-03 11:56

    Outline:

    • First cd to /usr/local/python25/bin
    • Download setuptools for Python2.5 (setuptools-0.6c11-py2.5.egg)
    • Install it (sh setuptools-0.6c11-py2.5.egg).
    • Now install pip (easy_install pip).
    • Install virtualenv and virtualenvwrapper using pip (pip install v... etc.).
    • Configure WORKON_HOME for virtualenv wrapper to work (export WORKON_HOME = $HOME/.virtualenvs). You can use any other directory you want (not just $HOME/.virtualenvs). Just make sure to use the full path.
    • Now create a virtualenv (mkvirtualenv foobar).
    • Switch to the new virtualenv (workon foobar).
    • Now install GAE, JetPack and whatever you want using pip install blah

    Why did your install not work?

    Looks like you did not install virtualenv for Python2.5. Hence this will not work.

    jiewmeng@JM:/usr/local/python25/bin$ ./python virtualenv /works/tmp/test
    

    You can check by running ls command in that directory. I suspect you won't find virtualenv file there.

    However this worked for you.

    jiewmeng@JM:/usr/local/python25/bin$ virtualenv /works/tmp/test
    

    Because it is using the virtualenv file for system default Python2.7. You can check which virtualenv and opening the virtualenv script. You'll see that the #! will point to system default python.

    So you need to install the easy_install and pip for Python 2.5 before you can create virtualenv for Python 2.5. Just follow the steps outlined above.

提交回复
热议问题