Python虚拟环境(venv)用户软件包

时间:2019-08-11 23:28:48

标签: python python-3.x python-venv

venv是否存在用户包的概念?我激活了一个静脉,并尝试:

$ pip3 install --user times2

但是,pip3 list没有显示该程序包,而pip3 uninstall times2显示了:

$ pip3 uninstall times2
Skipping times2 as it is not installed.

编辑:添加完整的打印输出:

rishai@mbp157:~$ python3 -m venv sw/venvsandbox2
rishai@mbp157:~$
rishai@mbp157:~$
rishai@mbp157:~$ source sw/venvsandbox2/bin/activate
(venvsandbox2) rishai@mbp157:~$
(venvsandbox2) rishai@mbp157:~$
(venvsandbox2) rishai@mbp157:~$ pip3 list
Package    Version
---------- -------
pip        19.0.3
setuptools 40.8.0
You are using pip version 19.0.3, however version 19.2.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
(venvsandbox2) rishai@mbp157:~$ pip3 install --user times2
Collecting times2
  Using cached https://files.pythonhosted.org/packages/e0/bc/22dbef03a9194dd4a7465a5a0be4b05f372fbdea7e9c59f0fd0caff8ca6f/times2-0.8-py2.py3-none-any.whl
Collecting python-dateutil (from times2)
  Using cached https://files.pythonhosted.org/packages/41/17/c62faccbfbd163c7f57f3844689e3a78bae1f403648a6afb1d0866d87fbb/python_dateutil-2.8.0-py2.py3-none-any.whl
Collecting pytz (from times2)
  Using cached https://files.pythonhosted.org/packages/87/76/46d697698a143e05f77bec5a526bf4e56a0be61d63425b68f4ba553b51f2/pytz-2019.2-py2.py3-none-any.whl
Collecting six>=1.5 (from python-dateutil->times2)
  Using cached https://files.pythonhosted.org/packages/73/fb/00a976f728d0d1fecfe898238ce23f502a721c0ac0ecfedb80e0d88c64e9/six-1.12.0-py2.py3-none-any.whl
Installing collected packages: six, python-dateutil, pytz, times2
Successfully installed python-dateutil-2.8.0 pytz-2019.2 six-1.12.0 times2-0.8
You are using pip version 19.0.3, however version 19.2.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
(venvsandbox2) rishai@mbp157:~$ pip3 list
Package    Version
---------- -------
pip        19.0.3
setuptools 40.8.0
You are using pip version 19.0.3, however version 19.2.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
(venvsandbox2) rishai@mbp157:~$ python3
Python 3.7.4 (default, Jul  9 2019, 18:13:23)
[Clang 10.0.1 (clang-1001.0.46.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import times2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'times2'
>>>

1 个答案:

答案 0 :(得分:1)

它肯定存在并且您实现了它。

您将--user参数传递给pip,并指示它“将提供的软件包放在用户目录中,而不是默认目录中。”

您的默认情况是在激活的虚拟环境中,如果您在调用之前未激活它,那么它将被安装在系统目录中。

停用您的环境,pip3 freeze将显示该软件包,sudo pip3 freeze将不会显示该软件包,而在GNU / Linux中,locate times2将在下面的~/local/处找到它。