Failed to install pytorch without root permission

Hmmm. Finally, I had PyTorch successfully built from source, using CMake.
However, in order to have python torch enabled, it seems I had to use the following commands: python setup.py build and python setup.py install, but failed with Permission denied. If I install with sudo, everything will be installed under /root/.local, instead of /home/username/.local .

➜  pytorch git:(master) ✗ python setup.py install --user
Building wheel torch-1.8.0a0
-- Building version 1.8.0a0
cmake --build . --target install --config Release -- -j 48
[0/1] Install the project...
-- Install configuration: "Release"
CMake Error at cmake_install.cmake:119 (file):
  file failed to open for writing (Permission denied):

    ........./pytorch/build/install_manifest.txt


FAILED: CMakeFiles/install.util 
cd ........./pytorch/build && /usr/local/bin/cmake -P cmake_install.cmake
ninja: build stopped: subcommand failed.
Traceback (most recent call last):
  File "setup.py", line 762, in <module>
    build_deps()
  File "setup.py", line 312, in build_deps
    build_caffe2(version=version,
  File "........./pytorch/tools/build_pytorch_libs.py", line 58, in build_caffe2
    cmake.build(my_env)
  File "........./pytorch/tools/setup_helpers/cmake.py", line 346, in build
    self.run(build_args, my_env)
  File "........./pytorch/tools/setup_helpers/cmake.py", line 141, in run
    check_call(command, cwd=self.build_dir, env=env)
  File "/usr/lib/python3.8/subprocess.py", line 364, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['cmake', '--build', '.', '--target', 'install', '--config', 'Release', '--', '-j', '48']' returned non-zero exit status 1.

Any anybody help please?

Cheers

Could you check the permissions of the pytorch/build folder and if your user doesn’t have the proper permissions, remove it and retry the installation?

For what it’s worth, I had a similar error when installing via python setup.py develop. But my “Permission denied” error was coming from the build-script running Ninja, and for some reason it was attempting to run /usr/local/bin/ninja --version rather than /home/username/conda-env/bin/ninja --version.

I couldn’t get the build-script to use the correct Ninja, but the solution that worked for me was to run python setup.py develop --cmake instead.