Home > Net >  how to get my python executable to find my site packages
how to get my python executable to find my site packages

Time:12-16

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:

enter image description here

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:

enter image description here

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:

enter image description here

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.

Select Interpreter

Also, you can select kernel in VSCODE Jupyter Notebook(Interactive Window). Press F1 and Type Select Notebook Kernel or press select kernel button.

Select Kernel

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)
  • Related