No module named sympy

42,200

Solution 1

Given that you are new to Python I would advise that you install a distribution that already includes the complete scientific python stack such as WinPython or Anaconda. If it is specifically sympy you are after you can play around online at Sympy live. If you want to stick to your distribution try installing sympy with

pip install sympy

rather than downloading it manually.

Solution 2

you can also do it in the jupyter notebook. Write in a cell this, and Run that cell:

!pip install --upgrade
!pip install sympy 
import sympy

If your kernel uses python3, then use "pip3" instead. You may have to do Kernel->Restart, if it doesn't work straight away.

If it still doesn't find the module because Jupyter doesn't load the correct folder where it is installed. then consider doing either

import sys
sys.path.append('my/path/to/module/folder') 
#the (successful) line "!pip install sympy " should tell you where this path is

or (on the bash terminal)

echo "PYTHONPATH=\"$PYTHONPATH:my/path/to/module/folder\"" >> ~/.bashrc
source ~/.bashrc
# then restart jupyter notebook 
Share:
42,200
pythonlearner
Author by

pythonlearner

Updated on July 09, 2022

Comments

  • pythonlearner
    pythonlearner almost 2 years

    Hi I'm learning linear algebra with python with an Edx course. (http://nbviewer.ipython.org/github/ULAFF/notebooks/tree/may-14-2014/).

    On "02.4.2.10 Practice with matrix-vector multiplication" with the first box, the code is:

    import generate_problems as gp
    print("What is the result of the matrix vector product below?")
    
    p = gp.Problem()
    
    p.new_problem()
    

    generate_problems is a module that the professor at Edx created. However, I got an error importing sympy.

    I got the error below:

    ---------------------------------------------------------------------------
    ImportError                               Traceback (most recent call last)
    <ipython-input-10-79d56e0988cb> in <module>()
    ----> 1 import generate_problems as gp
          2 print("What is the result of the matrix vector product below?")
          3 
          4 p = gp.Problem()
          5 
    
    /Users/user/Desktop/Course/Python/ipython/notebooks-master/generate_problems.py in <module>()
          2 from numpy import matrix
          3 
    ----> 4 from sympy import init_printing, Matrix, MatMul, latex, Rational, zeros
          5 from IPython.display import Math
          6 
    
    ImportError: No module named sympy
    

    I downloaded and installed sympy and it works in sympy directory in the terminal(Mac OS X yosemite) if I import.Could someone help me?

  • pythonlearner
    pythonlearner almost 9 years
    Thank you! I installed Anaconda and it's really great :) Solved the problem.
  • Boris Valderrama
    Boris Valderrama over 4 years
    How can I find the module's path?
  • angelo.mastro
    angelo.mastro almost 4 years
    @Elborito sorry for the late answer. that depends on (1) your OS, (2) the python package installer you have (pip2, pip3, conda2-3, others). whatever it is you should look for the "site-packages" folder. it contains the packages installed. I have anaconda, mine is "C:\Users\angelo\Anaconda3\Lib\site-packages"