"torch" and "pytorch" version mismatch in conda - python

I installed the following in an environment:
cudatoolkit=11.3
pytorch=1.11.0
torchvision=0.12.0
But when asking for the torch/cuda version I get this:
$ python3 -c "import torch; print(torch.__version__)"
1.12.1+cu102
Which is not what I want (1.12.1 would be fine, but cu102 is too old). Looking further, I see this:
$ conda list torch
# packages in environment at /home/ml/anaconda3/envs/ldm:
#
# Name Version Build Channel
pytorch 1.11.0 py3.8_cuda11.3_cudnn8.2.0_0 pytorch
pytorch-lightning 1.4.2 pypi_0 pypi
pytorch-mutex 1.0 cuda pytorch
torch 1.12.1 pypi_0 pypi
torch-fidelity 0.3.0 pypi_0 pypi
torchdiffeq 0.2.3 pypi_0 pypi
torchmetrics 0.6.0 pypi_0 pypi
torchvision 0.12.0 py38_cu113 pytorchcode
So "pytorch" has the version I want (with cuda11.3), but "torch" is 1.12.1. Why? Moreover, "torch" does not seem to be a conda package (PackagesNotFoundError when trying to install), which is surprising since it appears in "conda list".
There is clearly something I do not understand about conda / pytorch. Can someone please explain it?

From what I know, the torch package uses the LuaRocks Package manager. And if you use it mostly in python, you should aim for 'PyTorch', which conda only takes care of.
For your case, I strongly suggest you create a new environment and start again installing PyTorch and it's components from the beginning. Read this compatibility matrix and try to install it according to those tables.

So in the end that "torch" fake (?) package was my previous install of pytorch and cuda (with pip). The conda install actually made the pip one not work anymore ("import torch" was not working outside of the environment). Which is even weirder since my understanding of virtual environment was that it should at the very least not affect what's outside.
The solution was to reinstall pytorch with pip (outside the environment). After that, "import torch" worked inside the environment. Which again is weird since conda installed his own version of pytorch, apparently not to use it in the end.
I consider this an "answer" as it solves the problem I was having, but I still don't understand why conda behaved this way.

Related

Anaconda Navigator - using "conda install -c anaconda keras" installs incompatible tensorflow-dependencies

Using Anaconda Navigator (2.1.1),
creating a new environment via
conda create --name myenv1
and trying to install keras via
conda install -c anaconda keras
yields in
tensorflow 2.1.0
tensorflow-base 2.1.0
being installed, alongside with
tensorflow-estimator 2.6.0,
resulting into the infamous
"ModuleNotFoundError: No module named ‘tensorflow_core.estimator‘" in Python.
Is there anything I am doing wrong, or, why is compatibility not assured?
Could you please :
pip install -U tensorflow-estimator
Could you please use the later 2.x versions as many bugs are fixed, please try tf 2.6/2.7 and let us know.
you may also refer to similar issue here

Install PyTorch without installing Python 3.9 on Win7

Got clean installation of Anaconda (Python 3.8.8), tried to install PyTorch by running conda install pytorch torchvision torchaudio cudatoolkit=11.3 -c pytorch as suggested by the docs. The thing is, conda tries to install Python 3.9.7 in the process, which does not support Windows 7 (the famous "api-ms-win-core-path-l1-1-0.dll missing error"). Is there a way to make the installation of PyTorch without switching to the latest Python?
If you start with a clean package with a specific python version you could use the --freeze-installed flag to prevent the installer from making any changes to the installed packages, see documentation.

jupyter runs an old pytorch version

I have elementary knowledge on package managers, so forgive me if my question is phrased badly.
I am using miniconda as a package manager. I have python 3.8 installed, and I use jupyter lab to run ipython kernels.
My issue is that when import torch then the version 1.7.1 is loaded to the notebook, however, when I look at conda list I see that version 1.8.1 of torch is installed.
When I try to update using conda update --all and conda update pytorch nothing is being installed.
So
I don't know why pytorch is not updated to the new version of 1.9.
I don't know why an older version 1.7.1 is loaded to my jupyter notebook.
would love to get some help!
I am not sure exactly what solved it, but:
I updated homebrew which required me to install some command line tools of x-code, and then I managed to install pytorch again using
conda install pytorch torchvision -c pytorch.
Now the proper version is loaded when I use jupyter.

Cannot update python package on anaconda to latest version

Some of my python packages on anaconda cannot be updated to the latest version.
For instance, beautifulsoup4 latest version on anaconda is v4.71 as seen in the release notes.
https://docs.anaconda.com/anaconda/reference/release-notes/
However, when I run conda update beautifulsoup4, the latest version that I can update to is v4.6.
I discovered that the channel used by beautifulsoup4 is pypi.
# Name Version Build Channel
beautifulsoup4 4.6.0 pypi_0 pypi
bleach 3.1.0 py_0 conda-forge
I suspect if I were to change the channel from pypi to conda-forge, I should be able to update to the latest version.
How can I change the channel from pypi to conda-forge? Or does the solution lies somewhere else?
I am using Windows 10 64-bit, python 3.7.
I was running through this problem myself.
Let's take a look at versions in conda-forge and PyPi:
Conda Forge
PyPi
Both are actually up to date. So the problem here isn't as much the channels but conda mixing up the reference for the labels.
Update conda with
conda update
This will actually spew out a message telling you to run the command with a prefix for the proper path for your environment. Should be something like this:
conda update --prefix C:\Users\yourAccount\AppData\Local\Continuum\anaconda3 anaconda
Run that and it will update packages as well, including beautifulsoup4.
After this, you'll notice that creating new environment with just conda install beautifulsoup4 will return you the latest version.
Another curious thing to notice is that
There aren't distributions of 4.7 for Win-32 or Linux-32. So, if you are on either of those, updating conda won't help. You'll have to get the source code and build it yourself (if it is even possible).

Issues installing pytorch for OS X with conda

I used to have pytorch working for python 3 on OS X but now I can't get it to install automatically for some reason (I don't want to do from source).
I did:
conda install pytorch torchvision -c pytorch
as the website suggested... then I got a mkl error so I installed it but it still complains about it:
(FTIR_py3) brandomiranda~/home_simulation_research/FTIR/FTIR_proj $ conda install pytorch torchvision -c pytorch
Fetching package metadata ...........
Solving package specifications:
PackageNotFoundError: Package not found: '' Dependencies missing in current osx-64 channels:
- pytorch -> mkl >=2018
- torchvision -> pytorch >=0.3 -> mkl >=2018
You can search for packages on anaconda.org with
anaconda search -t conda mkl
You may need to install the anaconda-client command line client with
conda install anaconda-client
but I do have mkl:
(FTIR_py3) brandomiranda~/home_simulation_research/FTIR/FTIR_proj $ conda install mkl
Fetching package metadata .........
Solving package specifications: .
# All requested packages already installed.
# packages in environment at /Users/brandomiranda/miniconda3/envs/FTIR_py3:
#
mkl 2017.0.3 0
anyone know whats going on? it used to work a few days ago...
longer thread on pytorch forum:
https://discuss.pytorch.org/t/issues-installing-pytorch-for-os-x-with-conda/11496
As suggested in PyTorch forum, I think you should first install MKL. Your error trace also says that MKL is missing in your system. You can install MKL by doing:
$ conda install -c anaconda mkl
After this, install pytorch and torchvision by
$ conda install -c pytorch pytorch torchvision
Update conda first with conda update conda and try again.
It helped in my case.
Disclaimer: I didn't come up with this myself, but rather copied from github issue.

Categories