Having problems importing numpy
or scipy
suggests that your script is not running in the correct Python environment. It is possible to install multiple versions of Python on a computer, and which one is run when you type python
is determined by the PATH
setting. It may be that when RStudio executes your script (via python myfirstpythonfile.py
) it is launching the wrong Python — a version of Python on your computer that does not have the numpy
packages installed.
You can test if this is the case by running the following on the command line and seeing what it outputs:
python -c "import sys; print(sys.executable)"
You can try the same from within RStudio:
system('python -c "import sys; print(sys.executable)"')
If it gives a different result, you can pass the result of the first as an absolute path to python (changing /path/to/python for the correct value for your system):
system('/path/to/python myfirstpythonfile.py')
As you mention in the comments that you are actually trying to use Python3, then you may be able to simply do the following from within RStudio:
system('python3 myfirstpythonfile.py')
This will run your script using your installed Python3 and the associated packages/libraries.