且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何检查是否已为 VIRTUALENVWRAPPER_PYTHON=/usr/bin/python 等安装了 virtualenvwrapper

更新时间:2023-01-14 22:22:44

不确定您需要什么,但也许这会有所帮助.它有点冗长,但希望能回答您的问题:

Not exactly sure what you are needing, but maybe this will help. It is a little verbose, but hopefully will answer your questions:

这里发生了很多事情.

首先,/usr/local/bin/virtualenvwrapper.sh 是一个shell 脚本.如果您阅读脚本,您将看到以下代码:

First, /usr/local/bin/virtualenvwrapper.sh is a shell script. If you read the script, you will see the following code:

# Locate the global Python where virtualenvwrapper is installed.
if [ "$VIRTUALENVWRAPPER_PYTHON" = "" ] 
then
    VIRTUALENVWRAPPER_PYTHON="$(command \which python)"
fi

这意味着 virtualenvwrapper.sh 脚本使用名为 VIRTUALENVWRAPPER_PYTHON 的环境变量来确定 python 安装.这很重要,因为:

What this means is that the virtualenvwrapper.sh script uses an environmental variable named VIRTUALENVWRAPPER_PYTHON to determine the python installation. This is important because:

其次,一个系统上可以安装多个版本的python.(我目前有 3:2.7、3.5 和 3.6).无论如何,对于 Linux 系统,

Second, multiple versions of python can be installed on a system. (I currently have 3: 2.7, 3.5, and 3.6). And with Linux systems anyway,

/usr/bin/python

象征性地链接到这些版本之一.这是它在我的系统 Linux 系统上的外观:

is symbolically linked to one of those versions. This is how it looks on my system Linux system:

lenovo:davidj ~ >  ls -l /usr/bin/python
lrwxrwxrwx 1 root root 24 Apr 28 23:36 /usr/bin/python -> 
/etc/alternatives/python
 lenovo:davidj ~ >  ls -l /etc/alternatives/python
lrwxrwxrwx 1 root root 18 Aug 31 14:56 /etc/alternatives/python -> 
/usr/bin/python3.6

所以,当我运行时,按照符号链接链

So, following the chain of symbolic links, when I run

/usr/bin/python

我运行的是 3.6 版.我可以随意更改这些链接以指向版本 2.7、3.5 或我可能安装的任何其他版本.

I am running version 3.6. I can change those links at will to point to version 2.7, 3.5, or any other version I might install.

所有这一切意味着:除非您将 VIRTUALENVWRAPPER_PYTHON 设置为特定的 Python 安装,否则/usr/local/bin/virtualenvwrapper.sh 将默认为/usr/bin/python 以确定您正在运行的默认 Python 版本.

What all of this means is this: unless you have VIRTUALENVWRAPPER_PYTHON set to a specific python installation, /usr/local/bin/virtualenvwrapper.sh will default to /usr/bin/python to determine the default python version you are running.

就我而言,在我的 .bashrc 文件中

In my case, in my .bashrc file I have

export VIRTUALENVWRAPPER_PYTHON='/usr/bin/python3.6'

这意味着 virtualenvwrapper 将使用 python 3.6,因为我告诉它使用该特定版本.

This means that virtualenvwrapper will use python 3.6 because I am telling it to use that specific version.

在您的情况下,脚本失败是因为没有为/usr/bin/python 指向的那个版本的 python 安装 virtualenvwrapper.要确定您的 python 版本,只需运行:

In your case, the script is failing because virtualenvwrapper is not installed for that version of python that /usr/bin/python points to. To determine your version of python simply run:

python -V

然后为该版本安装 virtualenvwrapper.

and then install virtualenvwrapper for that version.

我希望这会有所帮助.