13

I installed the Python scipy stack using the following command taken from here

sudo apt-get install python-numpy python-scipy python-matplotlib ipython ipython-notebook python-pandas python-sympy python-nose

However, I can import sympy only in Python 2.7.6 which is the default Python version when I type in python in the terminal. When I start Python 3.4.0 by typing in python3, the import sympy statement throws the error

>>> import sympy
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named 'sympy'

How do I fix this problem?

21

You can use pip3 (which is just normal pip but in system's Python3 packages). Normally I would suggest avoiding using pip for installing stuff globally but given there are no packages for this that could overwrite the files, there's nothing to lose.

It's quick and simple:

sudo apt-get install python3-pip
sudo pip3 install sympy
|improve this answer|||||
  • Why using pip to install packages globally should be avoided? – ajay Jan 21 '15 at 12:14
  • 2
    For example if you have the python-requests package installed and then sudo pip install requests, it'll overwrite files that apt installed and then if apt updates, it'll overwrite those files and it turns into a big mushy mess. The two systems will likely be using different versions of the Requests library too. If you need your own Python environment (which you might, I do for Django development) use virtualenv. – Oli Jan 21 '15 at 12:21
  • 1
    ... Or python3 -m venv for Python 3 – Oli Dec 14 '15 at 15:11
7

In Ubuntu 16.04 and later, Sympy Computer Algebra System in Python can be installed from the default Ubuntu repositories. Open the terminal and type:

sudo apt install python3-sympy  

To install Sympy for Python 2.x run:

sudo apt install python-sympy
|improve this answer|||||
2

There's a backports and a nightly PPA with versions for all recent Ubuntu releases. Simply go

sudo add-apt-repository ppa:nschloe/sympy-backports
sudo apt update
sudo apt install python3-sympy
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.