Sympy在终端工作,但在Jupiter Notebook或Jupyterlab中工作,有什么建议吗?

发布于 2025-02-06 11:55:18 字数 684 浏览 1 评论 0原文

硬件/软件:
MacBook Pro 16英寸,2021 -M1 Max(Macos Monterey版本12.4)和Python 3.9.13。

已经尝试过:

pip install sympy
pip install -u sympy
conda安装sympy
conda install -c conda-forge sympy

在终端中工作正常:

>>> from sympy import *
>>>

但是在jupyter-lab和jupiter笔记本中:

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
Input In [1], in <cell line: 1>()
----> 1 from sympy import *

ModuleNotFoundError: No module named 'sympy

Hardware/Software:
MacBook Pro 16-inch, 2021 - M1 max (macOS Monterey Version 12.4) and Python 3.9.13.

Have tried:

pip install sympy
pip install -U sympy
conda install sympy
conda install -c conda-forge sympy

In terminal it works fine:

>>> from sympy import *
>>>

But in both jupyter-lab and Jupiter notebook:

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
Input In [1], in <cell line: 1>()
----> 1 from sympy import *

ModuleNotFoundError: No module named 'sympy

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

自此以后,行同陌路 2025-02-13 11:55:18
  1. @creanion提出的调试步骤

    a:
    在终端:

      $ python
    
    &gt;&gt;&gt; sys.version_info
    
    
    sys.version_info(major = 3,次要= 9,micro = 13,reareelevel ='final',serial = 0) 
    
    &gt;&gt;&gt; Sys.cutable
    /usr/local/caskroom/miniforge/base/bin/python
    
     &gt;&gt;&gt; Platform.Processor()
    
     'i386'
    
     b
     在jupyter-lab中: 
    
    sys.version_info
     sys.version_info(major = 3,次要= 10,micro = 4,reareelevel ='final',serial = 0)
    
    Sys.cutable
    
    '/library/frameworks/python.framework/versions/3.10/bin/python3.10'
    
    Platform.Processor()
    
    '手臂'
    
     
  2. 创建@hrokr建议的虚拟环境
    安装

      conda create -n pyc39 python = 3.9
    
     
  3. 安装ipykernel

    不确定我是否应该在此步骤之前激活env,或者这里的所有内容都是必要的,但是以下是全局安装的

      conda安装ipykernel
    
    python3 -m ipykernel install -user -name pyc39 -display -name“ pyc39”
    
    conda安装-n Pyc39 nb_conda_kernels
    
    conda安装-N pyc39 ipykernel
     
  4. activate env,打开jupyter-lab,然后选择新创建的pyc39以验证

      conda激活pyc39
    
    jupyer-lab!
    
    来自Sympy Import * 
    
     
  1. Debugging step as proposed by @creanion

    a:
    In terminal:

    $python
    
    >>> sys.version_info
    
    
    sys.version_info(major=3, minor=9, micro=13, releaselevel='final', serial=0) 
    
    >>> sys.executable
    /usr/local/Caskroom/miniforge/base/bin/python
    
     >>> platform.processor()
    
     'i386'
    
     b
     While in jupyter-lab: 
    
    sys.version_info
     sys.version_info(major=3, minor=10, micro=4, releaselevel='final', serial=0)
    
    sys.executable
    
    '/Library/Frameworks/Python.framework/Versions/3.10/bin/python3.10’
    
    platform.processor()
    
    'arm’
    
    
  2. Creating virtual environment as suggested by @hrokr
    Install

    conda create -n pyc39  python=3.9
    
    
  3. Install ipykernel

    Was not sure if I should have activated env in prior to this step, and or everything here was necessary, however the following was globally installed

    conda install ipykernel
    
    python3 -m ipykernel install --user --name pyc39 --display-name "pyc39”
    
    conda install -n pyc39 nb_conda_kernels
    
    conda install -n pyc39 ipykernel
    
  4. Activate env, open jupyter-lab and choose the newly created pyc39 to verify

    conda activate pyc39
    
    jupyer-lab!
    
    from sympy import * 
    
    
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文