我正在按照本教程安装virtualenvwrapper
https://realpython.com/python-virtual-environments-a-primer/#managing-virtual-environments-with-virtualenvwrapper
但是,我不能让我的工作。
当我这样做时,pip install virtualenvwrapper --user我收到以下警告。
Installing collected packages: virtualenv, pbr, six, stevedore, virtualenv-clone, virtualenvwrapper
WARNING: The script virtualenv is installed in '/Users/user1/Library/Python/2.7/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
WARNING: The script pbr is installed in '/Users/user1/Library/Python/2.7/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
WARNING: The script virtualenv-clone is installed in '/Users/user1/Library/Python/2.7/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Run Code Online (Sandbox Code Playgroud)
所以我将以下内容添加到我的.bash_profile,现在它可以找到包。
"/Users/user1/Library/Python/2.7/bin:$PATH"
Run Code Online (Sandbox Code Playgroud)
但我只是不明白为什么在我的环境中需要这个额外的步骤,而其他人似乎对直接安装到/local/bin.
这些是我的 python2 和 pip 没有符号链接的地方。
admins-MacBook-Pro:~ user1$ which python
/usr/bin/python
admins-MacBook-Pro:~ user1$ which pip
/usr/local/bin/pip
Run Code Online (Sandbox Code Playgroud)
题
pip安装我的东西?/Users/user1/Library/Python/2.7/bin/usr/local/bin/大多数人使用虚拟环境来维护不同版本的包。这样您的各种代码库就不会相互冲突。使用虚拟环境的第二个原因是这样您就不会污染 Python 的系统安装。
添加该--user标志将在用户级别而不是系统级别将包安装到 Python。如果您养成安装到用户级别的习惯,那么您将避免在更新系统需要的软件包版本时出现问题。
一旦您在虚拟环境中工作,那么您安装的任何东西都将在您的环境中。然而,初始包安装virtualenv必须安装在某处——在机器的用户级别。
“pip install --user ...”的目的是什么?
我正在编辑答案。您不应该使用 sudo 或尝试在系统级别安装。警告清楚地说明了您的 virtualenv 的安装位置以及您需要添加到 PATH 中的目录。我建议您按照此处所述添加这些目录:https : //apple.stackexchange.com/a/358873/249870
通过添加以下行来编辑您的 ~/.bash_profile 文件:
export PATH="/Users/user1/Library/Python/2.7/bin:$PATH"
接下来,在命令行上,获取文件:
$ source ~/.bash_profile
那应该这样做。