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

Cannot activate conda env when created in a path #16562

Closed
jrenardOceanSonics opened this issue Oct 8, 2021 · 13 comments
Closed

Cannot activate conda env when created in a path #16562

jrenardOceanSonics opened this issue Oct 8, 2021 · 13 comments

Comments

@jrenardOceanSonics
Copy link

jrenardOceanSonics commented Oct 8, 2021

What steps will reproduce the problem?

1 Create a conda environment with the --prefix option, specifying a path rather than an environment name.

2 install spyder-kernel in the environment.

3 Inside the new environment, create an environment variable using: conda env config vars set MY_VAR='HELLO'

4 launch spyder from another conda environment (can be the base environment)

5 change the Python Interpreter to point to the python.exe file in the new environment.
The path is obtained from the command: python -c "import sys; print(sys.executable)"

6 Create a new console or restart the kernel. Spyder outputs the message '<path_to_env>/Scripts/activate' is not recognized as an internal or external command.

Python 3.9.7 | packaged by conda-forge | (default, Sep 29 2021, 19:20:16) [MSC v.1916 64 bit (AMD64)]
Type "copyright", "credits" or "license" for more information.

IPython  -- An enhanced Interactive Python.

Restarting kernel...
 

'C:/<path_to_dir>/.conda/dev_env/Scripts/activate' is not recognized as an internal or external command,
operable program or batch file.

7 Check that the environment variable MY_VAR does not exist.

If the environment is created with a name and placed in the default miniconda3/envs directory, there is no issue and the new environment appears directly in the Spyder drop-down menu for the Python interpreter.

Environment

  • Spyder version: 5.1.5 None
  • Python version: 3.8.12 64-bit
  • Qt version: 5.12.9
  • PyQt5 version: 5.12.3
  • Operating System: Windows 10

Installation from miniconda3

@ccordoba12
Copy link
Member

Hey @jrenardOceanSonics, thanks for reporting. This is certainly a use case we haven't tried on Windows.

@dalthviz, could you try to reproduce this problem on your side? Thanks!

@ccordoba12 ccordoba12 changed the title Cannot activate conda env Cannot activate conda env when created in a path Oct 9, 2021
@dalthviz
Copy link
Member

dalthviz commented Oct 11, 2021

@ccordoba12 @jrenardOceanSonics I was able to reproduce this, athough the message about the activation only happens to me when doing a kernel restart. However in both cases the env var set with conda doesn't exist.

@ccordoba12
Copy link
Member

Ok, but does the kernel restart after the message is displayed?

@ccordoba12 ccordoba12 added this to the v5.2.1 milestone Oct 11, 2021
@dalthviz
Copy link
Member

This is what I'm seeing @ccordoba12 :

After restart:

imagen

In a new Console instance:

imagen

@ccordoba12
Copy link
Member

Ok, I see. @dalthviz, could you verify that the interpreter is the one in the environment by running sys.executable in the console?

@dalthviz
Copy link
Member

Is the one in the environment either if you restart or create a new Console:

After restart:

imagen

With a new Console:

imagen

@ccordoba12
Copy link
Member

Ok, so I think the problem is just that environment is nor properly activated.

@ccordoba12 ccordoba12 modified the milestones: v5.2.1, v5.2.2 Nov 26, 2021
@ccordoba12 ccordoba12 modified the milestones: v5.2.2, v5.3.0 Dec 19, 2021
@ccordoba12 ccordoba12 modified the milestones: v5.3.0, v5.3.1 Jan 30, 2022
@ccordoba12 ccordoba12 modified the milestones: v5.3.1, v5.3.2 Apr 9, 2022
@ccordoba12 ccordoba12 modified the milestones: v5.3.2, v5.3.3 May 4, 2022
@DereckZhang
Copy link

@ccordoba12
I met the same problem in 5.3.0, conda environment created in a path is not properly activated, but conda env in default path(in my case is 'C:\ProgramData\Miniconda3\envs\envname\python.exe') can be properly activated.
Today I update to 5.3.1 and change none of settings, the same conda env in default path can't be properly activated! It shows :

An error ocurred while starting the kernel
The following argument was not expected: C:/ProgramData/Miniconda3/envs/envname
Run with ‑‑help for more information.

I think this problem will nag many people, hope it can be resolved in the near future.

@ccordoba12 ccordoba12 modified the milestones: v5.3.3, v5.3.4 Jun 20, 2022
@ghost
Copy link

ghost commented Jul 19, 2022

I have the same issue on 5.3.2. When I start Spyder I'm always greeted with the "An error ocurred while starting the kernel" error in red and the following text:

The following argument was not expected: C:/Users/username/Miniconda3/envs/env_name
Run with ‑‑help for more information.

What worries me now is that in the past (pre 5.3.2) I could click on "New console" and a new console would start right away (while still printing the text about "the following argument..."). However, now I sometimes need to start 3-4 new consoles before a console actually starts.

I've installed Spyder on Windows with the standalone installer.

@ccordoba12 ccordoba12 modified the milestones: v5.3.4, v5.3.3 Jul 20, 2022
@LiGengLei
Copy link

@ba-tno I have the same issue on 5.3.2.

@dalthviz
Copy link
Member

dalthviz commented Aug 2, 2022

Just in case, I was able to reproduce the The following argument was not expected: message when using the standalone windows installer with a custom interpreter. Trying to launch multiple times consoles causes at some point the console to start but still printing the error message before the first console prompt:

imagen

imagen

Could this error by related with installations for all users (installation with Admin privileges) using either the standalone installer or Anaconda/Miniconda?

@dalthviz dalthviz modified the milestones: v5.3.3, v5.3.4 Aug 19, 2022
@ghost
Copy link

ghost commented Aug 22, 2022

Could this error by related with installations for all users (installation with Admin privileges) using either the standalone installer or Anaconda/Miniconda?

Just tested: I uninstalled standalone Spyder 5.3.2, which was installed "for all users" (with Admin privileges), and installed it again "just for me" (using the the standalone installer). Now the console starts without error when using a custom interpreter.

If it matters: my Miniconda is also installed "just for me" in C:\users\username\Miniconda3.

@dalthviz
Copy link
Member

Note: Seems like this issue could be relevant here - mamba-org/mamba#1881 (for the per environment environment variables part of the OP, at least if you are using the standalone installer which uses the micromamba executable to activate envs)

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

5 participants