0

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

user1315621
  • 3,044
  • 9
  • 42
  • 86

1 Answers1

0

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.

Evgeny Tanhilevich
  • 1,119
  • 1
  • 8
  • 17
  • Yes this works. But is the behavior above normal? I don't remember it pip being broken like that – user1315621 Oct 13 '21 at 16:25
  • The details of where pip installs packages strongly depend on the details of your setup, i.e. if you are using virtual environments, some other environment managers (Anaconda, etc) and other stuff. I have experienced this issue myself on a vanilla python installation, so I guess it is pretty normal. See here: https://stackoverflow.com/questions/29980798/where-does-pip-install-its-packages for a more detailed discussion of where pip installs packages – Evgeny Tanhilevich Oct 13 '21 at 16:41
  • With `vanilla python installation` you mean no virtualenv / conda / etc? – user1315621 Oct 13 '21 at 17:05
  • 1
    Yes, that is correct – Evgeny Tanhilevich Oct 13 '21 at 17:09
  • If you want to add that tot he answer that could help in the future other people – user1315621 Oct 14 '21 at 16:59