How to install torch in python - 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.

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

Related

Python pip - Cant update pip

I tried upgrading pip on python version 3.6 but failed
I used this command:
python -m pip install --upgrade pip
And got this error:
C:\Users\home>python -m pip install --upgrade pip
Collecting pip
Using cached https://files.pythonhosted.org/packages/cb/28/91f26bd088ce8e22169032100d4260614fc3da435025ff389ef1d396a433/pip-20.2.4-py2.py3-none-any.whl
Installing collected packages: pip
Found existing installation: pip 7.1.2
Uninstalling pip-7.1.2:
Successfully uninstalled pip-7.1.2
Rolling back uninstall of pip
Exception:
Traceback (most recent call last):
File "C:\Users\home\AppData\Local\Programs\Python\Python37\lib\site-packages\pip\basecommand.py", line 211, in main
status = self.run(options, args)
File "C:\Users\home\AppData\Local\Programs\Python\Python37\lib\site-packages\pip\commands\install.py", line 311, in run
root=options.root_path,
File "C:\Users\home\AppData\Local\Programs\Python\Python37\lib\site-packages\pip\req\req_set.py", line 646, in install
**kwargs
File "C:\Users\home\AppData\Local\Programs\Python\Python37\lib\site-packages\pip\req\req_install.py", line 803, in install
self.move_wheel_files(self.source_dir, root=root)
File "C:\Users\home\AppData\Local\Programs\Python\Python37\lib\site-packages\pip\req\req_install.py", line 998, in move_wheel_files
isolated=self.isolated,
File "C:\Users\home\AppData\Local\Programs\Python\Python37\lib\site-packages\pip\wheel.py", line 449, in move_wheel_files
generated.extend(maker.make(spec))
File "C:\Users\home\AppData\Local\Programs\Python\Python37\lib\site-packages\pip\_vendor\distlib\scripts.py", line 353, in make
self._make_script(entry, filenames, options=options)
File "C:\Users\home\AppData\Local\Programs\Python\Python37\lib\site-packages\pip\_vendor\distlib\scripts.py", line 257, in _make_script
self._write_script(scriptnames, shebang, script, filenames, ext)
File "C:\Users\home\AppData\Local\Programs\Python\Python37\lib\site-packages\pip\_vendor\distlib\scripts.py", line 193, in _write_script
launcher = self._get_launcher('t')
File "C:\Users\home\AppData\Local\Programs\Python\Python37\lib\site-packages\pip\_vendor\distlib\scripts.py", line 332, in _get_launcher
result = finder(distlib_package).find(name).bytes
File "C:\Users\home\AppData\Local\Programs\Python\Python37\lib\site-packages\pip\_vendor\distlib\resources.py", line 324, in finder
raise DistlibException('Unable to locate finder for %r' % package)
pip._vendor.distlib.DistlibException: Unable to locate finder for 'pip._vendor.distlib'
easy_install --upgrade pip solved it

Error about Python when installing Tensorflow

Am have tried to download both tensorflow and tensorflow-gpu on Ubuntu16.04, it didn't work..
I was using pip install -i https://pypi.tuna.tsinghua.edu.cn/simple --upgrade tensorflow-gpu
It's ok at first, but after a while it was stuck. it appears ERROR like below:
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting tensorflow-gpu
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/ce/9a/6a3985daf15d0b87b1ef3c499293cf0889cd294223a6ca28b9529770b29e/tensorflow_gpu-2.0.0-cp27-cp27mu-manylinux2010_x86_64.whl (380.8MB)
|▍ | 4.8MB 8.0kB/s eta 13:03:00ERROR: Exception:
Traceback (most recent call last):
File "/home/bayar/.local/lib/python2.7/site-packages/pip/_internal/cli/base_command.py", line 153, in _main
status = self.run(options, args)
File "/home/bayar/.local/lib/python2.7/site-packages/pip/_internal/commands/install.py", line 382, in run
resolver.resolve(requirement_set)
File "/home/bayar/.local/lib/python2.7/site-packages/pip/_internal/legacy_resolve.py", line 201, in resolve
self._resolve_one(requirement_set, req)
File "/home/bayar/.local/lib/python2.7/site-packages/pip/_internal/legacy_resolve.py", line 365, in _resolve_one
abstract_dist = self._get_abstract_dist_for(req_to_install)
File "/home/bayar/.local/lib/python2.7/site-packages/pip/_internal/legacy_resolve.py", line 313, in _get_abstract_dist_for
req, self.session, self.finder, self.require_hashes
File "/home/bayar/.local/lib/python2.7/site-packages/pip/_internal/operations/prepare.py", line 194, in prepare_linked_requirement
progress_bar=self.progress_bar
File "/home/bayar/.local/lib/python2.7/site-packages/pip/_internal/download.py", line 465, in unpack_url
progress_bar=progress_bar
File "/home/bayar/.local/lib/python2.7/site-packages/pip/_internal/download.py", line 316, in unpack_http_url
progress_bar)
File "/home/bayar/.local/lib/python2.7/site-packages/pip/_internal/download.py", line 551, in _download_http_url
_download_url(resp, link, content_file, hashes, progress_bar)
File "/home/bayar/.local/lib/python2.7/site-packages/pip/_internal/download.py", line 253, in _download_url
hashes.check_against_chunks(downloaded_chunks)
File "/home/bayar/.local/lib/python2.7/site-packages/pip/_internal/utils/hashes.py", line 80, in check_against_chunks
for chunk in chunks:
File "/home/bayar/.local/lib/python2.7/site-packages/pip/_internal/download.py", line 223, in written_chunks
for chunk in chunks:
File "/home/bayar/.local/lib/python2.7/site-packages/pip/_internal/utils/ui.py", line 160, in iter
for x in it:
File "/home/bayar/.local/lib/python2.7/site-packages/pip/_internal/download.py", line 212, in resp_read
decode_content=False):
File "/home/bayar/.local/lib/python2.7/site-packages/pip/_vendor/urllib3/response.py", line 564, in stream
data = self.read(amt=amt, decode_content=decode_content)
File "/home/bayar/.local/lib/python2.7/site-packages/pip/_vendor/urllib3/response.py", line 529, in read
raise IncompleteRead(self._fp_bytes_read, self.length_remaining)
File "/usr/lib/python2.7/contextlib.py", line 35, in __exit__
self.gen.throw(type, value, traceback)
File "/home/bayar/.local/lib/python2.7/site-packages/pip/_vendor/urllib3/response.py", line 439, in _error_catcher
raise ReadTimeoutError(self._pool, None, "Read timed out.")
ReadTimeoutError: HTTPSConnectionPool(host='pypi.tuna.tsinghua.edu.cn', port=443): Read timed out.
I have tried several times. I thought it were problem caused by pip, so I used pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple --upgrade tensorflow-gpu also. However, another problem came up.
pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple --upgrade tensorflow-gpu
Collecting tensorflow-gpu
Could not find a version that satisfies the requirement tensorflow-gpu (from versions: )
No matching distribution found for tensorflow-gpu
Could you do me a favor?
To install tensorflow try this
pip3 install --upgrade tensorflow
To install tensorflow-gpu try this
pip3 install tensorflow-gpu
Check your python path using
which python
If this is equal to the python's expected path
then use the following commands to install the packages.
python -m pip install tensorflow
python -m pip install tensorflow-gpu

pip install packages in Python runing into errors

I am trying to install a few packages in Python. For example trying to install quantmod but was told to upgrade my pip which I did through Anaconda prompt but when I go to try and install quantmod again I get the same error message. This happens with all packages I am trying to install...
I am running pip install quantmod and to upgrade pip this python -m pip install --upgrade pip
(base) C:\Users\USER\AppData\Local\Programs\Python\Python36-32>pip install quantmod
Collecting quantmod
Could not find a version that satisfies the requirement quantmod (from versions: )
No matching distribution found for quantmod
You are using pip version 9.0.1, however version 10.0.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
(base) C:\Users\USER\AppData\Local\Programs\Python\Python36-32>python -m pip install --upgrade pip
Requirement already up-to-date: pip in c:\users\USER\appdata\local\programs\python\python36-32\lib\site-packages (10.0.1)
(base) C:\Users\USER\AppData\Local\Programs\Python\Python36-32>pip install quantmod
Collecting quantmod
Could not find a version that satisfies the requirement quantmod (from versions: )
No matching distribution found for quantmod
You are using pip version 9.0.1, however version 10.0.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
EDIT 1 with pip install --upgrade pip:
Exception:
Traceback (most recent call last):
File "C:\Users\USER\Anaconda3\lib\site-packages\pip\basecommand.py", line 215, in main
status = self.run(options, args)
File "C:\Users\USER\Anaconda3\lib\site-packages\pip\commands\install.py", line 335, in run
wb.build(autobuilding=True)
File "C:\Users\USER\Anaconda3\lib\site-packages\pip\wheel.py", line 749, in build
self.requirement_set.prepare_files(self.finder)
File "C:\Users\USER\Anaconda3\lib\site-packages\pip\req\req_set.py", line 380, in prepare_files
ignore_dependencies=self.ignore_dependencies))
File "C:\Users\USER\Anaconda3\lib\site-packages\pip\req\req_set.py", line 487, in _prepare_file
req_to_install, finder)
File "C:\Users\USER\Anaconda3\lib\site-packages\pip\req\req_set.py", line 428, in _check_skip_installed
req_to_install, upgrade_allowed)
File "C:\Users\USER\Anaconda3\lib\site-packages\pip\index.py", line 465, in find_requirement
all_candidates = self.find_all_candidates(req.name)
File "C:\Users\USER\Anaconda3\lib\site-packages\pip\index.py", line 423, in find_all_candidates
for page in self._get_pages(url_locations, project_name):
File "C:\Users\USER\Anaconda3\lib\site-packages\pip\index.py", line 568, in _get_pages
page = self._get_page(location)
File "C:\Users\USERR\Anaconda3\lib\site-packages\pip\index.py", line 683, in _get_page
return HTMLPage.get_page(link, session=self.session)
File "C:\Users\USER\Anaconda3\lib\site-packages\pip\index.py", line 811, in get_page
inst = cls(resp.content, resp.url, resp.headers)
File "C:\Users\USER\Anaconda3\lib\site-packages\pip\index.py", line 731, in __init__
namespaceHTMLElements=False,
TypeError: parse() got an unexpected keyword argument 'transport_encoding'
You are using pip version 9.0.1, however version 10.0.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
(base) C:\Users\USER\AppData\Local\Programs\Python\Python36-32>
EDIT:
(base) C:\Users\USER\AppData\Local\Programs\Python\Python36-32>pip install Gensim
Collecting Gensim
Exception:
Traceback (most recent call last):
File "C:\Users\USER\Anaconda3\lib\site-packages\pip\basecommand.py", line 215, in main
status = self.run(options, args)
File "C:\Users\USER\Anaconda3\lib\site-packages\pip\commands\install.py", line 335, in run
wb.build(autobuilding=True)
File "C:\Users\USER\Anaconda3\lib\site-packages\pip\wheel.py", line 749, in build
self.requirement_set.prepare_files(self.finder)
File "C:\Users\USER\Anaconda3\lib\site-packages\pip\req\req_set.py", line 380, in prepare_files
ignore_dependencies=self.ignore_dependencies))
File "C:\Users\USER\Anaconda3\lib\site-packages\pip\req\req_set.py", line 554, in _prepare_file
require_hashes
File "C:\Users\USER\Anaconda3\lib\site-packages\pip\req\req_install.py", line 278, in populate_link
self.link = finder.find_requirement(self, upgrade)
File "C:\Users\USER\Anaconda3\lib\site-packages\pip\index.py", line 465, in find_requirement
all_candidates = self.find_all_candidates(req.name)
File "C:\Users\USER\Anaconda3\lib\site-packages\pip\index.py", line 423, in find_all_candidates
for page in self._get_pages(url_locations, project_name):
File "C:\Users\USER\Anaconda3\lib\site-packages\pip\index.py", line 568, in _get_pages
page = self._get_page(location)
File "C:\Users\USER\Anaconda3\lib\site-packages\pip\index.py", line 683, in _get_page
return HTMLPage.get_page(link, session=self.session)
File "C:\Users\USER\Anaconda3\lib\site-packages\pip\index.py", line 811, in get_page
inst = cls(resp.content, resp.url, resp.headers)
File "C:\Users\USER\Anaconda3\lib\site-packages\pip\index.py", line 731, in __init__
namespaceHTMLElements=False,
TypeError: parse() got an unexpected keyword argument 'transport_encoding'
You are using pip version 9.0.1, however version 10.0.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

Pip won't install anything or upgrade and can't be removed

I'm on Python 3.6 and trying to use py -m pip install discord.py to install the discord package to write a discord bot. However, that command works most of the way until it says Rolling back uninstall of pip and then it crashes like so:
Exception:
Traceback (most recent call last):
File "C:\Program Files\Python36\lib\site-packages\pip\basecommand.py", line 211, in main
status = self.run(options, args)
File "C:\Program Files\Python36\lib\site-packages\pip\commands\install.py", line 311, in run
root=options.root_path,
File "C:\Program Files\Python36\lib\site-packages\pip\req\req_set.py", line 646, in install
**kwargs
File "C:\Program Files\Python36\lib\site-packages\pip\req\req_install.py", line 803, in install
self.move_wheel_files(self.source_dir, root=root)
File "C:\Program Files\Python36\lib\site-packages\pip\req\req_install.py", line 998, in move_wheel_files
isolated=self.isolated,
File "C:\Program Files\Python36\lib\site-packages\pip\wheel.py", line 449, in move_wheel_files
generated.extend(maker.make(spec))
File "C:\Program Files\Python36\lib\site-packages\pip_vendor\distlib\scripts.py", line 353, in make
self._make_script(entry, filenames, options=options)
File "C:\Program Files\Python36\lib\site-packages\pip_vendor\distlib\scripts.py", line 257, in _make_script
self._write_script(scriptnames, shebang, script, filenames, ext)
File "C:\Program Files\Python36\lib\site-packages\pip_vendor\distlib\scripts.py", line 193, in _write_script
launcher = self._get_launcher('t')
File "C:\Program Files\Python36\lib\site-packages\pip_vendor\distlib\scripts.py", line 332, in _get_launcher
result = finder(distlib_package).find(name).bytes
File "C:\Program Files\Python36\lib\site-packages\pip_vendor\distlib\resources.py", line 324, in finder
raise DistlibException('Unable to locate finder for %r' % package)
pip._vendor.distlib.DistlibException: Unable to locate finder for 'pip._vendor.distlib'
You are using pip version 7.1.2, however version 9.0.3 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
So I try updating pip with py -m pip install --upgrade pip and it works most of the way until Rolling back uninstall of pip where it says:
Exception:
Traceback (most recent call last):
File "C:\Program Files\Python36\lib\site-packages\pip\basecommand.py", line 211, in main
status = self.run(options, args)
File "C:\Program Files\Python36\lib\site-packages\pip\commands\install.py", line 311, in run
root=options.root_path,
File "C:\Program Files\Python36\lib\site-packages\pip\req\req_set.py", line 646, in install
**kwargs
File "C:\Program Files\Python36\lib\site-packages\pip\req\req_install.py", line 803, in install
self.move_wheel_files(self.source_dir, root=root)
File "C:\Program Files\Python36\lib\site-packages\pip\req\req_install.py", line 998, in move_wheel_files
isolated=self.isolated,
File "C:\Program Files\Python36\lib\site-packages\pip\wheel.py", line 449, in move_wheel_files
generated.extend(maker.make(spec))
File "C:\Program Files\Python36\lib\site-packages\pip_vendor\distlib\scripts.py", line 353, in make
self._make_script(entry, filenames, options=options)
File "C:\Program Files\Python36\lib\site-packages\pip_vendor\distlib\scripts.py", line 257, in _make_script
self._write_script(scriptnames, shebang, script, filenames, ext)
File "C:\Program Files\Python36\lib\site-packages\pip_vendor\distlib\scripts.py", line 193, in _write_script
launcher = self._get_launcher('t')
File "C:\Program Files\Python36\lib\site-packages\pip_vendor\distlib\scripts.py", line 332, in _get_launcher
result = finder(distlib_package).find(name).bytes
File "C:\Program Files\Python36\lib\site-packages\pip_vendor\distlib\resources.py", line 324, in finder
raise DistlibException('Unable to locate finder for %r' % package)
pip._vendor.distlib.DistlibException: Unable to locate finder for 'pip._vendor.distlib'
You are using pip version 7.1.2, however version 9.0.3 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
Oddly enough, trying to just run pip in the command prompt it gives me 'pip' is not recognized as an internal or external command,
operable program or batch file.
I've tried uninstalling with py -m pip uninstall pip setuptools and reinstalling by running py get-pip.py on the python file, none of which seem to do anything.
So I have no way of uninstalling, reinstalling, or upgrading pip, and I can't use the current version of pip to install anything. I've searched for hours and tried changing my PATH variable and looking at file path limits, but I'm completly stuck and very new to this type of thing. I'm on Windows 10.
EDIT: "pip", "pip3", "python" and "python3" commands don't work. "py" command works.
EDIT: I seem to have gotten around using pip this time. I downloaded the discord package from github then followed instructions here which say to run py setup.py install --user. Still, I'd like to be able to use pip in the future.
There are couple solutions. You can reinstall python and during installation add it to environmental variable. Another way would be adding scripts and python to environmental path. http://www.correlatedsolutions.com/support/index.php?/Knowledgebase/Article/View/85/1/running-python-scripts-from-anywhere-under-windows.

Install tensorflow via pip but failed just as follows

Traceback (most recent call last):<br>
File "/usr/local/lib/python2.7/dist-packages/pip/basecommand.py", line 215, in main<br>
status = self.run(options, args)<br>
File "/usr/local/lib/python2.7/dist-packages/pip/commands/install.py", line 335, in run<br>
wb.build(autobuilding=True)<br>
File "/usr/local/lib/python2.7/dist-packages/pip/wheel.py", line 749, in build<br>
self.requirement_set.prepare_files(self.finder)<br>
File "/usr/local/lib/python2.7/dist-packages/pip/req/req_set.py", line 380, in prepare_files
ignore_dependencies=self.ignore_dependencies))<br>
File "/usr/local/lib/python2.7/dist-packages/pip/req/req_set.py", line 620, in _prepare_file
session=self.session, hashes=hashes)<br>
File "/usr/local/lib/python2.7/dist-packages/pip/download.py", line 821, in unpack_url
hashes=hashes<br>
File "/usr/local/lib/python2.7/dist-packages/pip/download.py", line 659, in unpack_http_url
hashes)<br>
File "/usr/local/lib/python2.7/dist-packages/pip/download.py", line 882, in _download_http_url
_download_url(resp, link, content_file, hashes)<br>
File "/usr/local/lib/python2.7/dist-packages/pip/download.py", line 603, in _download_url
hashes.check_against_chunks(downloaded_chunks)<br>
File "/usr/local/lib/python2.7/dist-packages/pip/utils/hashes.py", line 46, in check_against_chunks<br>
for chunk in chunks:<br>
File "/usr/local/lib/python2.7/dist-packages/pip/download.py", line 571, in written_chunks
for chunk in chunks:<br>
File "/usr/local/lib/python2.7/dist-packages/pip/utils/ui.py", line 139, in iter<br>
for x in it:<br>
File "/usr/local/lib/python2.7/dist-packages/pip/download.py", line 560, in resp_read
decode_content=False):<br>
File "/usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/packages/urllib3/response.py", line 357, in stream<br>
data = self.read(amt=amt, decode_content=decode_content)<br>
File "/usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/packages/urllib3/response.py", line 324, in read<br>
flush_decoder = True<br>
File "/usr/lib/python2.7/contextlib.py", line 35, in __exit__
self.gen.throw(type, value, traceback)<br>
File "/usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/packages/urllib3/response.py", line 246, in _error_catcher<br>
raise ReadTimeoutError(self._pool, None, 'Read timed out.')<br>
ReadTimeoutError: HTTPSConnectionPool(host='pypi.python.org', port=443): Read timed out.
I solved it by modifying the command like this:
pip --default-timeout=100 install THEPACKAGENAME
You can also try installing using wheel packages.
The Wheel packages depend on the kind of operating system you have, the python version and whether you want to install with CPU/GPU support.
Also upgrade you protobuf before installing Tensorflow.
Please find a list of packages here:
https://www.tensorflow.org/install/install_linux#the_url_of_the_tensorflow_python_package
You can then issue this command :
$ sudo pip install --upgrade <TF wheel package URL> - For Python 2.7
$ sudo pip3 install --upgrade <TF wheel package URL> - For Python 3.x
Tensorflow site has some details on some common installation problems. You can look at those as well, just in case.
https://www.tensorflow.org/install/install_linux#common_installation_problems

Categories