I have used anaconda to set up multiple environments. I then use visual studio code to do all my editing. However, there seems to be a difference between what packages the jupyter / interactive window in vscode can find, and which packages the 'python.exe' called from the terminal can find.
Specifically: I have installed mne_bids using pip, since that was not in conda.
I can import this fine using the interactive window:
However, running the same bit of code from the dedicated terminal does not work:
python mne_test3.py
Traceback (most recent call last):
File "mne_test3.py", line 3, in <module>
import mne_bids
ModuleNotFoundError: No module named 'mne_bids'
So what do I need to change for me to be able to import the same packages in the terminal as well as the interactive window? Both of them are using the same conda environment. I have set the PYTHONPATH environment variable using the windows gui:
EDIT: Some helpful people are suggesting that I may have different conda environments activated. I don't think that is the case. In the image below can be seen the whole vscode interface:
Hopefully you can see that both the interactive window, as well as the powershell, are 'MNE' (which is the name of the conda environment with mne_bids in it).
It seems that the problem I have is similar to what is discussed in Visual Studio Code terminal doesn't activate Conda environment. I am working my way through some of the suggestions there.
CodePudding user response:
In VSCODE, Press F1 and Type python: Select Interpreter. Or Press Python Kernel Button. Then you can select python interpreter that mne_bids module was installed.
Also, you can select kernel in VSCODE Jupyter Notebook(Interactive Window). Press F1 and Type Select Notebook Kernel or press select kernel button.
And I think you should use conda virtual environment. See the documentation on managing Conda environments.
CodePudding user response:
You have selected the different python environments for the Jupyter Interactive
and python file
.
You can get which python interpreter you have selected for python file
from the bottom left of the VSCode, and which for Jupyter Interactive
from the top-right.
You need not add PYTHONPATH
in the system environment. And if you want to get the PYTHONPATH
, you can take this:
import sys
from pprint import pprint
pprint(sys.path)