Home > Enterprise >  Broken pip installation only works with sudo
Broken pip installation only works with sudo

Time:10-16

If I try to install something with pip e.g. python3 -m pip install torch==1.9.1 cu111 --find-links https://download.pytorch.org/whl/torch_stable.html I get the following error:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "/usr/lib/python3/dist-packages/pip/commands/install.py", line 290, in run
    with self._build_session(options) as session:
  File "/usr/lib/python3/dist-packages/pip/basecommand.py", line 69, in _build_session
    if options.cache_dir else None
  File "/usr/lib/python3.6/posixpath.py", line 80, in join
    a = os.fspath(a)
TypeError: expected str, bytes or os.PathLike object, not int

This throws the same error: python3 -m pip install --user torch==1.9.1 cu111 --find-links https://download.pytorch.org/whl/torch_stable.html. Installing with sudo does the job but it does not seem right. How can I fix my pip? I'm on Ubuntu 18.04 and Python 3.6

CodePudding user response:

Try

python3 -m pip install --user torch==1.9.1 cu111 --find-links https://download.pytorch.org/whl/torch_stable.html

This would install into your user directory.

Edit

The exact location where pip installs packages depends on many factors, including whether virtual environments or third party environment managers (e.g. conda) are used. It is of course OS and version dependent, too. There are lots of blogs and SO posts dedicated to the subject, like this one.

By default, if neither virtual env nor conda are used, reasonably recent python/pip versions on most Linux flavours write to either /usr/lib[64] or /usr/local/lib[64], both of which are root-writeable. A possible workaround is to use the --user flag, as mentioned above.

  • Related