我正在使用一台我没有管理员访问权限的服务器。安装了几个版本的Python。比如一个在/some/home/directory/Python2.6/
,另一个在/some/home/directory/Python2.7/
。
有没有一种简单的方法可以在终端临时更改Python版本,而不改变默认的Python版本,并且不需要获取root权限(到目前为止,我找到的所有答案都要求满足其中一种条件)?
我正在使用一台我没有管理员访问权限的服务器。安装了几个版本的Python。比如一个在/some/home/directory/Python2.6/
,另一个在/some/home/directory/Python2.7/
。
有没有一种简单的方法可以在终端临时更改Python版本,而不改变默认的Python版本,并且不需要获取root权限(到目前为止,我找到的所有答案都要求满足其中一种条件)?
alias python='/usr/bin/python3.4'
vi ~/.bashrc
。 - nuwandame从linfo.org中获取An alias can be created with the same name as the core name of a command (i.e., a command without any options or arguments). In such case, it is the alias that is called (i.e., activated) first when the name is used, rather than the command with the same name. For example, an alias named ls could be created for the command ls -al as follows:
alias ls="ls -al"
ls is a commonly used command that by default lists the names of the files and directories within the current directory (i.e., the directory in which the user is currently working). The -a option instructs ls to also show any hidden files and directories, and the -l option tells it to provide detailed information about each file and subdirectory.
Such an alias can be disabled temporarily and the core command called by preceding it directly (i.e., with no spaces in between) with a backslash, i.e.,
\ls
#!/usr/bin/python2.6
,那么你的程序将把python 2.6视为其运行环境。同样地,如果你提到python2.7,它将从python2.7开始考虑。#!/usr/bin/env python2.7
可能比直接输入 Python 路径更好,也使您的代码更具可移植性。 - user201155# install pip and venv as user
python3 -m pip install --user --upgrade pip
python3 -m pip install --user virtualenv
#create the virtual env files and folders in the current dir
python3 -m venv env
# activate the virtual env by sourcing the bin file
source env/bin/activate
#confirm it
which python
virtualenv
。 - muru