Issues installing pytorch for OS X with conda - python

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.

Related

"torch" and "pytorch" version mismatch in conda

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.

How do I install Pytorch 1.3.1 with CUDA enabled

I have a conda environment on my Ubuntu 16.04 system.
When I install Pytorch using:
conda install pytorch
and I try and run the script I need, I get the error message:
raise AssertionError("Torch not compiled with CUDA enabled")
From looking at forums, I see that this is because I have installed Pytorch without CUDA support.
I then tried:
conda install -c pytorch torchvision cudatoolkit=10.1 pytorch
but now I get the error:
from torch.utils.cpp_extension import BuildExtension, CUDAExtension
File "/home/username/miniconda3/envs/super_resolution/lib/python3.6/site-packages/torch/__init__.py", line 81, in <module>
from torch._C import *
ImportError: /lib64/libc.so.6: version `GLIBC_2.14' not found
So it seems that these two installs are installing different versions of Pytorch(?). The first one that seemed to work was Pytorch 1.3.1.
My question: How do I install Pytorch with CUDA enabled, but ensure it is version 1.3.1 so that it works with my system?
Given that your system is running Ubuntu 16.04, it comes with glibc installed. You can check your version by typing ldd --version.
Keep in mind that PyTorch is compiled on CentOS which runs glibc version 2.17.
Then check the CUDA version installed on your system nvcc --version
Then install PyTorch as follows e.g. if your cuda version is 9.2:
conda install pytorch torchvision cudatoolkit=9.2 -c pytorch
If you get the glibc version error, try installing an earlier version of PyTorch.
If neither of the above options work, then try installing PyTorch from sources.
If you would like to set a specific PyTorch version to install, please set it as <version_nr> in the below command:
conda install pytorch=<version_nr> torchvision cudatoolkit=9.2 -c pytorch
For CUDA 10.1:
conda install pytorch torchvision cudatoolkit=10.1 -c pytorch
For CUDA 9.2:
conda install pytorch torchvision cudatoolkit=9.2 -c pytorch
For no CUDA:
conda install pytorch torchvision cpuonly -c pytorch
Not sure whether you have solved your problem or not, but I have this exact same problem before because I was trying to install pytorch on a cluster and I don't have root access. You need to download glibc into your directoryand set the environmental variable LD_LIBRARY_PATH to your local glibc https://stackoverflow.com/a/48650638/5662642.
To install glibc locally, I will point you to this thread that I read to solve my problem
https://stackoverflow.com/a/38317265/5662642 (instead of setting --prefix=/opt/glibc-2.14 when installing, you might want to set it to other directory that you have access to). Hope it works for you

How should I install and import simpletransformers?

I have been using the following conda & python verison:
conda version : 4.6.14
conda-build version : 3.17.8
python version : 3.7.3.final.0
I installed simpletransformers in the following manner:
conda create -n simpletransformers python pandas tqdm
conda activate simpletransformers
conda install pytorch cpuonly -c pytorch
conda install -c anaconda scipy
conda install -c anaconda scikit-learn
pip install transformers
pip install seqeval
pip install tensorboardx
pip install simpletransformers
After doing so, I've been trying to import the classification model without much luck:
import simpletransformers
I get the following error:
ModuleNotFoundError: No module named 'simpletransformers'
Can someone point out where I'm going wrong? I'm using PyCharm as my IDE.
The setup docs work for me on Mac and Ubuntu using Anaconda:
Install Anaconda or Miniconda
Create a new virtual python 3.7 environment and install pandas and tqdm
conda create -n simplet python=3.7 pandas tqdm
conda activate simplet
PyTorch
3 a. GPU (use_cuda=True in your model): conda install pytorch cudatoolkit=10.1 -c pytorch
3 b. CPU (use_cuda=False in your model): conda install pytorch cpuonly -c pytorch
If you want to use fp16 training on an NVIDIA GPU install apex (don't use pip)
Install simpletransformers.
pip install simpletransformers
Download the .whl file from "https://pypi.org/project/simpletransformers/#files"
Open command prompt
type pip install "path/simpletransformers-0.13.2-py3-none-any.whl" and hit enter
Check whether the package gets installed.
Note that simpletransformers requires Python '>=3.6'
Whenever I have a package that is not available via Anaconda Cloud, i.e., I have to install from PyPI or GitHub, then I create a YAML environment definition for it. This follows the best practices enumerated in "Using Pip in a Conda Environment".
The advantage of a YAML is that it allows Conda to solve for everything at once and it lets one treat envs as immutable objects (i.e., if you need to alter the env, edit the YAML and recreate). This helps avoid the mess that inevitably seems to result from running a series of conda install, pip install, or conda update commands.
For me this is a multi-stage process, but it has been a reliable workflow for me:
Workflow for Mixed Conda-PyPI Environments
Look at the setup.py or requirements.txt of the non-Conda package. Here it is for simpletransformers.
For each requirement, check Anaconda Cloud (or conda search) to see if it is available as a Conda package.
If it is available, add it to the YAML file as a (non-pip) dependency. This ensures that everything that can come from Conda does.
Also, keep track of the channels that these packages come from. Note, I will not use a private channel I am unfamiliar with. In this case pytorch, conda-forge, and defaults (i.e., anaconda) suffice.
Include the packages that are PyPI-only under the pip section of the YAML, including the main package of interest (i.e., simpletransformers). Technically, you don't need to include the other dependencies, since pip will pull them in automatically, but I like to keep them explicit so that if I ever update the YAML I might check again if someone ported the PyPI packages to Conda Forge.
Create the env using the YAML
conda env create -n st_env -f simpletransformers.yaml
Check to see if any additional packages were implicitly pulled in as dependencies from PyPI, but were actually available through Conda. Edit the YAML to put these in the Conda dependencies section. In this case, keras is apparently also needed.
Remove the env and recreate using the updated maximally Conda version.
Most important: never change the env except through editing the YAML.
YAML for SimpleTransformers Environment
simpletransformers.yaml
name: st_env
channels:
- pytorch
- conda-forge
- defaults
dependencies:
- python=3.7
- pandas
- tqdm
- cpuonly
- pytorch
- transformers
- scipy
- scikit-learn
- requests
- tensorboardx
- keras
- pip
- pip:
- seqeval
- simpletransformers
Install with
conda env create -n st_env -f simpletransformers.yaml
If you have pip installed in your environment, just do hit a pip install simpletransformers in your terminal or If you're using jupyter notebook/colab, etc. then paste !pip install simpletransformers in your first cell and run it.
Then import simpletransformers
import simpletransformers

How to install pytorch in Anaconda with conda or pip?

I am trying to install pytorch in Anaconda to work with Python 3.5 in Windows. Following the instructions in pytorch.org I introduced the following code in Anaconda:
pip3 install torch torchvision
But the following error came in:
Command "python setup.py egg_info" failed with error code 1 in C:\Users\sluis\AppData\Local\Temp\pip-install-qmrvz7b9\torch\
By searching on the web I found out that it may be because of setuptools being out of date but I checked and have it updated. I also tried:
conda install -c peterjc123 pytorch cuda80
But the following error arise:
The following specifications were found to be in conflict:
- pytorch
Use "conda info <package>" to see the dependencies for each package.
I also tried to load the pytorch's tar.bz2 file which I download in the following website:
anaconda.org/peterjc123/pytorch/files
And then just do:
$ conda install filename.tar.bz2
But I got the following error:
Error: HTTPError: 404 Client Error: None for url: file:///C|/Users/sluis/pytorch-0.3.1-py36_cuda80_cudnn6he774522_2.tar.bz2: file:///C|/Users/sluis/pytorch-0.3.1-py36_cuda80_cudnn6he774522_2.tar.bz2
I am quite new to this programming world so I don't really know how to dig more on the errors. Anyone knows how to get pytorch installed?
Edit: As suggested in the comments I tried:
conda install pytorch torchivsion -c pytorch
And I got the following error:
Error: Packages missing in current win-64 channels:
- pytorch
- torchvision
I did:
anaconda search -t conda torchvision
And tried to install dericlk/torchvision using the following command:
conda install -c derickl torchvision
But I am getting the same error:
Error: Package missing in current win-64 channels:
- torchvision
I couldn't find any torchvisionpackages for win-64.
conda list is giving me the following:
# packages in environment at C:\Users\aaaa\AppData\Local\Continuum\Anaconda3\envs\torchenv2:
#
mkl-include 2018.0.2 1 anaconda
certifi 2016.2.28 py35_0
cffi 1.10.0 py35_0
cmake 3.6.3 vc14_0 [vc14]
openmp 2018.0.0 intel_8 intel
mkl 2017.0.3 0
numpy 1.13.1 py35_0
pip 10.0.0 <pip>
pip 9.0.1 py35_1
pycparser 2.18 py35_0
python 3.5.4 0
pyyaml 3.12 py35_0
setuptools 36.4.0 py35_1
typing 3.6.2 py35_0
vc 14 0
vs2015_runtime 14.0.25420 0
wheel 0.29.0 py35_0
wincertstore 0.2 py35_0
zlib 1.2.11 vc14_0 [vc14]
=======
Go to the official PyTorch.org and follow the steps accordingly.
Select your preferences and you will see an appropriate command below on the page.
If you don't have GPU in the system, set CUDA as None or CPU
Example command:
conda install pytorch-cpu torchvision-cpu -c pytorch
The following worked for me. First install MKL:
conda install -c anaconda mkl
After this, install pytorch and torchvision:
conda install -c pytorch pytorch torchvision
For windows python 3.6 and above without cuda
pip install torch==1.2.0+cpu torchvision==0.4.0+cpu -f https://download.pytorch.org/whl/torch_stable.html
Can you please try with below steps
conda create -n pytorch_env python=3.5
source activate pytorch_env
conda install -c soumith pytorch
python
> import torch
You can even find pytorch after you execute command conda list.
For linux, cuda9.0, python3.6:
pip3 install http://download.pytorch.org/whl/cu90/torch-0.3.1-cp36-cp36m-linux_x86_64.whl
pip3 install torchvision
For other cuda/python version: check website: https://ptorch.com/news/145.html
try updating the base conda package with the following command,then you can try reistalling it.
conda update --all
conda update -n base conda
For me it worked doing this:
Uninstall the previous version: go to C:\users\username\anaconda3 and run the anaconda-uninstall.exe
Install again anaconda
then run the following commands on the anaconda pompt:
conda create -n my_env python=2.7
conda activate my_env
start the gui app
conda install -c peterjc123 pytorch
anaconda-navigator
For Readers live in 2021/06/xx:
use pip3 install torch
As an update, now the Pytorch official site has the right version depending on your system:
https://pytorch.org/
I recommend using the official website for installation. Some of the previous awnsers may lead to a version that is not adequate.
After Activating conda environment
Use below command
python3 -m pip install torch torchvision
Example
(torchenv) ubuntu#user :~$ python3 -m pip install torch torchvision
Visit https://anaconda.org/pytorch/torchvision and you will find the solution
conda install -c pytorch torchvision
Try running:
conda install -c pytorch pytorch

How to install Gensim version 0.11.1 on Windows 10 Machine?

I have anaconda and Pip installed. I tried doing
conda install -c anaconda gensim-0.11.1
but it couldn't find the package and the following msg was thrown on the PowerShell.
Using Anaconda Cloud api site https://api.anaconda.org
Fetching package metadata: ......
Solving package specifications: .
Error: Package missing in current win-64 channels:
- gensim-0.11.1
You can search for this package on anaconda.org with
anaconda search -t conda gensim-0.11.1
Any help would be appreciated. Thanks!
--Conda works well with the machine but even help with Pip would be appreciated.
Any reason you need the 0.11.1 version? That version hasn't been specifically built as a conda package apparently.
At the moment, conda install gensim will easily give you version 0.12.4.
If you really need version 0.11.1, first
conda install scipy pip
then
pip install gensim==0.11.1

Categories