Building from source without root access

mahmoodn: <p>Hi,<br>
I would like to install Pytorch from source for CUDA 12.2. It seems that the default <code>python setup.py install</code> commands requires root access as you can see below:</p>
<pre><code class="lang-auto">-- Set runtime path of "/home/mahmood/pytorch/torch/test/cuda_vectorized_test" to "$ORIGIN:/usr/local/cuda-12.2/lib64"
-- Set runtime path of "/home/mahmood/pytorch/torch/test/cuda_cudnn_test" to "$ORIGIN:/usr/local/cuda-12.2/lib64"
CMake Error at caffe2/cmake_install.cmake:1866 (file):
  file INSTALL cannot make directory "/usr/lib/python3/dist-packages/caffe2":
  Permission denied.
Call Stack (most recent call first):
  cmake_install.cmake:139 (include)


gmake: *** [Makefile:110: install] Error 1
</code></pre>
<p>So, is there anyway to install that for current user? Something like <code>pip --user</code>.</p>

trusira: <p>Try changing <code>CMAKE_PREFIX_PATH</code> to a directory that does not require root permission.<br>
Eg. If you’re using conda, <code>export CMAKE_PREFIX_PATH=${CONDA_PREFIX:-"$(dirname $(which conda))/../"} </code></p>

mahmoodn: <p>I am not using Conda. The following commands ended with the same error:</p>
<pre><code class="lang-auto">CMAKE_PREFIX_PATH=/home/mahmood/pytorch/install
python setup.py clean
python setup.py develop
</code></pre>
<p>The output is</p>
<pre><code class="lang-auto">CMake Error at caffe2/cmake_install.cmake:1866 (file):
  file INSTALL cannot make directory "/usr/lib/python3/dist-packages/caffe2":
  Permission denied.
Call Stack (most recent call first):
  cmake_install.cmake:139 (include)
</code></pre>
<p>Sounds like there is a problem with caffe2.</p>

ptrblck: <p>No, the issue is that no new folders can be created in your current Python env as your user account does not have the right permissions as <a class="mention" href="/u/trusira">@trusira</a> also pointed towards.<br>
Either add permissions to the Python env for your user or try to use another virtual env, e.g. conda.</p>

mahmoodn: <p>Regardless of using Conda or not using Conda, the <code>CMAKE_PREFIX_PATH</code> should fix the problem but I don’t know why it is ignored. I assume that the default Python env should read that variable and install caffe2 in the local directory.</p>

tom: <p>I had the same problem, starting about a month ago.</p>
<p>I described the line I have comment out here:</p>
<aside class="onebox githubissue" data-onebox-src="https://github.com/pytorch/pytorch/issues/129304">
  <header class="source">

      <a href="https://github.com/pytorch/pytorch/issues/129304" target="_blank" rel="noopener nofollow ugc">github.com/pytorch/pytorch</a>
  </header>

  <article class="onebox-body">
    <div class="github-row">
  <div class="github-icon-container" title="Issue">
	  <svg width="60" height="60" class="github-icon" viewBox="0 0 14 16" aria-hidden="true"><path fill-rule="evenodd" d="M7 2.3c3.14 0 5.7 2.56 5.7 5.7s-2.56 5.7-5.7 5.7A5.71 5.71 0 0 1 1.3 8c0-3.14 2.56-5.7 5.7-5.7zM7 1C3.14 1 0 4.14 0 8s3.14 7 7 7 7-3.14 7-7-3.14-7-7-7zm1 3H6v5h2V4zm0 6H6v2h2v-2z"></path></svg>
  </div>

  <div class="github-info-container">
    <h4>
      <a href="https://github.com/pytorch/pytorch/issues/129304" target="_blank" rel="noopener nofollow ugc">`python3 setup.py bdist_wheel` tries to write to /usr/local/... during build</a>
    </h4>

    <div class="github-info">
      <div class="date">
        opened <span class="discourse-local-date" data-format="ll" data-date="2024-06-22" data-time="08:04:53" data-timezone="UTC">08:04AM - 22 Jun 24 UTC</span>
      </div>


      <div class="user">
        <a href="https://github.com/t-vi" target="_blank" rel="noopener nofollow ugc">
          <img alt="t-vi" src="https://avatars.githubusercontent.com/u/20787943?v=4" class="onebox-avatar-inline" width="20" height="20">
          t-vi
        </a>
      </div>
    </div>

    <div class="labels">
        <span style="display:inline-block;margin-top:2px;background-color: #B8B8B8;padding: 2px;border-radius: 4px;color: #fff;margin-left: 3px;">
          needs reproduction
        </span>
        <span style="display:inline-block;margin-top:2px;background-color: #B8B8B8;padding: 2px;border-radius: 4px;color: #fff;margin-left: 3px;">
          module: build
        </span>
        <span style="display:inline-block;margin-top:2px;background-color: #B8B8B8;padding: 2px;border-radius: 4px;color: #fff;margin-left: 3px;">
          triaged
        </span>
        <span style="display:inline-block;margin-top:2px;background-color: #B8B8B8;padding: 2px;border-radius: 4px;color: #fff;margin-left: 3px;">
          module: regression
        </span>
    </div>
  </div>
</div>

  <div class="github-row">
    <p class="github-body-container">### 🐛 Describe the bug

`python3 setup.py bdist_wheel` tries to write to /usr/lo<span class="show-more-container"><a href="" rel="noopener" class="show-more">…</a></span><span class="excerpt hidden">cal/... during build
The problem comes from the bottom of the caffe2/CMakeFiles.txt setting the Python lib rel path to the Python installation.

Seems related to #127683


### Versions

Main branch recently

cc @malfet @seemethere</span></p>
  </div>

  </article>

  <div class="onebox-metadata">
    
    
  </div>

  <div style="clear: both"></div>
</aside>


mahmoodn: <p>Agree with that… Seems that something is hard coded in the CMAKE file list.</p>