在 linux 中激活 virtualenv 无效
Activating virtualenv in linux isn't working
我已经在 Ubuntu 20.04 上安装了 virtualenv
。采购 activate
脚本后,它似乎已激活,但安装包似乎将其安装在用户的站点包中而不是虚拟环境中。
(venv) $ python3 -m pip install pytest
Requirement already satisfied: pytest in /home/xxx/.local/lib/python3.8/site-packages (6.2.5)
Requirement already satisfied: packaging in /home/xxx/.local/lib/python3.8/site-packages (from pytest) (20.9)
Requirement already satisfied: pluggy<2.0,>=0.12 in /home/xxx/.local/lib/python3.8/site-packages (from pytest) (1.0.0)
Requirement already satisfied: py>=1.8.2 in /home/xxx/.local/lib/python3.8/site-packages (from pytest) (1.10.0)
Requirement already satisfied: attrs>=19.2.0 in /home/xxx/.local/lib/python3.8/site-packages (fro
此外,当我 运行 Python 并查看 sys.path
:
['', '/usr/lib/python38.zip', '/usr/lib/python3.8', '/usr/lib/python3.8/lib-dynload', '/home/xxx/.local/lib/python3.8/site-packages', '/usr/local/lib/python3.8/dist-packages', '/usr/lib/python3/dist-packages']
我偷偷摸摸地说,在 virtualenv 中,你可能不需要调用 python3
而是 python
命令直接指向 Python 3 解释器 为那个 virtualenv。在这种情况下,调用 python3
明确指向您的全局 Python 3 env。毕竟,现代 virtualenvs 默认使用 Python 3 创建。
我已经在 Ubuntu 20.04 上安装了 virtualenv
。采购 activate
脚本后,它似乎已激活,但安装包似乎将其安装在用户的站点包中而不是虚拟环境中。
(venv) $ python3 -m pip install pytest
Requirement already satisfied: pytest in /home/xxx/.local/lib/python3.8/site-packages (6.2.5)
Requirement already satisfied: packaging in /home/xxx/.local/lib/python3.8/site-packages (from pytest) (20.9)
Requirement already satisfied: pluggy<2.0,>=0.12 in /home/xxx/.local/lib/python3.8/site-packages (from pytest) (1.0.0)
Requirement already satisfied: py>=1.8.2 in /home/xxx/.local/lib/python3.8/site-packages (from pytest) (1.10.0)
Requirement already satisfied: attrs>=19.2.0 in /home/xxx/.local/lib/python3.8/site-packages (fro
此外,当我 运行 Python 并查看 sys.path
:
['', '/usr/lib/python38.zip', '/usr/lib/python3.8', '/usr/lib/python3.8/lib-dynload', '/home/xxx/.local/lib/python3.8/site-packages', '/usr/local/lib/python3.8/dist-packages', '/usr/lib/python3/dist-packages']
我偷偷摸摸地说,在 virtualenv 中,你可能不需要调用 python3
而是 python
命令直接指向 Python 3 解释器 为那个 virtualenv。在这种情况下,调用 python3
明确指向您的全局 Python 3 env。毕竟,现代 virtualenvs 默认使用 Python 3 创建。