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 build and python 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 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):


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 "", line 762, in <module>
  File "", line 312, in build_deps
  File "........./pytorch/tools/", line 58, in build_caffe2
  File "........./pytorch/tools/setup_helpers/", line 346, in build, my_env)
  File "........./pytorch/tools/setup_helpers/", line 141, in run
    check_call(command, cwd=self.build_dir, env=env)
  File "/usr/lib/python3.8/", 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?


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 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 develop --cmake instead.