我有一个系统范围内安装了 python 2.5 的 VPS。 我将 python 2.7 安装到用户的主目录之一(使用 --prefix)。将其添加到 bashrc 和 bash_profile,将 python 变量导出到 env,现在当我在控制台中键入 python 时,python 2.7 正在运行。 但是当我从我的应用程序(Django 与 FastCGI 一起使用)检查 python 版本时,我仍然看到它使用的是 2.5。 在 ps 输出中,我看到为此帐户运行的 python 进程和使用特定于托管的帐户运行的 apache 进程。如何在不更改系统范围版本的情况下将此特定帐户切换到 2.7? 谢谢!
最佳答案
一种选择是使用 python virtualenv
用于创建 Python 虚拟环境的工具,您可以在 .bashrc
中获取该环境。
mike@tester:~$ virtualenv --python=/usr/bin/python3 $HOME/fcgi_python
Running virtualenv with interpreter /usr/bin/python3
Using base prefix '/usr'
New python executable in fcgi_python/bin/python3
Also creating executable in fcgi_python/bin/python
Installing Setuptools..............................................................................................................................................................................................................................done.
Installing Pip.....................................................................................................................................................................................................................................................................................................................................done.
mike@tester:~$ python --version
Python 2.7.5+
mike@tester:~$ source $HOME/fcgi_python/bin/activate
(fcgi_python)mike@tester:~$ python --version
Python 3.3.2+
在上面的示例中,您可以将 --python=
之后的参数替换为安装在用户主目录中的 Python 解释器的路径。
关于python - python/pythonpath 路径问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19627743/