I have install scipy to read data from a .mat file. When I am in Python in the command prompt I am able to type the following and get the value I desire:
Command Prompt
>>> import scipy
>>> import scipy.io
>>> from scipy.io import loadmat
>>> x=loadmat('C:\My websites\Rooftop PV.mat')
>>> size = x['component']['Size'][0][0][0][0]
>>> print(size)
150
>>> import sys
>>> sys.executable
'C:\\...\\Documents\\anaconda3\\python.exe'
However, when I run the .py script...
.py script
import sys
print(sys.executable)
import scipy
import scipy.io
from scipy.io import loadmat
x = loadmat('C:\My websites\Rooftop PV.mat')
size = x['component']['Size'][0][0][0][0]
print(size)
it is unable to find the scipy.io module, producing this error:
Error:
C:\Python\pythonw.exe
File "C:\Python\testmatfile.py", line 4, in <module>
import scipy.io
ModuleNotFoundError: No module named 'scipy.io'
Any ideas on why this might be? Thanks!
As you can see there are two different python executables used. C:\\...\\Documents\\anaconda3\\python.exe is used in the first case and C:\Python\pythonw.exe is used in the second case. You have your lib installed for the first python executable (into the corresponding path), so you just need to run
C:\Python\pythonw.exe -m pip install <lib_name>
command to install the lib into the path related to the second executable. You can also use virtualenv or docker to run your script into isolated env with all required dependencies.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With