question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot activate conda env when created in a path

See original GitHub issue

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

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:12 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
ba-tnocommented, 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.

1reaction
DereckZhangcommented, May 28, 2022

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

I can not activate virtual environment in conda - Stack Overflow
It is because I have changed the system's $PATH variable from anaconda's main bin directory to the environment's bin directory.
Read more >
PATH not set by conda activate · Issue #9392 - GitHub
With an empty environment active, running python will use another version available on your PATH (most likely the system version).
Read more >
Managing environments - Conda
With conda, you can create, export, list, remove, and update environments that have different versions of Python and/or packages installed in them.
Read more >
Efficient Way to Activate Conda in VSCode - Medium
Option 1: Create New Integrated Terminal (In Active Workspace) · Ctrl+Shift+P and search “Terminal”. · Choose “Terminal: Create New Integrated Terminal (In Active ......
Read more >
Working with Environments – Introduction to Conda for (Data ...
By default the conda install command will install packages into the current, active environment. The following would activate the basic-scipy-env we created ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found