Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SymPy: name 'symbols' is not defined

Tags:

sympy

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?

like image 214
Daniel Larsson Avatar asked Nov 16 '22 14:11

Daniel Larsson


1 Answers

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"

like image 140
SDwarfs Avatar answered Apr 23 '23 10:04

SDwarfs