I’m experiencing an issue with installing and using the ‘sympy’ module in my Python environment. I created the environment using MiniConda and I’m using VS Code as my code editor. I have already tried installing ‘sympy’ using both Conda and pip commands, and they both indicate successful installation. However, when I try to import ‘sympy’ in my Python code, I get a 'ModuleNotFoundError: No module named 'sympy'' error
.
I have double-checked that the module is indeed installed in my environment (everywhere sympy is listed as installed), but it seems that VS Code is unable to recognize it. I have restarted my computer and reactivated my environment, but the issue persists.
Could someone please help me troubleshoot this problem? Any suggestions or insights would be greatly appreciated!
import math
from sympy import*
x= Symbol('x')
l = Symbol('l')
t = Symbol('t')
e = Symbol('e')
This is the code I tried to make working.
ModuleNotFoundError Traceback (most recent call last)
Cell In[1], line 3
1 import math
----> 3 from sympy import*
5 x= Symbol('x')
6 l = Symbol('l')
ModuleNotFoundError: No module named 'sympy'
And this is the Error in detail.
Thank you in advance.
2
Answers
Thanks so much for all of your suggestions.
I ended up updating Python to 3.11 in both Anaconda and VS Code and created a new environment using Python 3.11. Now it works just fine.
I believe I have discovered the root of the problem!
When you run code in the editor, VSCode simulates a terminal. It types enters into that terminal a line that looks something like this:
Now that python may be version 3, 2, 3.8, 3.10, etc. what you need to do is make sure that the version of python you installed scipy with matches up with the version of python your program is being run in. You can do that by doing the following:
As you can see on that 4th line of output, it tells me the python version, 3.8. So this means that whenever VSCode runs python, it is running python 3.8. We need to make sure that we are installing scipy with and, in fact, running our code in python 3.8.
Press CTRL+Shift+P or CMD+Shift+P depending on your OS, to open the command palette. Search for the ‘python interpreter’ option. Change your python interpreter to the version mentioned when installing scipy with pip.
That should do it!
Remember to always install using python -m pip install
Output: