PuffedRiceCrackers
PuffedRiceCrackers

Reputation: 785

ModuleNotFoundError, but it runs in anaconda (jupyter)

I've installed a module named rauth through terminal with pip3 install rauth command but when I import the module and run the code on Visual Studio Code with python3 interpreter, it gives ModuleNotFoundError: No module named 'rauth' error. But it is indeed installed and I can use it in Anaconda. The package file is stored here.

/Users/puffedricecracker/anaconda3/lib/python3.7/site-packages/rauth

And it seems like all my pip installed packages are stored in that path, but those are imported outside Anaconda with no problem. Tried several other commands as google search suggested.

pip install instead of pip3 install

python -m pip install

python3 -m pip install

Let me know if there is any other information needed to be specified.

Upvotes: 0

Views: 537

Answers (2)

PuffedRiceCrackers
PuffedRiceCrackers

Reputation: 785

I don't know if this could be an universal solution but there was a way to set where to install a package using pip.

  1. In python shell, find where your python modules usually go. It seemed like most of pip installed packages were installed in the second path so I chose that.
>>> import re
>>> print(re.__file__)
/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/re.py

>>> import sqlalchemy
>>> print(sqlalchemy.__file__)
/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/sqlalchemy/__init__.py
  1. Uninstall the package using pip uninstall packagename
  2. Reinstall with a path name.
pip install packagename -t /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages

(In fact, just copy pasting package files (in my case, they were rauth, rauth-0.7.3.dist-info) from anaconda package path in the post worked.)

Upvotes: 0

user9022647
user9022647

Reputation:

this is due to the module is installed into site-packages in Anaconda but not Visual Studio. Can you check if the module exists in Visual Studio folder? Another way to test it is to open Python IDLE and run the import, it should also return an error.

Upvotes: 1

Related Questions