Search code examples
pythonpython-3.xpython-venv

Python virtual environment (venv) user packages


Does the concept of user packages exist for venv? I activated a venv, and tried:

$ pip3 install --user times2

However, pip3 list does not show the package, and pip3 uninstall times2 shows:

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

EDIT: adding a complete printout:

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'
>>>

Solution

  • It surely exist and you made it happen.

    You passed that --user argument to pip and so instructed it to "place the provided packages in the user directory instead of the default".

    The default in your case is inside the activated virtual environment and if you hadn't activated it prior to call then it would have been installed in the system directory.

    Deactivate your environment and pip3 freeze will show the package, sudo pip3 freeze won't show it and in GNU/Linux locate times2 will find it somewhere bellow ~/local/.