How does one install PyTorch and related tools from within the setup.py install_requires list?

username: Brando_Miranda
cooked: <p>I was trying to test the <code>pip install -e .</code> on <a href="https://github.com/brando90/ultimate-utils" rel="noopener nofollow ugc">my library ultimate-utils</a> after changing laptops but I keep getting errors of this type:</p>
<pre><code class="lang-auto">(uutils_env) brandomiranda~/ultimate-utils ❯ pip install -e .                      
Obtaining file:///Users/brandomiranda/ultimate-utils
  Preparing metadata (setup.py) ... done
ERROR: Could not find a version that satisfies the requirement torchvision==0.10.1 (from ultimate-utils) (from versions: 0.1.6, 0.1.7, 0.1.8, 0.1.9, 0.2.0, 0.2.1, 0.2.2, 0.2.2.post2, 0.2.2.post3)
ERROR: No matching distribution found for torchvision==0.10.1
</code></pre>
<p>where it seems it stopped working to install anything related to pytorch for some reason.</p>
<p>I tried updating pip and conda but it did not work. I did:</p>
<pre><code class="lang-auto">pip install --upgrade pip
conda update conda
conda update conda-build
conda update -n base -c defaults conda
conda update --name base conda
conda update --all
conda install anaconda
</code></pre>
<p>but none seem to work.</p>
<p>my setup.py looks as follows:</p>
<pre><code class="lang-auto">"""
conda create -n uutils_env python=3.9
conda activate uutils_env
conda remove --all --name uutils_env
rm -rf /Users/brando/anaconda3/envs/uutils_env

pip install -e ~/ultimate-utils/ultimate-utils-proj-src/

pip install ultimate-utils

To test it:
python -c "import uutils; uutils.hello()"
python -c "import uutils; uutils.torch_uu.hello()"

python -c "import uutils; uutils.torch_uu.gpu_test_torch_any_device()"
python -c "import uutils; uutils.torch_uu.gpu_test()"

PyTorch:
    basing the torch install from the pytorch website as of this writing: https://pytorch.org/get-started/locally/
    pip3 install torch==1.9.1+cu111 torchvision==0.10.1+cu111 torchaudio==0.9.1 -f https://download.pytorch.org/whl/torch_stable.html

refs:
    - setup tools: https://setuptools.pypa.io/en/latest/userguide/package_discovery.html#using-find-or-find-packages
"""
from setuptools import setup
from setuptools import find_packages
import os

# import pathlib

here = os.path.abspath(os.path.dirname(__file__))
with open(os.path.join(here, 'README.md'), encoding='utf-8') as f:
    long_description = f.read()

setup(
    name='ultimate-utils',  # project name
    version='0.5.3',
    description="Brando's ultimate utils for science, machine learning and AI",
    long_description=long_description,
    long_description_content_type="text/markdown",
    url='https://github.com/brando90/ultimate-utils',
    author='Brando Miranda',
    author_email='brandojazz@gmail.com',
    python_requires='&gt;=3.9.0',
    license='MIT',
    package_dir={'': 'ultimate-utils-proj-src'},
    packages=find_packages('ultimate-utils-proj-src'),  # imports all modules/folders with  __init__.py &amp; python files

    # for pytorch see doc string at the top of file
    install_requires=[
        # 'torch==1.9.1',
        'torchvision==0.10.1',
        'torchaudio==0.9.1',
        'dill',
        'networkx&gt;=2.5',
        'scipy',
        'scikit-learn',
        'lark-parser',
        'torchtext==0.10.1',
        'tensorboard',
        'pandas',
        'progressbar2',
        'transformers',
        'requests',
        'aiohttp',
        'numpy',
        'plotly',
        'wandb',
        'matplotlib',
        # 'seaborn'

        # 'pygraphviz'  # removing because it requires user to install graphviz and gives other issues
    ]
)
</code></pre>
<p>the dir structure is simple:</p>
<p><a href="https://i.stack.imgur.com/CX2pJ.png" rel="noopener nofollow ugc"><img src="https://i.stack.imgur.com/CX2pJ.png" alt="enter image description here" width="255" height="285"></a></p>
<p>How do I fix this and what is not working?</p>
<p>I am trying to avoid having to run pip commands outside like:</p>
<pre><code class="lang-auto">conda install pytorch torchvision torchaudio -c pytorch
</code></pre>
<p><strong>at least for cpu in my local laptop</strong>…if I can install gpu ones automatically with a flag it could be nice but for future work…</p>
<hr>
<p>Related resources I tried:</p>
<ul>
<li>
<p><a href="https://docs.conda.io/projects/conda-build/en/latest/install-conda-build.html" class="inline-onebox" rel="noopener nofollow ugc">Installing and updating conda-build — conda-build 3.21.7+2.g4ec7d8a7.dirty documentation</a></p>
</li>
<li>
<p><a href="https://stackoverflow.com/questions/51712693/packagenotinstallederror-package-is-not-installed-in-prefix" class="inline-onebox" rel="noopener nofollow ugc">python - PackageNotInstalledError: Package is not installed in prefix - Stack Overflow</a></p>
</li>
<li>
<p><a href="https://stackoverflow.com/questions/66738473/installing-pytorch-with-cuda-in-setup-py" class="inline-onebox" rel="noopener nofollow ugc">python - Installing PyTorch with CUDA in setup.py - Stack Overflow</a></p>
</li>
<li>
<p><a href="https://github.com/brando90/ultimate-utils" class="inline-onebox" rel="noopener nofollow ugc">GitHub - brando90/ultimate-utils: Brando's utils</a></p>
</li>
<li>
<p><a href="https://pytorch.org/get-started/locally/" class="inline-onebox" rel="noopener nofollow ugc">Start Locally | PyTorch</a></p>
</li>
<li>
<p><a href="https://stackoverflow.com/questions/70295885/how-does-one-install-pytorch-and-related-tools-from-within-the-setup-py-install" class="inline-onebox" rel="noopener nofollow ugc">python - How does one install PyTorch and related tools from within the setup.py install_requires list? - Stack Overflow</a></p>
</li>
</ul>

username: albanD
cooked: <p>Hi,</p>
<p>Given the list of available versions that it shows, my first guess is that it is not a supported platform and so the only binaries that are valid are (very) old universal binaries that we use to provide (by mistake).</p>
<p>What is your machine, python version, os, etc?</p>

username: Brando_Miranda
cooked: <p>I was using python 3.9, mac os X, macbook pro, let me think what else and try without those equalities…</p>
<p>I am using torchmeta: <a href="https://github.com/tristandeleu/pytorch-meta/blob/master/setup.py" class="inline-onebox" rel="noopener nofollow ugc">pytorch-meta/setup.py at master · tristandeleu/pytorch-meta · GitHub</a> that has</p>
<pre><code class="lang-auto">install_requires=[
        'torch&gt;=1.4.0,&lt;1.10.0',
        'torchvision&gt;=0.5.0,&lt;0.11.0',
        'numpy&gt;=1.14.0',
        'Pillow&gt;=7.0.0',
        'h5py',
        'tqdm&gt;=4.0.0',
        'requests',  # Required by Torchvision
        'ordered-set'
    ],
</code></pre>
<aside class="onebox githubissue" data-onebox-src="https://github.com/tristandeleu/pytorch-meta/issues/146">
  <header class="source">

      <a href="https://github.com/tristandeleu/pytorch-meta/issues/146" target="_blank" rel="noopener nofollow ugc">github.com/tristandeleu/pytorch-meta</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 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/tristandeleu/pytorch-meta/issues/146" target="_blank" rel="noopener nofollow ugc">version of torchaudio?</a>
    </h4>

    <div class="github-info">
      <div class="date">
        opened <span class="discourse-local-date" data-format="ll" data-date="2021-12-09" data-time="23:25:17" data-timezone="UTC">11:25PM - 09 Dec 21 UTC</span>
      </div>


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

    <div class="labels">
    </div>
  </div>
</div>

  <div class="github-row">
    <p class="github-body-container">```
        'torchaudio&gt;=0.9.1',
```

works?https://discuss.pytorch.org/t/ho<span class="show-more-container"><a href="" rel="noopener" class="show-more">…</a></span><span class="excerpt hidden">w-does-one-install-pytorch-and-related-tools-from-within-the-setup-py-install-requires-list/138976/3</span></p>
  </div>

  </article>

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

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


username: Brando_Miranda
cooked: <p><a class="mention" href="/u/alband">@albanD</a> was this suppose to fail too?</p>
<pre><code class="lang-auto">    install_requires=[
        'torch&gt;=1.4.0,&lt;1.10.0',
        'torchvision&gt;=0.5.0,&lt;0.11.0',
        'torchaudio&gt;=0.9.1',
</code></pre>
<p>error:</p>
<pre><code class="lang-auto">(uutils_env) brandomiranda~/ultimate-utils ❯ pip install -e .
Obtaining file:///Users/brandomiranda/ultimate-utils
  Preparing metadata (setup.py) ... done
ERROR: Could not find a version that satisfies the requirement torch&lt;1.10.0,&gt;=1.4.0 (from ultimate-utils) (from versions: none)
ERROR: No matching distribution found for torch&lt;1.10.0,&gt;=1.4.0
</code></pre>
<p>why is it saying</p>
<pre><code class="lang-auto">(from versions: none)
</code></pre>
<p>??</p>
<hr>
<p>I think it’s the python 3.10 version that causes the issues, bizarre, why is that…? Saying that since the current installation seems to be working:</p>
<pre><code class="lang-auto">(meta_learning) brandomiranda~ ❯ conda create -n uutils_env python=3.9
conda activate uutils_env
Collecting package metadata (current_repodata.json): done
Solving environment: done

## Package Plan ##

  environment location: /Users/brandomiranda/miniconda3/envs/uutils_env

  added / updated specs:
    - python=3.9


The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    certifi-2021.10.8          |   py39hecd8cb5_0         151 KB
    pip-21.2.4                 |   py39hecd8cb5_0         1.8 MB
    python-3.9.7               |       h88f2d9e_1         9.8 MB
    setuptools-58.0.4          |   py39hecd8cb5_0         792 KB
    ------------------------------------------------------------
                                           Total:        12.5 MB

The following NEW packages will be INSTALLED:

  ca-certificates    pkgs/main/osx-64::ca-certificates-2021.10.26-hecd8cb5_2
  certifi            pkgs/main/osx-64::certifi-2021.10.8-py39hecd8cb5_0
  libcxx             pkgs/main/osx-64::libcxx-12.0.0-h2f01273_0
  libffi             pkgs/main/osx-64::libffi-3.3-hb1e8313_2
  ncurses            pkgs/main/osx-64::ncurses-6.3-hca72f7f_2
  openssl            pkgs/main/osx-64::openssl-1.1.1l-h9ed2024_0
  pip                pkgs/main/osx-64::pip-21.2.4-py39hecd8cb5_0
  python             pkgs/main/osx-64::python-3.9.7-h88f2d9e_1
  readline           pkgs/main/osx-64::readline-8.1-h9ed2024_0
  setuptools         pkgs/main/osx-64::setuptools-58.0.4-py39hecd8cb5_0
  sqlite             pkgs/main/osx-64::sqlite-3.36.0-hce871da_0
  tk                 pkgs/main/osx-64::tk-8.6.11-h7bc2e8c_0
  tzdata             pkgs/main/noarch::tzdata-2021e-hda174b7_0
  wheel              pkgs/main/noarch::wheel-0.37.0-pyhd3eb1b0_1
  xz                 pkgs/main/osx-64::xz-5.2.5-h1de35cc_0
  zlib               pkgs/main/osx-64::zlib-1.2.11-h1de35cc_3


Proceed ([y]/n)? 


Downloading and Extracting Packages
pip-21.2.4           | 1.8 MB    | ########################################################################################################################################## | 100% 
python-3.9.7         | 9.8 MB    | ########################################################################################################################################## | 100% 
setuptools-58.0.4    | 792 KB    | ########################################################################################################################################## | 100% 
certifi-2021.10.8    | 151 KB    | ########################################################################################################################################## | 100% 
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
#
# To activate this environment, use
#
#     $ conda activate uutils_env
#
# To deactivate an active environment, use
#
#     $ conda deactivate

</code></pre>
<p>then the pip install of my lib</p>
<pre><code class="lang-auto">(uutils_env) brandomiranda~/ultimate-utils ❯ pip install -e .
Obtaining file:///Users/brandomiranda/ultimate-utils
Collecting dill
  Using cached dill-0.3.4-py2.py3-none-any.whl (86 kB)
Collecting networkx&gt;=2.5
  Using cached networkx-2.6.3-py3-none-any.whl (1.9 MB)
Collecting scipy
  Downloading scipy-1.7.3-cp39-cp39-macosx_10_9_x86_64.whl (33.2 MB)
     |████████████████████████████████| 33.2 MB 56 kB/s 
Collecting scikit-learn
  Downloading scikit_learn-1.0.1-cp39-cp39-macosx_10_13_x86_64.whl (8.0 MB)
     |████████████████████████████████| 8.0 MB 51 kB/s 
Collecting lark-parser
  Using cached lark_parser-0.12.0-py2.py3-none-any.whl (103 kB)
Collecting torchtext==0.10.1
  Downloading torchtext-0.10.1-cp39-cp39-macosx_10_9_x86_64.whl (1.5 MB)
     |████████████████████████████████| 1.5 MB 76 kB/s 
Collecting tensorboard
  Downloading tensorboard-2.7.0-py3-none-any.whl (5.8 MB)
     |████████████████████████████████| 5.8 MB 97 kB/s 
Collecting pandas
  Downloading pandas-1.3.4-cp39-cp39-macosx_10_9_x86_64.whl (11.6 MB)
     |████████████████████████████████| 11.6 MB 88 kB/s 
Collecting progressbar2
  Downloading progressbar2-3.55.0-py2.py3-none-any.whl (26 kB)
Collecting transformers
  Downloading transformers-4.13.0-py3-none-any.whl (3.3 MB)
     |████████████████████████████████| 3.3 MB 58 kB/s 
Collecting requests
  Downloading requests-2.26.0-py2.py3-none-any.whl (62 kB)
     |████████████████████████████████| 62 kB 117 kB/s 
Collecting aiohttp
  Downloading aiohttp-3.8.1-cp39-cp39-macosx_10_9_x86_64.whl (574 kB)
     |████████████████████████████████| 574 kB 26 kB/s 
Collecting numpy
  Downloading numpy-1.21.4-cp39-cp39-macosx_10_9_x86_64.whl (17.0 MB)
     |████████████████████████████████| 17.0 MB 68 kB/s 
Collecting plotly
  Downloading plotly-5.4.0-py2.py3-none-any.whl (25.3 MB)
     |████████████████████████████████| 25.3 MB 55 kB/s 
Collecting wandb
  Downloading wandb-0.12.7-py2.py3-none-any.whl (1.7 MB)
     |████████████████████████████████| 1.7 MB 64 kB/s 
Collecting matplotlib
  Downloading matplotlib-3.5.0-cp39-cp39-macosx_10_9_x86_64.whl (7.3 MB)
     |████████████████████████████████| 7.3 MB 49 kB/s 
Collecting torch&lt;1.10.0,&gt;=1.4.0
  Downloading torch-1.9.1-cp39-none-macosx_10_9_x86_64.whl (218.8 MB)
     |███                             | 21.0 MB 66 kB/s eta 0:49:20
</code></pre>
<hr>
<p>I think I have those version since those are the ones I assume worked in my cluster since I have this command in my notes:</p>
<pre><code class="lang-auto">    pip3 install torch==1.9.1+cu111 torchvision==0.10.1+cu111 torchaudio==0.9.1 -f https://download.pytorch.org/whl/torch_stable.html

</code></pre>

username: Brando_Miranda
cooked: <p>It seems that once you sort out your PATH (which mine was broken details <a href="https://stackoverflow.com/questions/70307161/why-is-python-using-3-8-1-and-3-9-then-fail-to-install-packages-error-package?noredirect=1#comment124284866_70307161" class="inline-onebox" rel="noopener nofollow ugc">Why is python using 3.8.1 and 3.9, then fail to install packages (ERROR: Package pkg requires a different Python: 3.8.1 not in '&gt;=3.9.0')? - Stack Overflow</a>) then create a conda env with python 3.9 things seemed to work. Somehow Python 3.10 might be too new and borken.</p>