Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install torch in python

I tried pip3 install torch --no-cache-dir and, after few seconds, I got this:

Collecting torch
      Downloading https://files.pythonhosted.org/packages/24/19/4804aea17cd136f1705a5e98a00618cb8f6ccc375ad8bfa437408e09d058/torch-1.4.0-cp36-cp36m-manylinux1_x86_64.whl (753.4MB)
        100% |████████████████████████████████| 753.4MB 5.7MB/s 
    Exception:
    Traceback (most recent call last):
      File "/usr/lib/python3/dist-packages/pip/basecommand.py", line 215, in main
        status = self.run(options, args)
      File "/usr/lib/python3/dist-packages/pip/commands/install.py", line 342, in run
        requirement_set.prepare_files(finder)
      File "/usr/lib/python3/dist-packages/pip/req/req_set.py", line 380, in prepare_files
        ignore_dependencies=self.ignore_dependencies))
      File "/usr/lib/python3/dist-packages/pip/req/req_set.py", line 620, in _prepare_file
        session=self.session, hashes=hashes)
      File "/usr/lib/python3/dist-packages/pip/download.py", line 821, in unpack_url
        hashes=hashes
      File "/usr/lib/python3/dist-packages/pip/download.py", line 663, in unpack_http_url
        unpack_file(from_path, location, content_type, link)
      File "/usr/lib/python3/dist-packages/pip/utils/__init__.py", line 617, in unpack_file
        flatten=not filename.endswith('.whl')
      File "/usr/lib/python3/dist-packages/pip/utils/__init__.py", line 506, in unzip_file
        data = zip.read(name)
      File "/usr/lib/python3.6/zipfile.py", line 1338, in read
        return fp.read()
      File "/usr/lib/python3.6/zipfile.py", line 858, in read
        buf += self._read1(self.MAX_N)
      File "/usr/lib/python3.6/zipfile.py", line 948, in _read1
        data = self._decompressor.decompress(data, n)
    MemoryError

What should I do now to install PyTorch?

I tried almost every method mentioned on google. I am working on Ubuntu, I tried using conda too, but I am unable to use that package outside conda.

like image 499
Mannya Avatar asked May 24 '26 19:05

Mannya


1 Answers

For pip environment use this

pip3 install torchvision

For conda environment use this (run this command on anaconda prompt)

conda install PyTorch -c PyTorch

Update

Use this code to turn off your cache

pip3 --no-cache-dir install torchvision

or

pip3 install torchvision--no-cache-dir

or

pip install --no-cache-dir torchvision

Try one by one

like image 200
Kalana Avatar answered May 27 '26 08:05

Kalana



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!