Reputation: 151
This question may be obvious but I have trouble figuring out what's going on. As far as I can see there are no similar problems addressed on the internet.
I'm using Python 3.7 and Spyder (hence the Anaconda bundle). The problem I have is that I'm not able to use SymPy. I've written the following test code which seems to be correct according to documentation and examples:
from sympy import *
x, y, z, t = symbols('x y z t')
expr = x**2+2
d = diff(expr,x)
print(d)
When compiling this I get the message
NameError: name 'symbols' is not defined
What's going on here?
Upvotes: 5
Views: 12771
Reputation: 3239
The issue MIGHT be, that you called your source file 'sympy.py'. If you then "import sympy", you actually import your own source file instead of the sympy library. The solution is then to just rename your source file to something else... like "test.py" and try to run it.
The following comment actually gave ne the hint. However, since it's not the original poster, he might have had a different issue.
"Interestingly I have this problem when running the script as a file but not when running the code inside the console line by line. – logicbloke Jul 26 '20 at 1:00"
Upvotes: 1
Reputation: 11
try the following:
import sympy as sp
x, y, z, t = sp.symbols('x, y, z, t')
expr = x**2+2
d = diff(expr,x)
print(d)
Upvotes: 1
Reputation: 1
Your code works fine when I try it.
Have you updated your software recently?
If you're on Ubuntu, try running an update via the command line:
sudo apt-get update
For more information on this, check: https://askubuntu.com/questions/222348/what-does-sudo-apt-get-update-do
Upvotes: 0