[Errno 13] Permission denied: '/usr/local/lib/python3.10/dist-packages/test-easy-install-1318227.write-test'

Hi, morning everyone:

I’m trying to build PyTorch from souce again, but got the ERROR message as titled:

running develop
~/.local/lib/python3.10/site-packages/setuptools/command/easy_install.py:144: EasyInstallDeprecationWarning: easy_install command is deprecated. Use build and pip and other standards-based tools.
  warnings.warn(
~/.local/lib/python3.10/site-packages/setuptools/command/install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
  warnings.warn(
error: can't create or remove files in install directory

The following error occurred while trying to add or remove files in the
installation directory:

    [Errno 13] Permission denied: '/usr/local/lib/python3.10/dist-packages/test-easy-install-1318227.write-test'

The installation directory you specified (via --install-dir, --prefix, or
the distutils default setting) was:

    /usr/local/lib/python3.10/dist-packages/

My ENV (Ubuntu 22.04 + Cuda 11.6.2)

➜  ~ uname -r
5.15.0-35-generic
➜  ~ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 22.04 LTS
Release:	22.04
Codename:	jammy
➜  ~ python --version
Python 3.10.4
➜  ~ gcc --version
gcc (Ubuntu 11.2.0-19ubuntu1) 11.2.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

My questions are:

  • What is the right way to build PyTorch with the pip command ?
  • And, how can I specify to just build but NOT install ?
  • Finally, how can I specify the default installation path (–target ??? ) to ~ with permission, instead of /usr/local without permission?

Thank you