可以在Virtualenv上安装另一个版本的Python吗?

And*_*dré 145 python virtualenv

我在安装了Python 2.4的Web托管中有一个共享帐户,但我的代码与2.4不兼容.是否可以直接将Python 2.6安装到Virtualenv?

注意:我没有权限在共享服务器中安装它.

DTi*_*ing 251

以下是virtualenv的选项

$ virtualenv
You must provide a DEST_DIR
Usage: virtualenv [OPTIONS] DEST_DIR

Options:
  --version             show program's version number and exit.
  -h, --help            show this help message and exit.
  -v, --verbose         Increase verbosity.
  -q, --quiet           Decrease verbosity.
  -p PYTHON_EXE, --python=PYTHON_EXE
                        The Python interpreter to use, e.g.,
                        --python=python2.5 will use the python2.5 interpreter
                        to create the new environment.  The default is the
                        interpreter that virtualenv was installed with
                        (/usr/bin/python)
  --clear               Clear out the non-root install and start from scratch
  --no-site-packages    Don't give access to the global site-packages dir to
                        the virtual environment
  --unzip-setuptools    Unzip Setuptools or Distribute when installing it
  --relocatable         Make an EXISTING virtualenv environment relocatable.
                        This fixes up scripts and makes all .pth files
                        relative
  --distribute          Use Distribute instead of Setuptools. Set environ
                        variable VIRTUALENV_USE_DISTRIBUTE to make it the
                        default
  --prompt==PROMPT      Provides an alternative prompt prefix for this
                        environment
Run Code Online (Sandbox Code Playgroud)

1)你想要做的是将python安装到你能够写的目录中.

您可以按照说明操作here.

对于Python 2.7.1
Python source

mkdir ~/src
mkdir ~/.localpython
cd ~/src
wget http://www.python.org/ftp/python/2.7.1/Python-2.7.1.tgz
tar -zxvf Python-2.7.1.tgz
cd Python-2.7.1

make clean
./configure --prefix=/home/${USER}/.localpython
make
make install
Run Code Online (Sandbox Code Playgroud)

2)安装virtualenv
virtualenv source

cd ~/src
wget http://pypi.python.org/packages/source/v/virtualenv/virtualenv-1.5.2.tar.gz#md5=fbcefbd8520bb64bc24a560c6019a73c
tar -zxvf virtualenv-1.5.2.tar.gz
cd virtualenv-1.5.2/
~/.localpython/bin/python setup.py install
Run Code Online (Sandbox Code Playgroud)

3)使用本地python创建virtualenv
virtualenv docs

mkdir /home/${USER}/virtualenvs
cd /home/${USER}/virtualenvs
~/.localpython/bin/virtualenv py2.7 --python=/home/${USER}/.localpython/bin/python2.7
Run Code Online (Sandbox Code Playgroud)

4)激活环境

cd ~/virtualenvs/py2.7/bin
source ./activate
Run Code Online (Sandbox Code Playgroud)

5)检查

(py2.7)$ python
Python 2.7.1 (r271:86832, Mar 31 2011, 15:31:37) 
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()

(py2.7)$ deactivate
$ python
Python 2.6.6 (r266:84292, Sep 15 2010, 15:52:39) 
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 
Run Code Online (Sandbox Code Playgroud)

  • 精彩的写作!但是有两条评论:1.在执行`./configure --prefix =/home/<user> /.localpython`之前我没有做`make clean`实际上`make clean`返回错误.2."virtualenv name -p =/python/path`没有用,而`virtualenv name -p/python/path`确实有效.我认为这取决于virtualenv版本.干杯! (14认同)
  • 我发现缺少这么多基本模块 (4认同)
  • 下面是你需要安装的模块列表(在debian上),以使其尽可能接近完整安装:`curl gcc build-essential libncursesw5-dev libreadline5-dev libssl-dev libgdm-dev libbz2-dev libc6-dev libsqlite3-dev tk-dev` (3认同)

Thi*_*Lam 20

先决条件:

  1. sudo easy_install virtualenv
  2. sudo pip install virtualenvwrapper

使用Python2.6安装virtualenv:

  1. 您可以手动下载,构建和安装另一个版本的Python到/usr/local其他位置.
  2. 如果它是另一个位置/usr/local,请将其添加到PATH中.
  3. 重新加载shell以获取更新的PATH.
  4. 从这个角度上,你应该能够从你的shell拨打下列2蟒蛇二进制文件python2.5python2.6
  5. 使用以下命令创建virtualenv的新实例python2.6:

    mkvirtualenv --python=python2.6 yournewenv

  • 我认为mkvirtualenv命令仅在安装了virtualenvwrapper时才有效. (4认同)

Dan*_*kin 5

pyenv的完整指南

如果未安装 pyenv,则使用pyenv-installer安装它:

$ curl https://pyenv.run | bash
Run Code Online (Sandbox Code Playgroud)

要使用任何自定义 python 版本,例如3.5.6使用以下命令:

pyenv install 3.5.6
pyenv virtualenv 3.5.6 NAME_OF_YOUR_ENV
cd YOUR_PROJECT_PATH
pyenv local NAME_OF_YOUR_ENV
Run Code Online (Sandbox Code Playgroud)