Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Select different anaconda environments #4223

Open
ckaldemeyer opened this issue Mar 3, 2017 · 56 comments
Open

Select different anaconda environments #4223

ckaldemeyer opened this issue Mar 3, 2017 · 56 comments

Comments

@ckaldemeyer
Copy link

Description of your problem

What steps will reproduce the problem?

  1. A new anaconda environment is created
  2. I open spyder
  3. I set this environment (anaconda/bin/...) as standard intepreter

What is the expected output? What do you see instead?

I want wo use this environment (send the code to the interpreter)

The interpreter breaks down.

Isn't there a way to switch different Anaconda envs within Spyder?

Please provide any additional information below

Versions and main components

  • Spyder Version: 3.1.3
  • Python Version: 3.5
  • Qt Version:
  • PyQt Version:
  • Operating system: Ubuntu 16.04

Dependencies

Please go to the menu entry Help > Optional Dependencies (or
Help > Dependencies), press the button Copy to clipboard
and paste the contents below:

@ccordoba12
Copy link
Member

The interpreter breaks down.

Could you be more specific?

@hiccup7
Copy link

hiccup7 commented Mar 4, 2017

Spyder is not limited to use in an Anaconda distribution. I also use Spyder in a WinPython distribution. I don't think it is practical for Spyder to know which package manager installed it and handle all the complexities of changing environments.

With both Anaconda and WinPython, I create a separate Windows batch file for each environment to run Spyder. Discussion and example batch files are at winpython/winpython#351

@ccordoba12
Copy link
Member

I still don't understand that well how you guys are talking about, but our plan to manage environments/virtualenvs in Spyder is by adding the possibility of a setting a particular Python interpreter per project.

That will be done in Spyder 3.3.

@ckaldemeyer
Copy link
Author

The interpreter breaks down.
Could you be more specific?

I go to "Preferences > Python interpreter > Use the following interpreter" and change it to the newly created environment:

/home/cord/.anaconda3/envs/test/bin/python3

Now I restart Spyder and get the error:

An error ocurred while starting the kernel
Your Python environment or installation doesn't have the ipykernel module installed on it. Without this module is not possible for Spyder to create a console for you.
You can install ipykernel by running in a terminal:
pip install ipykernel

So I install ipykernel with pip within the environment:

(test) cord@cord-Laptop:~/.anaconda3/bin$ pip install ipykernel
Successfully installed decorator-4.0.11 ipykernel-4.5.2 ipython-5.3.0 ipython-genutils-0.1.0 jupyter-client-5.0.0 jupyter-core-4.3.0 pexpect-4.2.1 pickleshare-0.7.4 prompt-toolkit-1.0.13 ptyprocess-0.5.1 pygments-2.2.0 pyzmq-16.0.2 simplegeneric-0.8.1 tornado-4.4.2 traitlets-4.3.2 wcwidth-0.1.7
(test) cord@cord-Laptop:~/.anaconda3/bin$ 

And if I open Spyder it still shows the anaconda default environment:

Python 3.5.2 |Anaconda custom (64-bit)| (default, Jul  2 2016, 17:53:06)

Would this generally be the right way to work with different environments?

@ckaldemeyer
Copy link
Author

Or is this the case because Spyder is started from another anaconda environment and I normally had to start it from the system python interpreter?

@ccordoba12
Copy link
Member

And if I open Spyder it still shows the anaconda default environment

Are you sure is that the default environment? Please try to import any package besides ipykernel to see if that's true or not.

@ckaldemeyer
Copy link
Author

And if I open Spyder it still shows the anaconda default environment
Are you sure is that the default environment? Please try to import any package besides ipykernel to see if that's true or not.

You are right, it somehow worked after restarting a couple of times because the kernel broke down it IPython console did not open.

I have installed pyPdf in the environment test-wise and importing works partly but then breaks:

import pyPdf
Traceback (most recent call last):

File "<ipython-input-1-a5780a4295f9>", line 1, in <module>
import pyPdf

File "/home/cord/.anaconda3/envs/test/lib/python3.5/site-packages/pyPdf/__init__.py", line 1, in  > <module>
from pdf import PdfFileReader, PdfFileWriter

ImportError: No module named 'pdf'

This might also related to pyPdf but let's put my question more generally away from debugging third party packages:

If you wanted to use Spyder and Anaconda on a Linux-System working on different Anaconda environments, what would be the steps to install Spyder and later change between the environments?

@ccordoba12
Copy link
Member

There's no easy way right now, except changing interpreters in Python interpreter.

However, when we add the possibility to associate a conda env to a project, then you would only need to create a project for your code, and decide what modules you'd like to use in your project (we'll also provide a graphical interface to install conda packages).

Does that sound good?

@ckaldemeyer
Copy link
Author

There's no easy way right now, except changing interpreters in Python interpreter.

However, when we add the possibility to associate a conda env to a project, then you would only need to create a project for your code, and decide what modules you'd like to use in your project (we'll also provide a graphical interface to install conda packages).

Does that sound good?

👍

The only thing I'd be interested in would then be the planned release date 😄

@ccordoba12
Copy link
Member

This will be part of Spyder 3.3, to be released by the end of the summer.

@ckaldemeyer
Copy link
Author

Thanks!

@ccordoba12 ccordoba12 reopened this Mar 7, 2017
@ccordoba12
Copy link
Member

@ckaldemeyer, please leave this one open so we don't forget to address it in 3.3 ;-)

@ckaldemeyer
Copy link
Author

@ckaldemeyer, please leave this one open so we don't forget to address it in 3.3 ;-)

👍

@annesession
Copy link

annesession commented Jul 17, 2017

Spyder IDE specific enviroment workaround by attaching Spyder IDE to a running enviroment kernel

Preliminary: need to install ipykernel into the specific enviroment @ckaldemeyer has this as above. I've found it useful to add a descriptive name when installing the kernel, that way when changing kernels in Jupyter notebook it makes straightforward the environment you are working with:
(bioset) anne@linux:~> python -m ipykernel install --user --name bioset --display-name "Python (bioset-numpy)"

Get a list of your kernels (so you know which one to use)
anne@linux:~/anaconda3/envs> jupyter kernelspec list
Available kernels:
my_env /home/anne/.local/share/jupyter/kernels/my_env
python3 /home/anne/anaconda3/share/jupyter/kernels/python3

Launch Jupyter qtconsole (console, notebook) using the kernel associated with the enviroment you want to work with (ie the output from jupyter kernelspec list). If working with jupyter notebook, you can just launch the notebook normally and change the kernel on the right side.
jupyter qtconsole --kernel my_env

Within the qtconsole (console, notebook) spawned from the step above use a magic number command to get all of the information you need for a connection
%connect_info

The output from the magic number (%connect_info) at the end, lists the name of the kernel.json file you can use to attach, on linux its normally automatically saved to /run/user/"your user id"/jupyter if you added the kernel to the environment as a user. Alternatively copy the connection port information within the curly braces (including the curly braces) of the output %connect_info and save it as .json file.

Use Spyder IDE to connect to already running kernel:
From within the Spyder IDE-> select the gear icon in the IPython Console panel-> dropdown menu: Connect to an existing kernel-> Browse to the .json file created in the step above.

Spyder will now be using the kernel specific to your environment. Because you can use multiple IPython console tabs, you can run/test code against different environments by just changing the tabs of the IPython console

@ccordoba12 ccordoba12 modified the milestones: v4.0beta2, v4.0beta3 Aug 13, 2017
@none2serious
Copy link

Is there anything wrong with doing something like the following to invoke spyder with a specific environment?
Install spyder in an existing second anaconda env (e.g. an env running Intel Python 3 vs. my vanilla 2.7).
Create an alias to spyder in that env folder.

alias spyder3='~/anaconda/envs/idp3/bin/spyder'

Call that alias to open spyder in that env.

Python 3.5.3 |Intel Corporation| (default, Apr 27 2017, 10:37:05)
Type "copyright", "credits" or "license" for more information.

I've been doing this to run spyder within alternate envs without problems. Is this OK, or have I just been lucky?

@ccordoba12
Copy link
Member

Is there anything wrong with doing something like the following to invoke spyder with a specific environment?

That is ok. In fact, there's a similar mechanism for Windows users provided automatically by Anaconda (i.e. Anaconda creates Start menu entries for each Spyder package in different envs).

We simply want to avoid this process and let users work with a single Spyder version for all their projects.

@thomas2004ch
Copy link

thomas2004ch commented Sep 15, 2017

Hi all,

I use the Python 3.6. After I create a new ENV of Python 3.5 I have the same problem by switching Spyder between different ENVs. But I figure out. Here is what I did:
1.
Create a new env with:
conda create --name py35 python=3.5
2.
Change to the new created env with:
activate py35
3.
Install the Spyder with:
conda install spyder
4.
Start the Spyder and change the python.exe setting in Tools -> Preferences -> Python Intepreter -> Use the following Python Intepreter and select the Python.exe in the new created env.

Then close the Spyder
5.
Now start the Spyder but not the one from Python 3.6, but the one (double click the spyder.exe) from the new created ENV.

That's all.

@besli
Copy link

besli commented Feb 25, 2018

Hi Everyone;
Would you help me out about the python console is absent as a pane in spyder 3.6? I set up Anaconda 3 64 bit in my pc but I couldnt see the pane of python console in tool or view as a pane option. Thanks

@ccordoba12
Copy link
Member

@besli, the Python console was removed in Spyder 3.2: #4524.

@besli
Copy link

besli commented Feb 25, 2018

how about the Spyder 3.6?

@ccordoba12
Copy link
Member

3.6 is the Python version, not the Spyder version.

@BJWiley233

This comment has been minimized.

@ccordoba12

This comment has been minimized.

@ccordoba12 ccordoba12 modified the milestones: v4.0betaX, v4.0beta5 Aug 10, 2019
@ccordoba12 ccordoba12 modified the milestones: v4.0beta5, future Aug 31, 2019
@matthiasLevy

This comment has been minimized.

@ccordoba12

This comment has been minimized.

@matthiasLevy

This comment has been minimized.

@flobrec

This comment has been minimized.

@ccordoba12

This comment has been minimized.

@goanpeca goanpeca removed this from the future milestone Feb 23, 2020
@slideWXY
Copy link

the best way I found is to :

conda install spyder
then conda install conda-navigator
conda install spyder-kernels=0.*

and:
anaconda-navigator

then select the env in the top window
then start spyder

@ghost
Copy link

ghost commented Apr 9, 2020

the best way I found is to :

conda install spyder
then conda install conda-navigator
conda install spyder-kernels=0.*

and:
anaconda-navigator

then select the env in the top window
then start spyder

Brilliant - that's the answer right there! Much appreciated.

@goanpeca
Copy link
Member

This is also related with what @mrclary suggested we do to make the python interpreter configuration option in the preferences leaner.

I would like to hear your thoughts :-p .

I also agree we should probably use envs in general instead of interpreters, but there might be cases where one still needs to point to a specific interpreter.

Also some pointers, what should be the default behavior when switching to a different env (from the status bar), restart the consoles? only the current one? ask the user? add an option on preferences to do it automatically or ask the user all the time?

@mrclary
Copy link
Contributor

mrclary commented Apr 12, 2020

Also some pointers, what should be the default behavior when switching to a different env (from the status bar), restart the consoles? only the current one? ask the user? add an option on preferences to do it automatically or ask the user all the time?

What do you mean "switching to a different env (from the status bar)"? Do you mean just updating the status bar when switching console tabs? Presently, switching "interpreters" in the preferences only affects new console tabs, leaving existing console tabs in the environment (interpreter) they were started with; I think this is good. But it would be nice if the "interpreter" status in the status bar updated to reflect the current console tab, similar to the git status when switching editor documents.

@goanpeca
Copy link
Member

Like what VSCode does.

Screen Shot 2020-04-12 at 11 00 40

Going to the preferences the way it is now it is very cumbersome and I would say a very bad UX. But changing the env and not having some immediate effect for it or even a option of what to do when that happens will provide still a very bad user experience.

@mrclary
Copy link
Contributor

mrclary commented Apr 12, 2020

Yeah, that would be really nice. My vote would be to always restart the current console or just start a new console with that environment.

@ghost
Copy link

ghost commented Jun 29, 2020

The way VSCode changes the interpreters is very efficient and was hoping this was introduced in spyder. When will it be available?

@goanpeca goanpeca removed their assignment Aug 13, 2020
@PackElend
Copy link

I would like to see the same functionality as in VS Code as well, I have just switched from VS Code to Spyder but being a bit disappointed as this feature is missing.

@ccordoba12
Copy link
Member

@PackElend, since Spyder 4.2.0, you can go to

Tools > Preferences > Python interpreter

Check the option called Use the following interpreter and select your conda environment in the dropdown present there. That's better explained in our docs.

@PackElend
Copy link

I'm aware of this but this not as convenient as in VS Code.
The bad UX is well explained in #11362

@ccordoba12
Copy link
Member

This and #11362 are separate issues because they refer to different problems: one thing is being able to create an IPython console for any environment you have (this issue) and another one is to associate an env to a project (#11362).

@PackElend
Copy link

all issues have in common, that I want to be able to switch the environment by a single click or environment is changed automatically when a project is selected with a custom environment.
There shall be no risk of using the wrong environment when switching between projects etc.

@ccordoba12
Copy link
Member

Switching environments makes little sense in Spyder because a user can open as many consoles as they want. Therefore, we're planning to offer the ability to open a console with any detected environment.

If you want to participate in the discussion we're having about that, please leave your comment in spyder-ide/ux-improvements#10.

@mrclary
Copy link
Contributor

mrclary commented Jan 7, 2021

@ccordoba12 @PackElend, I agree that these features are desirable but I think we can close this issue in favor of existing ones.

@ccordoba12
Copy link
Member

I think we can close this issue in favor of existing ones.

I disagree. I think the PR that fixes spyder-ide/ux-improvements#10 should fix this one as well (this has a lot more history).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests