简体   繁体   中英

Module not found in Spyder outside of Anaconda

For a training course, I had to install Anaconda and launch Spyder from there. This used to work. However, I want to understand more about Python, because I have little experience with programming environments (I only use R and Stata up to now).

I stumbled on this issue: when I open Spyder directly (presumably I have downloaded a standalone version), most syntax runs well, but I cannot get the 'seaborn' module to work.

I tried pip install seaborn , pip3 install seaborn , conda install seaborn , but to no avail (outside of Anaconda, that is). I also tried updating spyder, homebrew, python and anaconda to the most recent versions. Probably this caused further issues discussed below.

My Python version is 3.9.7 (in terminal), Python3 is 3.9.9 (in terminal and through Anaconda), and through Spyder directly it is 3.9.5. Spyder IDE is 5.2.1, under Anaconda it is 5.1.5. I have no idea why these are all different, where to find the right paths, and how to update the Spyder version of Python and how to add the 'seaborn' module to that environment. It is possible to select a path for the Python interpreter in the Spyder preferences, but which path to take is unclear to me.

In short: how can I get seaborn to work in Spyder without having to rely on Anaconda (which seems a bit bloated to me and is slower to start up)?

Meanwhile, real problems occurred: I can't open Spyder from Anaconda any longer (so seaborn is not totally out of reach). This is the message:

/Users/myname/opt/anaconda3/bin/pythonw: line 3: /Users/myname/opt/anaconda3/python.app/Contents/MacOS/python: No such file or directory

This is the simple syntax I wanted to try:

# Seaborn example
import numpy as np
import pandas as pd
import seaborn as sns
sns.set_theme(style="whitegrid")

rs = np.random.RandomState(365)
values = rs.randn(365, 4).cumsum(axis=0)
dates = pd.date_range("1 1 2016", periods=365, freq="D")
data = pd.DataFrame(values, dates, columns=["A", "B", "C", "D"])
data = data.rolling(7).mean()

sns.lineplot(data=data, palette="tab10", linewidth=2.5)

Giving the error message: ModuleNotFoundError: No module named 'seaborn'

Probably this question is related: installed module in anaconda prompt shell but module not found in spyder?

I am working on an M1 MBA under Monterey.

Many thanks

I found the solution, which is to create a new environment and link to it, on the Spyder FAQ:https://docs.spyder-ide.org/5/faq.html#using-packages-installer

The video was helpful: https://youtu.be/i7Njb3xO4Fw

It seems I can use the Python version installed through conda (in opt/anaconda3) and base an 'environment' on this, adding modules by first activating the environment and then using conda install .

Meanwhile, I still cannot launch Spyder from Anaconda-Navigator.

/Users/myname/opt/anaconda3/bin/pythonw: line 3: /Users/myname/opt/anaconda3/python.app/Contents/MacOS/python: No such file or directory

Probably reinstalling will solve this. But I'm good for now.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM