Skip to content

Instantly share code, notes, and snippets.

@qin-yu
Last active May 17, 2021 14:47
Show Gist options
  • Save qin-yu/c1bb53e4981e69c51e4b990ab205491d to your computer and use it in GitHub Desktop.
Save qin-yu/c1bb53e4981e69c51e4b990ab205491d to your computer and use it in GitHub Desktop.

Some important things to note when one tries to use a remote interpreter in PyCharm:

  1. If you are using two instances of PyCharm, e.g. on two differenct machines:

    • map the project to a separate folder in the remote disk, the default /tmp/_______ should be fine, but it could be anywhere.
    • map the .pycharm_helper folder to a separate directory too, e.g. for home machine access create a ~/.pycharm_helper_home to map to.
  2. If you are using conda environments, do the following to actually get conda working:

    • suppose you are using an environment called my_conda_env, find the location of the python executable, e.g. you can do
      $ conda activate my_conda_env
      $ which python
    • now you know the path to that python interpreter is for example .../miniconda3/envs/my_conda_env/bin/python
    • now add a file pycharm_python to .../miniconda3/envs/my_conda_env/bin/ with the following content:
      #!/usr/bin/env bash
      
      source .../miniconda3/etc/profile.d/conda.sh  # <-- here you need to change it to the actual path
      conda activate my_conda_env
      python "$@"
    • set the remote interpreter to .../miniconda3/envs/my_conda_env/bin/pycharm_python in the remote server
    • to check if conda environment is actually used, in Python Console in PyCharm:
      >>> import os
      >>> print(os.environ.get('CONDA_PREFIX'))
  3. Make sure in all settings, e.g.

    • "Tools -> Deployment -> Configuration/Options" in top menu bar,
    • "Python Interpreter -> Interpreter Settings -> (Gear Icon) -> Show All -> (Pen Icon)" in PyCharm Settings (can be launched from bottom-right corner),
    • etc.
  4. Make sure when you are deploying by uploading in "Tools -> Deployment -> Upload ...", select the correct file/directory in project tree (usually just select the project root), otherwise not all files are sync-ed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment