virtualenv虚拟环境、virtualenvwrapper虚拟环境管理器、virtualenv:错误:未识别的参数:--no-site-packages。

22
我正在尝试将Python从3.6升级到3.8。我曾经成功地使用virtualenv/wrapper(虽然只有一个环境,没有任何附加功能),但是这次升级并不顺利。我删除了所有内容并尝试重新开始。我正在尝试创建一个新的环境,使用命令mkvirtualenv test,但是现在出现了错误:virtualenv: error: unrecognized arguments: --no-site-packages。它给出了一个手动调用virtualenv的建议,这让我相信virtualenvwrapper正在工作,但我肯定漏掉了一些东西。这里是我的详细信息: 终端(OSX-10.13.6(17G65))。
today@5 ~/dev/MST/server(master)$ which python
/usr/bin/python
today@5 ~/dev/MST/server(master)$ which python3
/usr/local/bin/python3
today@5 ~/dev/MST/server(master)$ which pip
/usr/local/bin/pip
today@5 ~/dev/MST/server(master)$ which pip3
today@5 ~/dev/MST/server(master)$ pip -V
-bash: /usr/local/bin/pip: /usr/local/opt/python/bin/python3.6: bad interpreter: No such file or directory
today@5 ~/dev/MST/server(master)$ pip3 -V
pip 20.0.2 from /usr/local/lib/python3.8/site-packages/pip (python 3.8)
today@5 ~/dev/MST/server(master)$ pip3 install virtualenv virtualenvwrapper
Requirement already satisfied: virtualenv in /usr/local/lib/python3.8/site-packages (20.0.13)
Requirement already satisfied: virtualenvwrapper in /usr/local/lib/python3.8/site-packages (4.8.4)
Requirement already satisfied: filelock<4,>=3.0.0 in /usr/local/lib/python3.8/site-packages (from virtualenv) (3.0.12)
Requirement already satisfied: appdirs<2,>=1.4.3 in /usr/local/lib/python3.8/site-packages (from virtualenv) (1.4.3)
Requirement already satisfied: six<2,>=1.9.0 in /usr/local/lib/python3.8/site-packages (from virtualenv) (1.14.0)
Requirement already satisfied: distlib<1,>=0.3.0 in /usr/local/lib/python3.8/site-packages (from virtualenv) (0.3.0)
Requirement already satisfied: stevedore in /usr/local/lib/python3.8/site-packages (from virtualenvwrapper) (1.32.0)
Requirement already satisfied: virtualenv-clone in /usr/local/lib/python3.8/site-packages (from virtualenvwrapper) (0.5.3)
Requirement already satisfied: pbr!=2.1.0,>=2.0.0 in /usr/local/lib/python3.8/site-packages (from stevedore->virtualenvwrapper) (5.4.4)
today@5 ~/dev/MST/server(master)$ which virtualenv
/usr/local/bin/virtualenv
today@5 ~/dev/MST/server(master)$ which virtualenvwrapper
today@5 ~/dev/MST/server(master)$ 
today@5 ~/dev/MST/server(master)$ workon
today@5 ~/dev/MST/server(master)$ 
today@5 ~/dev/MST/server(master)$ mkvirtualenv test
usage: virtualenv [--version] [--with-traceback] [-v | -q] [--app-data APP_DATA] [--clear-app-data] [--discovery {builtin}] [-p py] [--creator {builtin,cpython3-posix,venv}] [--seeder {app-data,pip}] [--no-seed]
                  [--activators comma_sep_list] [--clear] [--system-site-packages] [--symlinks | --copies] [--download | --no-download] [--extra-search-dir d [d ...]] [--pip version] [--setuptools version] [--wheel version] [--no-pip]
                  [--no-setuptools] [--no-wheel] [--symlink-app-data] [--prompt prompt] [-h]
                  dest
virtualenv: error: unrecognized arguments: --no-site-packages

~/.bash_profile

#…
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/Devel
export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python3
export VIRTUALENVWRAPPER_VIRTUALENV=/usr/local/bin/virtualenv
export VIRTUALENVWRAPPER_VIRTUALENV_ARGS='--no-site-packages'

source /usr/local/bin/virtualenvwrapper.sh
#…

NB -
  • 尝试安装virtualenvwrapper时,它显示版本4.8.4,但在线文档中说它在5.x中。
1个回答

35

--no-site-packagesvirtualenv 的默认选项(已经持续了5年左右?),你可以从你的 .bashrc 文件中删除 export VIRTUALENVWRAPPER_VIRTUALENV_ARGS='--no-site-packages'

virtualenv>=20 版本中,这个选项似乎已被删除。


我能读懂你的话,但不知道你在说什么/为什么它有效 :). 它有效,但你知道在哪里可以学到更多关于它们之间的区别吗?我从来没有擅长底层操作系统方面的东西:\ 谢谢! - chris Frisina
你想要解释哪个部分?源代码的工作方式是从文件中运行一组命令,export X=Y 将在你的 shell 环境中设置一个全局变量 XY。没有任何东西可以取消这个设置,因此重新运行源代码对你没有帮助。 - anthony sottile
1
我认为永远不要重新加载rc文件,始终使用新的会话是最好的选择(正如你上面看到的原因^^)。 - anthony sottile
2
@AnthonySottile,进行快速测试,只需执行unset VIRTUALENVWRAPPER_VIRTUALENV_ARGS即可。 - Robert P. Goldman
运行 printenv 命令查看混乱的信息。然后前往你的 bash 配置文件 ~/.bash_profile(或其他类型文件)清理混乱的信息。通常这是由于旧的环境配置被遗忘所导致的。 - KeitelDOG
显示剩余3条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接