Configure Pytorch for PyCharm using Conda in MacOS Catalina

SQL WARRIOR
3 min readOct 27, 2019

While Finally it works! Here’s the proof:

Now let’s roll back. First of all, here are my environment:

Platform: macOS Catalina on MacBook Retina 2008 late

Python: Python 3.7

PyCharm: PyCharm 2019 the latest version

Anaconda: Anaconda the latest version

PyTorch: PyTorch is from Pytorch.org with the following combination:

PyTorch Combination from pytorch.org

Please noted down the “Run this Command” we will run this using Conda later.

First, we need to install Anaconda. Nothing special just click through.

Second, we will install PyCharm. Nothing special as well.

Now we need to create virtual environment. Most of newbie (silly me!) felled into traps here. So I list the steps here:

  1. list existing environments:

conda info -e

Here’s my environment, be noted there’s only base environment, which is default. And also the * besides the folder, which means it is current active environment.

2. create new environments. Let’s call it Pytorch_nongpu. For learning purposes we don’t need GPU enabled. Plus, this is MacBook Pro it has AMD Graphic card only nowadays.

conda create -n pytorch_nongpu python=3.7

This created environment called Pytorch_nongpu, with python version 3.7.

3. Now check environments again

conda info -e

As we could tell the active one was not changed. Now we had two environments though.

4. Make sure your current environment is Pytorch_nongpu. Many times during troubleshooting, we made changes back and forth and sometimes we forgot which environment we were in.

conda activate Pytorch_nongpu

After that we the active environment changed to Pytorch_nongpu.

5. Run the command line

conda install pytorch torchvision -c pytorch

The reason it took me a hour to troubleshooting was that when I run above command, I was not in right environemnt. I hope this could save you hassle!

6. Now create project inside PyCharm. And then add new python file.Nothing special. Just create new project. And specify the environment. Here you had to choose “Existing interpreter”. And click … button (the yellow line):

Then new window open, choose Conda Environment on the left panel. Make sure to choose interpreter with “pytorch_nongpu” in it’s path:

7. To test use the following code:

from __future__ import print_function

import torch x = torch.rand(6, 3)

print(x)

You will see the result as the beginning of this article!

All done!

--

--

SQL WARRIOR

AWS Database Consultant. Still have passion on SQL Server since 1998. Expert on SQL Server Performance Tunning, High Availability. VMWare VCP 6/7.