Python 没有名为 sympy 的模块

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30275418/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 08:09:41  来源:igfitidea点击:

No module named sympy

pythonpython-2.7ipythonipython-notebooksympy

提问by pythonlearner

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

嗨,我正在通过 Edx 课程使用 python 学习线性代数。(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:

在第一个框的“02.4.2.10练习矩阵向量乘法”上,代码是:

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.

generate_problems 是 Edx 教授创建的一个模块。但是,我在导入 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?

我下载并安装了 sympy,如果我导入,它可以在终端(Mac OS X yosemite)的 sympy 目录中工作。有人可以帮助我吗?

采纳答案by krcools

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 WinPythonor 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

鉴于您是 Python 的新手,我建议您安装一个已经包含完整科学 Python 堆栈的发行版,例如WinPythonAnaconda。如果它特别是 sympy,那么您可以在Sympy live在线玩游戏。如果你想坚持你的发行版,请尝试安装 sympy

pip install sympy

rather than downloading it manually.

而不是手动下载。

回答by angelo.mastro

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

你也可以在jupyter notebook 中做到这一点。在一个单元格中写下这个,然后运行那个单元格:

!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.

如果您的内核使用 python3,请改用“pip3”。如果不能立即运行,您可能必须执行 Kernel->Restart。

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

如果它仍然找不到模块,因为 Jupyter 没有加载安装它的正确文件夹。然后考虑做

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)

或(在 bash 终端上)

echo "PYTHONPATH=\"$PYTHONPATH:my/path/to/module/folder\"" >> ~/.bashrc
source ~/.bashrc
# then restart jupyter notebook