Search code examples
pythonrpycharmarticulate

Trying to run Python using Reticulate giving a module not found error, but it is installed


I am trying to source data from a python script to use in R. I am using Articulate and PyCharm.

The script imports the module GetOldTweets3 and runs fine on its own, but when I try to run it using Articulate, I get Exception: ModuleNotFoundError: No module named 'GetOldTweets3'

py_config() gives me:

python:         C:/Users/<username>/AppData/Local/r-miniconda/envs/r-reticulate/python.exe
libpython:      C:/Users/<username>/AppData/Local/r-miniconda/envs/r-reticulate/python36.dll
pythonhome:     C:/Users/<username>/AppData/Local/r-miniconda/envs/r-reticulate
version:        3.6.10 |Anaconda, Inc.| (default, Mar 23 2020, 17:58:33) [MSC v.1916 64 bit (AMD64)]
Architecture:   64bit
numpy:          C:/Users/<username>/AppData/Local/r-miniconda/envs/r-reticulate/Lib/site-packages/numpy
numpy_version:  1.18.1

Running conda list in a terminal shows it there (in the pypi channel).

I am calling the python script using source_python().


Solution

  • Make sure you activate the conda virtual environment

    It looks like numpy is installed in your personal r-retuculate python virtual environment. Make sure you activate the virtual environment associated with your installed python packages.

    library(reticulate)
    use_virtualenv("r-reticulate")