1

Summary

I would like to use an anaconda environment living in Windows Subsystem for Linux (WSL) as a python interpreter for PyCharm and as a kernel for Jupyter Notebook.

What I've tried

I have an anaconda environment called tacs-v2 on my WSL (Ubuntu 20.04.3 LTS). I created this environment in order to install an open source finite-element code called TACS, which can only be compiled on Linux (hence the use of WSL).

I would like to use PyCharm as IDE for some python scripts related to TACS and I have been able to configure tacs-v2 as a remote interpreter in my PyCharm Professional on Windows following these instructions.

I would also like to create some Jupyter Notebooks related to TACS. I first tried to use PyCharm (on Windows) as editor of a Jupyter Notebook, however I got the following error when I executed it: enter image description here

When I tried to configure the interpreter for the Jupyter Server I found out that for some reasons my remote interpreter tacs-v2 could not be used: enter image description here

With PyCharm not working, I thought about launching the Jupyter Notebook directly from WSL. I followed this guide and I managed to succesfully run the notebook, with one caveat though. At the beginning of my notebook, the following import statement was initially causing a ModuleNotFoundError:

from tacs import TACS, elements, constitutive, functions

where tacs is the package constituting the finite-element code and it corresponds to a directory inside the local repository. See below for a representation of its structure:

tacs-2.0.0/
|-- build/
|-- docs/
|-- examples/
|-- ...
|-- tacs/
    |-- __init__.py
    |-- constitutive.cpp
    |-- constitutive.cpython-38-x86_64-linux-gnu.so
    |-- constitutive.pxd
    |-- constitutive.pyx
    |-- ...

Running the same import statement in a python script with PyCharm was fine. I found the solution in this answer. In fact, running

import sys
print(sys.path)

returned different results with PyCharm (Windows) and Jupyter (WSL). The former returned

['/mnt/c/Users/qa21944/git/tacs-2.0.0/examples/crm',
 '/mnt/c/Program Files/JetBrains/PyCharm 2021.2.2/plugins/python/helpers/pydev',
 '/mnt/c/Users/qa21944/git/tacs-2.0.0',
 '/mnt/c/Program Files/JetBrains/PyCharm 2021.2.2/plugins/python/helpers/pycharm_display',
 '/mnt/c/Program Files/JetBrains/PyCharm 2021.2.2/plugins/python/helpers/third_party/thriftpy',
 '/mnt/c/Program Files/JetBrains/PyCharm 2021.2.2/plugins/python/helpers/pydev',
 '/mnt/c/Users/qa21944/AppData/Local/JetBrains/PyCharm2021.2/cythonExtensions',
 '/mnt/c/Users/qa21944/git/tacs-2.0.0/examples/crm',
 '/home/fmamitrotta/anaconda3/envs/tacs-v2/lib/python38.zip',
 '/home/fmamitrotta/anaconda3/envs/tacs-v2/lib/python3.8',
 '/home/fmamitrotta/anaconda3/envs/tacs-v2/lib/python3.8/lib-dynload',
 '/home/fmamitrotta/anaconda3/envs/tacs-v2/lib/python3.8/site-packages',
 '/mnt/c/Program Files/JetBrains/PyCharm 2021.2.2/plugins/python/helpers/pycharm_matplotlib_backend',
 '/home/fmamitrotta/anaconda3/envs/tacs-v2/lib/python3.8/site-packages/IPython/extensions']

while the latter returned

['/mnt/c/Users/qa21944/git/tacs-2.0.0/examples/crm',
 '/home/fmamitrotta/anaconda3/envs/tacs-v2/lib/python38.zip',
 '/home/fmamitrotta/anaconda3/envs/tacs-v2/lib/python3.8',
 '/home/fmamitrotta/anaconda3/envs/tacs-v2/lib/python3.8/lib-dynload',
 '',
 '/home/fmamitrotta/anaconda3/envs/tacs-v2/lib/python3.8/site-packages',
 '/home/fmamitrotta/anaconda3/envs/tacs-v2/lib/python3.8/site-packages/IPython/extensions',
 '/home/fmamitrotta/.ipython']

So I had to add sys.path.append('/mnt/c/Users/qa21944/git/tacs-2.0.0') before the import statement in my notebook.

Questions

  • Microsoft docs recommed against working across operating systems. As a consequence, I would say that my setup of having the anaconda environment on WSL and the local repository and PyCharm on Windows is not ideal. Since I cannot avoid using WSL, can I have everything there? Unfortunately, it seems that the only way to use PyCharm with WSL is to have PyCharm Professional on Windows and configure a remote interpreter via WSL.
  • Why doesn't PyCharm let me set a remote interpreter (my tacs-v2) as interpreter of a Jupyter Server?
  • Why do I get a different output running print(sys.path) with PyCharm (on Windows) and Jupyter (on WSL)? Is there a way I can avoid to manually add the path to the tacs-2.0.0 directory in my notebook before the import statement?
fma
  • 219
  • 2
  • 14

0 Answers0